diff options
| author | Chris Burgener <christhecoolist@gmail.com> | 2016-06-18 21:58:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-18 21:58:04 -0400 |
| commit | 65f76cfc634af50fd9c42f41ab5abf531cfa1a55 (patch) | |
| tree | c99c8d750687e676ec36237d38b3b3c13551c5f1 /Source/Core/Common/StringUtil.cpp | |
| parent | f3f35d29bc641dc542dc116add3b00865a1d2040 (diff) | |
| parent | 63dab254e06a3aee934609663251d8bce7b1dac4 (diff) | |
Merge pull request #3905 from delroth/analytics
Analytics reporting support
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 2eb68a944a..007da2685a 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -36,6 +36,39 @@ static locale_t GetCLocale() } #endif +std::string HexDump(const u8* data, size_t size) +{ + constexpr size_t BYTES_PER_LINE = 16; + + std::string out; + for (size_t row_start = 0; row_start < size; row_start += BYTES_PER_LINE) + { + out += StringFromFormat("%06zx: ", row_start); + for (size_t i = 0; i < BYTES_PER_LINE; ++i) + { + if (row_start + i < size) + { + out += StringFromFormat("%02hhx ", data[row_start + i]); + } + else + { + out += " "; + } + } + out += " "; + for (size_t i = 0; i < BYTES_PER_LINE; ++i) + { + if (row_start + i < size) + { + char c = static_cast<char>(data[row_start + i]); + out += StringFromFormat("%c", isprint(c) ? c : '.'); + } + } + out += "\n"; + } + return out; +} + // faster than sscanf bool AsciiToHex(const std::string& _szValue, u32& result) { |
