Add String16::c_str and start using it.
This is for parity with String8::c_str and in general the first step in transition from String8|16.string() - to make it more similar to std::string. Bug: 295394788 Test: mma -j Change-Id: I6c1411bef07c761fb2fb3fb38c27801ac4cffc57
This commit is contained in:
parent
0c0dafae8d
commit
90af4157c5
|
@ -26,7 +26,7 @@ namespace android {
|
|||
|
||||
static const StaticString16 emptyString(u"");
|
||||
static inline char16_t* getEmptyString() {
|
||||
return const_cast<char16_t*>(emptyString.string());
|
||||
return const_cast<char16_t*>(emptyString.c_str());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -112,10 +112,7 @@ String16::String16(const char16_t* o) : mString(allocFromUTF16(o, strlen16(o)))
|
|||
|
||||
String16::String16(const char16_t* o, size_t len) : mString(allocFromUTF16(o, len)) {}
|
||||
|
||||
String16::String16(const String8& o)
|
||||
: mString(allocFromUTF8(o.string(), o.size()))
|
||||
{
|
||||
}
|
||||
String16::String16(const String8& o) : mString(allocFromUTF8(o.c_str(), o.size())) {}
|
||||
|
||||
String16::String16(const char* o)
|
||||
: mString(allocFromUTF8(o, strlen(o)))
|
||||
|
@ -173,7 +170,7 @@ status_t String16::setTo(const String16& other, size_t len, size_t begin)
|
|||
LOG_ALWAYS_FATAL("Not implemented");
|
||||
}
|
||||
|
||||
return setTo(other.string()+begin, len);
|
||||
return setTo(other.c_str() + begin, len);
|
||||
}
|
||||
|
||||
status_t String16::setTo(const char16_t* other)
|
||||
|
@ -200,7 +197,7 @@ status_t String16::setTo(const char16_t* other, size_t len)
|
|||
}
|
||||
|
||||
status_t String16::append(const String16& other) {
|
||||
return append(other.string(), other.size());
|
||||
return append(other.c_str(), other.size());
|
||||
}
|
||||
|
||||
status_t String16::append(const char16_t* chrs, size_t otherLen) {
|
||||
|
@ -286,7 +283,7 @@ bool String16::startsWith(const String16& prefix) const
|
|||
{
|
||||
const size_t ps = prefix.size();
|
||||
if (ps > size()) return false;
|
||||
return strzcmp16(mString, ps, prefix.string(), ps) == 0;
|
||||
return strzcmp16(mString, ps, prefix.c_str(), ps) == 0;
|
||||
}
|
||||
|
||||
bool String16::startsWith(const char16_t* prefix) const
|
||||
|
|
|
@ -150,10 +150,7 @@ String8::String8(const char* o, size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
String8::String8(const String16& o)
|
||||
: mString(allocFromUTF16(o.string(), o.size()))
|
||||
{
|
||||
}
|
||||
String8::String8(const String16& o) : mString(allocFromUTF16(o.c_str(), o.size())) {}
|
||||
|
||||
String8::String8(const char16_t* o)
|
||||
: mString(allocFromUTF16(o, strlen16(o)))
|
||||
|
@ -267,7 +264,7 @@ status_t String8::append(const String8& other)
|
|||
return OK;
|
||||
}
|
||||
|
||||
return real_append(other.string(), otherLen);
|
||||
return real_append(other.c_str(), otherLen);
|
||||
}
|
||||
|
||||
status_t String8::append(const char* other)
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
|
||||
~String16();
|
||||
|
||||
inline const char16_t* c_str() const;
|
||||
inline const char16_t* string() const;
|
||||
|
||||
private:
|
||||
|
@ -234,6 +235,11 @@ inline int strictly_order_type(const String16& lhs, const String16& rhs)
|
|||
return compare_type(lhs, rhs) < 0;
|
||||
}
|
||||
|
||||
inline const char16_t* String16::c_str() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
inline const char16_t* String16::string() const
|
||||
{
|
||||
return mString;
|
||||
|
@ -241,7 +247,7 @@ inline const char16_t* String16::string() const
|
|||
|
||||
inline std::string String16::std_string(const String16& str)
|
||||
{
|
||||
return std::string(String8(str).string());
|
||||
return std::string(String8(str).c_str());
|
||||
}
|
||||
|
||||
inline String16& String16::operator=(const String16& other)
|
||||
|
|
|
@ -193,14 +193,14 @@ public:
|
|||
* replaces whatever was there before.
|
||||
*/
|
||||
String8& appendPath(const char* leaf);
|
||||
String8& appendPath(const String8& leaf) { return appendPath(leaf.string()); }
|
||||
String8& appendPath(const String8& leaf) { return appendPath(leaf.c_str()); }
|
||||
|
||||
/*
|
||||
* Like appendPath(), but does not affect this string. Returns a new one instead.
|
||||
*/
|
||||
String8 appendPathCopy(const char* leaf) const
|
||||
{ String8 p(*this); p.appendPath(leaf); return p; }
|
||||
String8 appendPathCopy(const String8& leaf) const { return appendPathCopy(leaf.string()); }
|
||||
String8 appendPathCopy(const String8& leaf) const { return appendPathCopy(leaf.c_str()); }
|
||||
|
||||
/*
|
||||
* Converts all separators in this string to /, the default path separator.
|
||||
|
@ -255,7 +255,7 @@ inline const char* String8::string() const
|
|||
|
||||
inline std::string String8::std_string(const String8& str)
|
||||
{
|
||||
return std::string(str.string());
|
||||
return std::string(str.c_str());
|
||||
}
|
||||
|
||||
inline size_t String8::size() const
|
||||
|
|
Loading…
Reference in New Issue