Merge "Revert "Remove unused String8::setPathName."" am: 615bf4ef14
am: 01f3306b69
am: 2cca5cc992
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1768145 Change-Id: I9eb161676ecb73ba75d08b7d49b8305bf12455ab
This commit is contained in:
commit
6fd9460002
3 changed files with 26 additions and 7 deletions
|
@ -431,17 +431,24 @@ void String8::toLower()
|
|||
// ---------------------------------------------------------------------------
|
||||
// Path functions
|
||||
|
||||
static void setPathName(String8& s, const char* name) {
|
||||
size_t len = strlen(name);
|
||||
char* buf = s.lockBuffer(len);
|
||||
void String8::setPathName(const char* name)
|
||||
{
|
||||
setPathName(name, strlen(name));
|
||||
}
|
||||
|
||||
void String8::setPathName(const char* name, size_t len)
|
||||
{
|
||||
char* buf = lockBuffer(len);
|
||||
|
||||
memcpy(buf, name, len);
|
||||
|
||||
// remove trailing path separator, if present
|
||||
if (len > 0 && buf[len - 1] == OS_PATH_SEPARATOR) len--;
|
||||
if (len > 0 && buf[len-1] == OS_PATH_SEPARATOR)
|
||||
len--;
|
||||
|
||||
buf[len] = '\0';
|
||||
|
||||
s.unlockBuffer(len);
|
||||
unlockBuffer(len);
|
||||
}
|
||||
|
||||
String8 String8::getPathLeaf(void) const
|
||||
|
@ -554,7 +561,7 @@ String8& String8::appendPath(const char* name)
|
|||
size_t len = length();
|
||||
if (len == 0) {
|
||||
// no existing filename, just use the new one
|
||||
setPathName(*this, name);
|
||||
setPathName(name);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -574,7 +581,7 @@ String8& String8::appendPath(const char* name)
|
|||
|
||||
return *this;
|
||||
} else {
|
||||
setPathName(*this, name);
|
||||
setPathName(name);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,6 +89,10 @@ std::vector<std::function<void(FuzzedDataProvider*, android::String8*, android::
|
|||
str1->walkPath(path_out_str.get());
|
||||
path_out_str->clear();
|
||||
},
|
||||
[](FuzzedDataProvider* dataProvider, android::String8* str1,
|
||||
android::String8*) -> void {
|
||||
str1->setPathName(dataProvider->ConsumeBytesWithTerminator<char>(5).data());
|
||||
},
|
||||
[](FuzzedDataProvider* dataProvider, android::String8* str1,
|
||||
android::String8*) -> void {
|
||||
str1->appendPath(dataProvider->ConsumeBytesWithTerminator<char>(5).data());
|
||||
|
|
|
@ -136,6 +136,14 @@ public:
|
|||
* These methods operate on the string as if it were a path name.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set the filename field to a specific value.
|
||||
*
|
||||
* Normalizes the filename, removing a trailing '/' if present.
|
||||
*/
|
||||
void setPathName(const char* name);
|
||||
void setPathName(const char* name, size_t numChars);
|
||||
|
||||
/*
|
||||
* Get just the filename component.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue