diff options
| author | 2018-09-19 19:53:11 +0800 | |
|---|---|---|
| committer | 2018-09-19 19:53:11 +0800 | |
| commit | c8f9bbbf859c0e38cf691b64c67761382fcebfc2 (patch) | |
| tree | 99529c2277a6b740a6e278985c5147fa649c5497 /src/common/string_util.cpp | |
| parent | Add 1D sampler for TLDS - TexelFetch (Mario Rabbids) (diff) | |
| parent | Merge pull request #1348 from ogniK5377/GetImageSize (diff) | |
| download | yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.gz yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.xz yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.zip | |
Merge branch 'master' into tlds
Diffstat (limited to 'src/common/string_util.cpp')
| -rw-r--r-- | src/common/string_util.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 0ca663032..c9a5425a7 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -37,7 +37,7 @@ std::string ToUpper(std::string str) { | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | // For Debugging. Read out an u8 array. | 39 | // For Debugging. Read out an u8 array. |
| 40 | std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { | 40 | std::string ArrayToString(const u8* data, std::size_t size, int line_len, bool spaces) { |
| 41 | std::ostringstream oss; | 41 | std::ostringstream oss; |
| 42 | oss << std::setfill('0') << std::hex; | 42 | oss << std::setfill('0') << std::hex; |
| 43 | 43 | ||
| @@ -60,7 +60,7 @@ std::string StringFromBuffer(const std::vector<u8>& data) { | |||
| 60 | 60 | ||
| 61 | // Turns " hej " into "hej". Also handles tabs. | 61 | // Turns " hej " into "hej". Also handles tabs. |
| 62 | std::string StripSpaces(const std::string& str) { | 62 | std::string StripSpaces(const std::string& str) { |
| 63 | const size_t s = str.find_first_not_of(" \t\r\n"); | 63 | const std::size_t s = str.find_first_not_of(" \t\r\n"); |
| 64 | 64 | ||
| 65 | if (str.npos != s) | 65 | if (str.npos != s) |
| 66 | return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); | 66 | return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); |
| @@ -121,10 +121,10 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ | |||
| 121 | if (full_path.empty()) | 121 | if (full_path.empty()) |
| 122 | return false; | 122 | return false; |
| 123 | 123 | ||
| 124 | size_t dir_end = full_path.find_last_of("/" | 124 | std::size_t dir_end = full_path.find_last_of("/" |
| 125 | // windows needs the : included for something like just "C:" to be considered a directory | 125 | // windows needs the : included for something like just "C:" to be considered a directory |
| 126 | #ifdef _WIN32 | 126 | #ifdef _WIN32 |
| 127 | "\\:" | 127 | "\\:" |
| 128 | #endif | 128 | #endif |
| 129 | ); | 129 | ); |
| 130 | if (std::string::npos == dir_end) | 130 | if (std::string::npos == dir_end) |
| @@ -132,7 +132,7 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ | |||
| 132 | else | 132 | else |
| 133 | dir_end += 1; | 133 | dir_end += 1; |
| 134 | 134 | ||
| 135 | size_t fname_end = full_path.rfind('.'); | 135 | std::size_t fname_end = full_path.rfind('.'); |
| 136 | if (fname_end < dir_end || std::string::npos == fname_end) | 136 | if (fname_end < dir_end || std::string::npos == fname_end) |
| 137 | fname_end = full_path.size(); | 137 | fname_end = full_path.size(); |
| 138 | 138 | ||
| @@ -172,7 +172,7 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri | |||
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | std::string TabsToSpaces(int tab_size, std::string in) { | 174 | std::string TabsToSpaces(int tab_size, std::string in) { |
| 175 | size_t i = 0; | 175 | std::size_t i = 0; |
| 176 | 176 | ||
| 177 | while ((i = in.find('\t')) != std::string::npos) { | 177 | while ((i = in.find('\t')) != std::string::npos) { |
| 178 | in.replace(i, 1, tab_size, ' '); | 178 | in.replace(i, 1, tab_size, ' '); |
| @@ -182,7 +182,7 @@ std::string TabsToSpaces(int tab_size, std::string in) { | |||
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) { | 184 | std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) { |
| 185 | size_t pos = 0; | 185 | std::size_t pos = 0; |
| 186 | 186 | ||
| 187 | if (src == dest) | 187 | if (src == dest) |
| 188 | return result; | 188 | return result; |
| @@ -280,22 +280,22 @@ static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& | |||
| 280 | return {}; | 280 | return {}; |
| 281 | } | 281 | } |
| 282 | 282 | ||
| 283 | const size_t in_bytes = sizeof(T) * input.size(); | 283 | const std::size_t in_bytes = sizeof(T) * input.size(); |
| 284 | // Multiply by 4, which is the max number of bytes to encode a codepoint | 284 | // Multiply by 4, which is the max number of bytes to encode a codepoint |
| 285 | const size_t out_buffer_size = 4 * in_bytes; | 285 | const std::size_t out_buffer_size = 4 * in_bytes; |
| 286 | 286 | ||
| 287 | std::string out_buffer(out_buffer_size, '\0'); | 287 | std::string out_buffer(out_buffer_size, '\0'); |
| 288 | 288 | ||
| 289 | auto src_buffer = &input[0]; | 289 | auto src_buffer = &input[0]; |
| 290 | size_t src_bytes = in_bytes; | 290 | std::size_t src_bytes = in_bytes; |
| 291 | auto dst_buffer = &out_buffer[0]; | 291 | auto dst_buffer = &out_buffer[0]; |
| 292 | size_t dst_bytes = out_buffer.size(); | 292 | std::size_t dst_bytes = out_buffer.size(); |
| 293 | 293 | ||
| 294 | while (0 != src_bytes) { | 294 | while (0 != src_bytes) { |
| 295 | size_t const iconv_result = | 295 | std::size_t const iconv_result = |
| 296 | iconv(conv_desc, (char**)(&src_buffer), &src_bytes, &dst_buffer, &dst_bytes); | 296 | iconv(conv_desc, (char**)(&src_buffer), &src_bytes, &dst_buffer, &dst_bytes); |
| 297 | 297 | ||
| 298 | if (static_cast<size_t>(-1) == iconv_result) { | 298 | if (static_cast<std::size_t>(-1) == iconv_result) { |
| 299 | if (EILSEQ == errno || EINVAL == errno) { | 299 | if (EILSEQ == errno || EINVAL == errno) { |
| 300 | // Try to skip the bad character | 300 | // Try to skip the bad character |
| 301 | if (0 != src_bytes) { | 301 | if (0 != src_bytes) { |
| @@ -326,22 +326,22 @@ std::u16string UTF8ToUTF16(const std::string& input) { | |||
| 326 | return {}; | 326 | return {}; |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | const size_t in_bytes = sizeof(char) * input.size(); | 329 | const std::size_t in_bytes = sizeof(char) * input.size(); |
| 330 | // Multiply by 4, which is the max number of bytes to encode a codepoint | 330 | // Multiply by 4, which is the max number of bytes to encode a codepoint |
| 331 | const size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes; | 331 | const std::size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes; |
| 332 | 332 | ||
| 333 | std::u16string out_buffer(out_buffer_size, char16_t{}); | 333 | std::u16string out_buffer(out_buffer_size, char16_t{}); |
| 334 | 334 | ||
| 335 | char* src_buffer = const_cast<char*>(&input[0]); | 335 | char* src_buffer = const_cast<char*>(&input[0]); |
| 336 | size_t src_bytes = in_bytes; | 336 | std::size_t src_bytes = in_bytes; |
| 337 | char* dst_buffer = (char*)(&out_buffer[0]); | 337 | char* dst_buffer = (char*)(&out_buffer[0]); |
| 338 | size_t dst_bytes = out_buffer.size(); | 338 | std::size_t dst_bytes = out_buffer.size(); |
| 339 | 339 | ||
| 340 | while (0 != src_bytes) { | 340 | while (0 != src_bytes) { |
| 341 | size_t const iconv_result = | 341 | std::size_t const iconv_result = |
| 342 | iconv(conv_desc, &src_buffer, &src_bytes, &dst_buffer, &dst_bytes); | 342 | iconv(conv_desc, &src_buffer, &src_bytes, &dst_buffer, &dst_bytes); |
| 343 | 343 | ||
| 344 | if (static_cast<size_t>(-1) == iconv_result) { | 344 | if (static_cast<std::size_t>(-1) == iconv_result) { |
| 345 | if (EILSEQ == errno || EINVAL == errno) { | 345 | if (EILSEQ == errno || EINVAL == errno) { |
| 346 | // Try to skip the bad character | 346 | // Try to skip the bad character |
| 347 | if (0 != src_bytes) { | 347 | if (0 != src_bytes) { |
| @@ -381,8 +381,8 @@ std::string SHIFTJISToUTF8(const std::string& input) { | |||
| 381 | 381 | ||
| 382 | #endif | 382 | #endif |
| 383 | 383 | ||
| 384 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, size_t max_len) { | 384 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) { |
| 385 | size_t len = 0; | 385 | std::size_t len = 0; |
| 386 | while (len < max_len && buffer[len] != '\0') | 386 | while (len < max_len && buffer[len] != '\0') |
| 387 | ++len; | 387 | ++len; |
| 388 | 388 | ||