Migrate String8/16 from .string() to c_str()
This will align usage with std::string.
Bug: 295394788
Test: make checkbuild
Change-Id: Ic5c215b011197950dcbcb0339f44cc68fefc65a1
diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp
index f054de9..4b27bdd 100644
--- a/libutils/ProcessCallStack.cpp
+++ b/libutils/ProcessCallStack.cpp
@@ -205,8 +205,7 @@
}
void ProcessCallStack::printInternal(Printer& printer, Printer& csPrinter) const {
- dumpProcessHeader(printer, getpid(),
- getTimeString(mTimeUpdated).string());
+ dumpProcessHeader(printer, getpid(), getTimeString(mTimeUpdated).c_str());
for (size_t i = 0; i < mThreadMap.size(); ++i) {
pid_t tid = mThreadMap.keyAt(i);
@@ -214,7 +213,7 @@
const String8& threadName = threadInfo.threadName;
printer.printLine("");
- printer.printFormatLine("\"%s\" sysTid=%d", threadName.string(), tid);
+ printer.printFormatLine("\"%s\" sysTid=%d", threadName.c_str(), tid);
threadInfo.callStack.print(csPrinter);
}
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index ab122c7..e0a2846 100644
--- a/libutils/RefBase.cpp
+++ b/libutils/RefBase.cpp
@@ -330,7 +330,7 @@
this);
int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 0644);
if (rc >= 0) {
- (void)write(rc, text.string(), text.length());
+ (void)write(rc, text.c_str(), text.length());
close(rc);
ALOGI("STACK TRACE for %p saved in %s", this, name);
}
diff --git a/libutils/String16_fuzz.cpp b/libutils/String16_fuzz.cpp
index d7e5ec7..a271aee 100644
--- a/libutils/String16_fuzz.cpp
+++ b/libutils/String16_fuzz.cpp
@@ -25,7 +25,7 @@
// Bytes and size
([](FuzzedDataProvider&, android::String16 str1, android::String16) -> void {
- str1.string();
+ str1.c_str();
}),
([](FuzzedDataProvider&, android::String16 str1, android::String16) -> void {
str1.isStaticString();
@@ -39,7 +39,7 @@
str1.startsWith(str2);
}),
([](FuzzedDataProvider&, android::String16 str1, android::String16 str2) -> void {
- str1.contains(str2.string());
+ str1.contains(str2.c_str());
}),
([](FuzzedDataProvider&, android::String16 str1, android::String16 str2) -> void {
str1.compare(str2);
@@ -52,7 +52,7 @@
([](FuzzedDataProvider& dataProvider, android::String16 str1,
android::String16 str2) -> void {
int pos = dataProvider.ConsumeIntegralInRange<int>(0, str1.size());
- str1.insert(pos, str2.string());
+ str1.insert(pos, str2.c_str());
}),
// Find and replace operations
diff --git a/libutils/String8_test.cpp b/libutils/String8_test.cpp
index 35fd512..9c12cb1 100644
--- a/libutils/String8_test.cpp
+++ b/libutils/String8_test.cpp
@@ -36,7 +36,7 @@
TEST_F(String8Test, Cstr) {
String8 tmp("Hello, world!");
- EXPECT_STREQ(tmp.string(), "Hello, world!");
+ EXPECT_STREQ(tmp.c_str(), "Hello, world!");
}
TEST_F(String8Test, OperatorPlus) {
@@ -45,16 +45,16 @@
// Test adding String8 + const char*
const char* ccsrc2 = "world!";
String8 dst1 = src1 + ccsrc2;
- EXPECT_STREQ(dst1.string(), "Hello, world!");
- EXPECT_STREQ(src1.string(), "Hello, ");
+ EXPECT_STREQ(dst1.c_str(), "Hello, world!");
+ EXPECT_STREQ(src1.c_str(), "Hello, ");
EXPECT_STREQ(ccsrc2, "world!");
// Test adding String8 + String8
String8 ssrc2("world!");
String8 dst2 = src1 + ssrc2;
- EXPECT_STREQ(dst2.string(), "Hello, world!");
- EXPECT_STREQ(src1.string(), "Hello, ");
- EXPECT_STREQ(ssrc2.string(), "world!");
+ EXPECT_STREQ(dst2.c_str(), "Hello, world!");
+ EXPECT_STREQ(src1.c_str(), "Hello, ");
+ EXPECT_STREQ(ssrc2.c_str(), "world!");
}
TEST_F(String8Test, OperatorPlusEquals) {
@@ -63,14 +63,14 @@
// Testing String8 += String8
String8 src2(" is my passport.");
src1 += src2;
- EXPECT_STREQ(src1.string(), "My voice is my passport.");
- EXPECT_STREQ(src2.string(), " is my passport.");
+ EXPECT_STREQ(src1.c_str(), "My voice is my passport.");
+ EXPECT_STREQ(src2.c_str(), " is my passport.");
// Adding const char* to the previous string.
const char* src3 = " Verify me.";
src1 += src3;
- EXPECT_STREQ(src1.string(), "My voice is my passport. Verify me.");
- EXPECT_STREQ(src2.string(), " is my passport.");
+ EXPECT_STREQ(src1.c_str(), "My voice is my passport. Verify me.");
+ EXPECT_STREQ(src2.c_str(), " is my passport.");
EXPECT_STREQ(src3, " Verify me.");
}
diff --git a/libutils/Tokenizer.cpp b/libutils/Tokenizer.cpp
index c3ec165..9fc955c 100644
--- a/libutils/Tokenizer.cpp
+++ b/libutils/Tokenizer.cpp
@@ -50,15 +50,15 @@
*outTokenizer = nullptr;
int result = OK;
- int fd = ::open(filename.string(), O_RDONLY);
+ int fd = ::open(filename.c_str(), O_RDONLY);
if (fd < 0) {
result = -errno;
- ALOGE("Error opening file '%s': %s", filename.string(), strerror(errno));
+ ALOGE("Error opening file '%s': %s", filename.c_str(), strerror(errno));
} else {
struct stat stat;
if (fstat(fd, &stat)) {
result = -errno;
- ALOGE("Error getting size of file '%s': %s", filename.string(), strerror(errno));
+ ALOGE("Error getting size of file '%s': %s", filename.c_str(), strerror(errno));
} else {
size_t length = size_t(stat.st_size);
@@ -80,7 +80,7 @@
ssize_t nrd = read(fd, buffer, length);
if (nrd < 0) {
result = -errno;
- ALOGE("Error reading file '%s': %s", filename.string(), strerror(errno));
+ ALOGE("Error reading file '%s': %s", filename.c_str(), strerror(errno));
delete[] buffer;
buffer = nullptr;
} else {
@@ -106,7 +106,7 @@
String8 Tokenizer::getLocation() const {
String8 result;
- result.appendFormat("%s:%d", mFilename.string(), mLineNumber);
+ result.appendFormat("%s:%d", mFilename.c_str(), mLineNumber);
return result;
}