diff --git a/include/utils/String16.h b/include/utils/String16.h index 50ac6d028..4a5874a4c 100644 --- a/include/utils/String16.h +++ b/include/utils/String16.h @@ -17,8 +17,10 @@ #ifndef ANDROID_STRING16_H #define ANDROID_STRING16_H +#include // for std::string + #include -#include +#include #include // --------------------------------------------------------------------------- @@ -65,6 +67,7 @@ public: inline const char16_t* string() const; + static inline std::string std_string(const String16& str); size_t size() const; void setTo(const String16& other); status_t setTo(const char16_t* other); @@ -142,6 +145,11 @@ inline const char16_t* String16::string() const return mString; } +inline std::string String16::std_string(const String16& str) +{ + return std::string(String8(str).string()); +} + inline String16& String16::operator=(const String16& other) { setTo(other); diff --git a/include/utils/String8.h b/include/utils/String8.h index 7734cfb52..1d12994d1 100644 --- a/include/utils/String8.h +++ b/include/utils/String8.h @@ -17,6 +17,8 @@ #ifndef ANDROID_STRING8_H #define ANDROID_STRING8_H +#include // for std::string + #include #include #include @@ -63,6 +65,7 @@ public: static String8 formatV(const char* fmt, va_list args); inline const char* string() const; + static inline std::string std_string(const String8& str); inline size_t size() const; inline size_t bytes() const; inline bool isEmpty() const; @@ -261,6 +264,11 @@ inline const char* String8::string() const return mString; } +inline std::string String8::std_string(const String8& str) +{ + return std::string(str.string()); +} + inline size_t String8::size() const { return length(); diff --git a/libutils/String16.cpp b/libutils/String16.cpp index 449fb205c..87eda1b35 100644 --- a/libutils/String16.cpp +++ b/libutils/String16.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include