diff options
Diffstat (limited to 'src/common/string_util.h')
| -rw-r--r-- | src/common/string_util.h | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/common/string_util.h b/src/common/string_util.h index 023dff5dc..a32c07c06 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -12,19 +12,19 @@ | |||
| 12 | namespace Common { | 12 | namespace Common { |
| 13 | 13 | ||
| 14 | /// Make a string lowercase | 14 | /// Make a string lowercase |
| 15 | std::string ToLower(std::string str); | 15 | [[nodiscard]] std::string ToLower(std::string str); |
| 16 | 16 | ||
| 17 | /// Make a string uppercase | 17 | /// Make a string uppercase |
| 18 | std::string ToUpper(std::string str); | 18 | [[nodiscard]] std::string ToUpper(std::string str); |
| 19 | 19 | ||
| 20 | std::string StringFromBuffer(const std::vector<u8>& data); | 20 | [[nodiscard]] std::string StringFromBuffer(const std::vector<u8>& data); |
| 21 | 21 | ||
| 22 | std::string StripSpaces(const std::string& s); | 22 | [[nodiscard]] std::string StripSpaces(const std::string& s); |
| 23 | std::string StripQuotes(const std::string& s); | 23 | [[nodiscard]] std::string StripQuotes(const std::string& s); |
| 24 | 24 | ||
| 25 | std::string StringFromBool(bool value); | 25 | [[nodiscard]] std::string StringFromBool(bool value); |
| 26 | 26 | ||
| 27 | std::string TabsToSpaces(int tab_size, std::string in); | 27 | [[nodiscard]] std::string TabsToSpaces(int tab_size, std::string in); |
| 28 | 28 | ||
| 29 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); | 29 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); |
| 30 | 30 | ||
| @@ -34,14 +34,15 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ | |||
| 34 | 34 | ||
| 35 | void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, | 35 | void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, |
| 36 | const std::string& _Filename); | 36 | const std::string& _Filename); |
| 37 | std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest); | 37 | [[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, |
| 38 | const std::string& dest); | ||
| 38 | 39 | ||
| 39 | std::string UTF16ToUTF8(const std::u16string& input); | 40 | [[nodiscard]] std::string UTF16ToUTF8(const std::u16string& input); |
| 40 | std::u16string UTF8ToUTF16(const std::string& input); | 41 | [[nodiscard]] std::u16string UTF8ToUTF16(const std::string& input); |
| 41 | 42 | ||
| 42 | #ifdef _WIN32 | 43 | #ifdef _WIN32 |
| 43 | std::string UTF16ToUTF8(const std::wstring& input); | 44 | [[nodiscard]] std::string UTF16ToUTF8(const std::wstring& input); |
| 44 | std::wstring UTF8ToUTF16W(const std::string& str); | 45 | [[nodiscard]] std::wstring UTF8ToUTF16W(const std::string& str); |
| 45 | 46 | ||
| 46 | #endif | 47 | #endif |
| 47 | 48 | ||
| @@ -50,7 +51,7 @@ std::wstring UTF8ToUTF16W(const std::string& str); | |||
| 50 | * `other` for equality. | 51 | * `other` for equality. |
| 51 | */ | 52 | */ |
| 52 | template <typename InIt> | 53 | template <typename InIt> |
| 53 | bool ComparePartialString(InIt begin, InIt end, const char* other) { | 54 | [[nodiscard]] bool ComparePartialString(InIt begin, InIt end, const char* other) { |
| 54 | for (; begin != end && *other != '\0'; ++begin, ++other) { | 55 | for (; begin != end && *other != '\0'; ++begin, ++other) { |
| 55 | if (*begin != *other) { | 56 | if (*begin != *other) { |
| 56 | return false; | 57 | return false; |
| @@ -64,14 +65,15 @@ bool ComparePartialString(InIt begin, InIt end, const char* other) { | |||
| 64 | * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't | 65 | * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't |
| 65 | * NUL-terminated then the string ends at max_len characters. | 66 | * NUL-terminated then the string ends at max_len characters. |
| 66 | */ | 67 | */ |
| 67 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len); | 68 | [[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, |
| 69 | std::size_t max_len); | ||
| 68 | 70 | ||
| 69 | /** | 71 | /** |
| 70 | * Creates a UTF-16 std::u16string from a fixed-size NUL-terminated char buffer. If the buffer isn't | 72 | * Creates a UTF-16 std::u16string from a fixed-size NUL-terminated char buffer. If the buffer isn't |
| 71 | * null-terminated, then the string ends at the greatest multiple of two less then or equal to | 73 | * null-terminated, then the string ends at the greatest multiple of two less then or equal to |
| 72 | * max_len_bytes. | 74 | * max_len_bytes. |
| 73 | */ | 75 | */ |
| 74 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, | 76 | [[nodiscard]] std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, |
| 75 | std::size_t max_len); | 77 | std::size_t max_len); |
| 76 | 78 | ||
| 77 | } // namespace Common | 79 | } // namespace Common |