diff options
Diffstat (limited to 'src/common/string_util.h')
| -rw-r--r-- | src/common/string_util.h | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/common/string_util.h b/src/common/string_util.h index 89d9f133e..075bf4ecb 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <sstream> | 10 | #include <sstream> |
| 11 | #include <string> | 11 | #include <string> |
| 12 | #include <vector> | 12 | #include <vector> |
| 13 | |||
| 14 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 15 | 14 | ||
| 16 | namespace Common { | 15 | namespace Common { |
| @@ -25,9 +24,8 @@ std::string StringFromFormat(const char* format, ...); | |||
| 25 | // Cheap! | 24 | // Cheap! |
| 26 | bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args); | 25 | bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args); |
| 27 | 26 | ||
| 28 | template<size_t Count> | 27 | template <size_t Count> |
| 29 | inline void CharArrayFromFormat(char (& out)[Count], const char* format, ...) | 28 | inline void CharArrayFromFormat(char (&out)[Count], const char* format, ...) { |
| 30 | { | ||
| 31 | va_list args; | 29 | va_list args; |
| 32 | va_start(args, format); | 30 | va_start(args, format); |
| 33 | CharArrayFromFormatV(out, Count, format, args); | 31 | CharArrayFromFormatV(out, Count, format, args); |
| @@ -35,15 +33,14 @@ inline void CharArrayFromFormat(char (& out)[Count], const char* format, ...) | |||
| 35 | } | 33 | } |
| 36 | 34 | ||
| 37 | // Good | 35 | // Good |
| 38 | std::string ArrayToString(const u8 *data, u32 size, int line_len = 20, bool spaces = true); | 36 | std::string ArrayToString(const u8* data, u32 size, int line_len = 20, bool spaces = true); |
| 39 | 37 | ||
| 40 | std::string StripSpaces(const std::string &s); | 38 | std::string StripSpaces(const std::string& s); |
| 41 | std::string StripQuotes(const std::string &s); | 39 | std::string StripQuotes(const std::string& s); |
| 42 | 40 | ||
| 43 | // Thousand separator. Turns 12345678 into 12,345,678 | 41 | // Thousand separator. Turns 12345678 into 12,345,678 |
| 44 | template <typename I> | 42 | template <typename I> |
| 45 | std::string ThousandSeparate(I value, int spaces = 0) | 43 | std::string ThousandSeparate(I value, int spaces = 0) { |
| 46 | { | ||
| 47 | std::ostringstream oss; | 44 | std::ostringstream oss; |
| 48 | 45 | ||
| 49 | // std::locale("") seems to be broken on many platforms | 46 | // std::locale("") seems to be broken on many platforms |
| @@ -57,35 +54,34 @@ std::string ThousandSeparate(I value, int spaces = 0) | |||
| 57 | 54 | ||
| 58 | std::string StringFromBool(bool value); | 55 | std::string StringFromBool(bool value); |
| 59 | 56 | ||
| 60 | bool TryParse(const std::string &str, bool *output); | 57 | bool TryParse(const std::string& str, bool* output); |
| 61 | bool TryParse(const std::string &str, u32 *output); | 58 | bool TryParse(const std::string& str, u32* output); |
| 62 | 59 | ||
| 63 | template <typename N> | 60 | template <typename N> |
| 64 | static bool TryParse(const std::string &str, N *const output) | 61 | static bool TryParse(const std::string& str, N* const output) { |
| 65 | { | ||
| 66 | std::istringstream iss(str); | 62 | std::istringstream iss(str); |
| 67 | 63 | ||
| 68 | N tmp = 0; | 64 | N tmp = 0; |
| 69 | if (iss >> tmp) | 65 | if (iss >> tmp) { |
| 70 | { | ||
| 71 | *output = tmp; | 66 | *output = tmp; |
| 72 | return true; | 67 | return true; |
| 73 | } | 68 | } else |
| 74 | else | ||
| 75 | return false; | 69 | return false; |
| 76 | } | 70 | } |
| 77 | 71 | ||
| 78 | // TODO: kill this | 72 | // TODO: kill this |
| 79 | bool AsciiToHex(const char* _szValue, u32& result); | 73 | bool AsciiToHex(const char* _szValue, u32& result); |
| 80 | 74 | ||
| 81 | std::string TabsToSpaces(int tab_size, const std::string &in); | 75 | std::string TabsToSpaces(int tab_size, const std::string& in); |
| 82 | 76 | ||
| 83 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); | 77 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); |
| 84 | 78 | ||
| 85 | // "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe" | 79 | // "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe" |
| 86 | bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension); | 80 | bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, |
| 81 | std::string* _pExtension); | ||
| 87 | 82 | ||
| 88 | void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, const std::string& _Filename); | 83 | void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, |
| 84 | const std::string& _Filename); | ||
| 89 | std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest); | 85 | std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest); |
| 90 | 86 | ||
| 91 | std::string UTF16ToUTF8(const std::u16string& input); | 87 | std::string UTF16ToUTF8(const std::u16string& input); |
| @@ -99,17 +95,21 @@ std::string UTF16ToUTF8(const std::wstring& input); | |||
| 99 | std::wstring UTF8ToUTF16W(const std::string& str); | 95 | std::wstring UTF8ToUTF16W(const std::string& str); |
| 100 | 96 | ||
| 101 | #ifdef _UNICODE | 97 | #ifdef _UNICODE |
| 102 | inline std::string TStrToUTF8(const std::wstring& str) | 98 | inline std::string TStrToUTF8(const std::wstring& str) { |
| 103 | { return UTF16ToUTF8(str); } | 99 | return UTF16ToUTF8(str); |
| 100 | } | ||
| 104 | 101 | ||
| 105 | inline std::wstring UTF8ToTStr(const std::string& str) | 102 | inline std::wstring UTF8ToTStr(const std::string& str) { |
| 106 | { return UTF8ToUTF16W(str); } | 103 | return UTF8ToUTF16W(str); |
| 104 | } | ||
| 107 | #else | 105 | #else |
| 108 | inline std::string TStrToUTF8(const std::string& str) | 106 | inline std::string TStrToUTF8(const std::string& str) { |
| 109 | { return str; } | 107 | return str; |
| 108 | } | ||
| 110 | 109 | ||
| 111 | inline std::string UTF8ToTStr(const std::string& str) | 110 | inline std::string UTF8ToTStr(const std::string& str) { |
| 112 | { return str; } | 111 | return str; |
| 112 | } | ||
| 113 | #endif | 113 | #endif |
| 114 | 114 | ||
| 115 | #endif | 115 | #endif |
| @@ -134,5 +134,4 @@ bool ComparePartialString(InIt begin, InIt end, const char* other) { | |||
| 134 | * NUL-terminated then the string ends at max_len characters. | 134 | * NUL-terminated then the string ends at max_len characters. |
| 135 | */ | 135 | */ |
| 136 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, size_t max_len); | 136 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, size_t max_len); |
| 137 | |||
| 138 | } | 137 | } |