Merge "libutils: add String8 and String16 std_string utility methods"

This commit is contained in:
Samuel Tan 2016-02-19 03:18:31 +00:00 committed by Gerrit Code Review
commit fb0670d650
3 changed files with 17 additions and 2 deletions

View file

@ -17,8 +17,10 @@
#ifndef ANDROID_STRING16_H
#define ANDROID_STRING16_H
#include <string> // for std::string
#include <utils/Errors.h>
#include <utils/Unicode.h>
#include <utils/String8.h>
#include <utils/TypeHelpers.h>
// ---------------------------------------------------------------------------
@ -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);

View file

@ -17,6 +17,8 @@
#ifndef ANDROID_STRING8_H
#define ANDROID_STRING8_H
#include <string> // for std::string
#include <utils/Errors.h>
#include <utils/Unicode.h>
#include <utils/TypeHelpers.h>
@ -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();

View file

@ -18,7 +18,6 @@
#include <utils/Log.h>
#include <utils/Unicode.h>
#include <utils/String8.h>
#include <utils/threads.h>
#include <memory.h>