Merge "Add String16::c_str and start using it." into main
diff --git a/libutils/String16.cpp b/libutils/String16.cpp
index 68642d8..38d483e 100644
--- a/libutils/String16.cpp
+++ b/libutils/String16.cpp
@@ -26,7 +26,7 @@
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, 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 @@
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::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 @@
{
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
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index 8d312b5..79b7edf 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -150,10 +150,7 @@
}
}
-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 @@
return OK;
}
- return real_append(other.string(), otherLen);
+ return real_append(other.c_str(), otherLen);
}
status_t String8::append(const char* other)
diff --git a/libutils/include/utils/String16.h b/libutils/include/utils/String16.h
index 3ef56a3..d719aea 100644
--- a/libutils/include/utils/String16.h
+++ b/libutils/include/utils/String16.h
@@ -53,6 +53,7 @@
~String16();
+ inline const char16_t* c_str() const;
inline const char16_t* string() const;
private:
@@ -234,6 +235,11 @@
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 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)
diff --git a/libutils/include/utils/String8.h b/libutils/include/utils/String8.h
index 8b2dcf9..e58f1a5 100644
--- a/libutils/include/utils/String8.h
+++ b/libutils/include/utils/String8.h
@@ -193,14 +193,14 @@
* 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 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