1
0
ithewei 5 жил өмнө
parent
commit
d4fc62e6ad
2 өөрчлөгдсөн 14 нэмэгдсэн , 4 устгасан
  1. 12 4
      base/hstring.h
  2. 2 0
      docs/apis.md

+ 12 - 4
base/hstring.h

@@ -64,10 +64,18 @@ public:
 namespace hv {
 // NOTE: low-version NDK not provide std::to_string
 template<typename T>
-static inline std::string to_string(const T& num) {
-    std::ostringstream os;
-    os << num;
-    return os.str();
+static inline std::string to_string(const T& t) {
+    std::ostringstream oss;
+    oss << t;
+    return oss.str();
+}
+
+template<typename T>
+static inline T from_string(const std::string& str) {
+    T t;
+    std::istringstream iss(str);
+    iss >> t;
+    return t;
 }
 }
 

+ 2 - 0
docs/apis.md

@@ -244,6 +244,8 @@
 - dirname
 - filename
 - suffixname
+- hv::to_string
+- hv::from_string
 
 ### hdir.h
 - listdir