X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fos_string.hpp;h=78d02f2cacc5a4bbefcf430249a74361b068377a;hb=HEAD;hp=c3fcf83396c405595c33e9cec55b69569bf10622;hpb=0ee1f060f9a25fe36fd12649f6797e3a6e4360b5;p=apitrace diff --git a/common/os_string.hpp b/common/os_string.hpp index c3fcf83..78d02f2 100644 --- a/common/os_string.hpp +++ b/common/os_string.hpp @@ -93,12 +93,19 @@ protected: Buffer::iterator rfind(char c) { Buffer::iterator it = buffer.end(); + + // Skip trailing '\0' + assert(it != buffer.begin()); + --it; + assert(*it == '\0'); + while (it != buffer.begin()) { --it; if (*it == c) { return it; } } + return buffer.end(); } @@ -126,17 +133,30 @@ protected: Buffer::iterator rfindSep(void) { Buffer::iterator it = buffer.end(); + // Skip trailing '\0' + assert(it != buffer.begin()); + --it; + assert(*it == '\0'); + // Skip trailing separators - while (it != buffer.begin() && isSep(*it)) { + while (it != buffer.begin()) { --it; + if (isSep(*it)) { + // Halt if find the root + if (it == buffer.begin()) { + return it; + } + } else { + break; + } } // Advance to the last separator while (it != buffer.begin()) { + --it; if (isSep(*it)) { return it; } - --it; } return buffer.end(); @@ -186,7 +206,7 @@ public: va_list args_copy; va_copy(args_copy, args); #ifdef _WIN32 - /* We need to use _vcsprintf to calculate the length as vsnprintf returns -1 + /* We need to use _vscprintf to calculate the length as vsnprintf returns -1 * if the number of characters to write is greater than count. */ length = _vscprintf(format, args_copy); @@ -373,6 +393,9 @@ public: String getProcessName(); String getCurrentDir(); +bool copyFile(const String &srcFileName, const String &dstFileName, bool override = true); + +bool removeFile(const String &fileName); } /* namespace os */