hewei 6 vuotta sitten
vanhempi
commit
5f0225fa57
3 muutettua tiedostoa jossa 29 lisäystä ja 14 poistoa
  1. 17 3
      base/htime.c
  2. 4 0
      base/htime.h
  3. 8 11
      http/http_content.h

+ 17 - 3
base/htime.c

@@ -10,6 +10,8 @@
     #define strnicmp    strncasecmp
 #endif
 
+static const char* s_weekdays[] = {"Sunday", "Monday", " Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
+
 static const char* s_months[] = {"January", "February", "March", "April", "May", "June",
     "July", "August", "September", "October", "November", "December"};
 
@@ -212,12 +214,24 @@ int month_atoi(const char* month) {
 }
 
 const char* month_itoa(int month) {
-    if (month < 1 || month > 12) {
-        return NULL;
-    }
+    assert(month >= 1 && month <= 12);
     return s_months[month-1];
 }
 
+int weekday_atoi(const char* weekday) {
+    for (size_t i = 0; i < 7; ++i) {
+        if (strnicmp(weekday, s_weekdays[i], strlen(weekday)) == 0)
+            return i;
+    }
+    return 0;
+}
+
+const char* weekday_itoa(int weekday) {
+    assert(month >= 0 && month <= 7);
+    if (weekday == 7) weekday = 0;
+    return s_weekdays[weekday];
+}
+
 datetime_t get_compile_datetime() {
     static datetime_t dt;
     char month[32];

+ 4 - 0
base/htime.h

@@ -120,9 +120,13 @@ datetime_t* datetime_future(datetime_t* dt, int days DEFAULT(1));
 time_t calc_next_timeout(int minute, int hour, int day, int week, int month);
 
 int days_of_month(int month, int year);
+
 int month_atoi(const char* month);
 const char* month_itoa(int month);
 
+int weekday_atoi(const char* weekday);
+const char* weekday_itoa(int weekday);
+
 datetime_t get_compile_datetime();
 
 #ifdef __cplusplus

+ 8 - 11
http/http_content.h

@@ -55,6 +55,7 @@ int         parse_query_params(const char* query_string, QueryParams& query_para
 // NOTE: WITHOUT_HTTP_CONTENT
 // ndk-r10e no std::to_string and can't compile modern json.hpp
 #ifndef WITHOUT_HTTP_CONTENT
+#include <sstream>
 
 /**************multipart/form-data*************************************
 --boundary
@@ -81,17 +82,13 @@ struct FormData {
             this->filename = filename;
         }
     }
-    FormData(int n) {
-        content = std::to_string(n);
-    }
-    FormData(long long n) {
-        content = std::to_string(n);
-    }
-    FormData(float f) {
-        content = std::to_string(f);
-    }
-    FormData(double lf) {
-        content = std::to_string(lf);
+    template<typename T>
+    FormData(T num) {
+        // NOTE: low-version NDK not provide std::to_string
+        //content = std::to_string(num);
+        std::ostringstream os;
+        os << num;
+        content = os.str();
     }
 };