diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/string_util.cpp | 9 | ||||
| -rw-r--r-- | src/common/string_util.h | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 14f7037d8..a1360dd26 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -214,6 +214,15 @@ std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t | |||
| 214 | return std::string(buffer, len); | 214 | return std::string(buffer, len); |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(const char16_t* buffer, | ||
| 218 | std::size_t max_len) { | ||
| 219 | std::size_t len = 0; | ||
| 220 | while (len < max_len && buffer[len] != '\0') | ||
| 221 | ++len; | ||
| 222 | |||
| 223 | return std::u16string(buffer, len); | ||
| 224 | } | ||
| 225 | |||
| 217 | const char* TrimSourcePath(const char* path, const char* root) { | 226 | const char* TrimSourcePath(const char* path, const char* root) { |
| 218 | const char* p = path; | 227 | const char* p = path; |
| 219 | 228 | ||
diff --git a/src/common/string_util.h b/src/common/string_util.h index 08f96533b..95b7badaf 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -67,6 +67,14 @@ bool ComparePartialString(InIt begin, InIt end, const char* other) { | |||
| 67 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len); | 67 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len); |
| 68 | 68 | ||
| 69 | /** | 69 | /** |
| 70 | * Creates a UTF-16 std::u16string from a fixed-size NUL-terminated char buffer. If the buffer isn't | ||
| 71 | * NUL-terminated, then the string ends at the greatest multiple of two less then or equal to | ||
| 72 | * max_len_bytes. | ||
| 73 | */ | ||
| 74 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(const char16_t* buffer, | ||
| 75 | std::size_t max_len); | ||
| 76 | |||
| 77 | /** | ||
| 70 | * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's | 78 | * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's |
| 71 | * intended to be used to strip a system-specific build directory from the `__FILE__` macro, | 79 | * intended to be used to strip a system-specific build directory from the `__FILE__` macro, |
| 72 | * leaving only the path relative to the sources root. | 80 | * leaving only the path relative to the sources root. |