From af5680755e23d46c5963741e2c278315ffb75d2f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 8 Nov 2011 11:51:18 +0100 Subject: [PATCH] Move "to_hex()" function from mkvinfo.cpp to the string formatting library --- src/common/strings/formatting.cpp | 12 ++++++++++++ src/common/strings/formatting.h | 6 ++++++ src/info/mkvinfo.cpp | 13 ------------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/common/strings/formatting.cpp b/src/common/strings/formatting.cpp index c3a48cda8..6c3ac42ce 100644 --- a/src/common/strings/formatting.cpp +++ b/src/common/strings/formatting.cpp @@ -240,3 +240,15 @@ format_paragraph(const std::string &text_to_wrap, const char *break_chars) { return to_utf8(format_paragraph(to_wide(text_to_wrap), indent_column, to_wide(indent_first_line), to_wide(indent_following_lines), wrap_column, to_wide(break_chars))); } + +std::string +to_hex(const unsigned char *buf, + size_t size) { + static boost::format s_bf_to_hex("%|1$02x| "); + + std::string hex("0x"); + for (size_t idx = 0; idx < size; ++idx) + hex += (s_bf_to_hex % static_cast(buf[idx])).str(); + + return hex; +} diff --git a/src/common/strings/formatting.h b/src/common/strings/formatting.h index 79a64f98a..513a12595 100644 --- a/src/common/strings/formatting.h +++ b/src/common/strings/formatting.h @@ -60,4 +60,10 @@ std::string to_string(uint64_t value); std::string to_string(double value, unsigned int precision); std::string to_string(int64_t numerator, int64_t denominator, unsigned int precision); +std::string to_hex(const unsigned char *buf, size_t size); +inline std::string +to_hex(const std::string &buf) { + return to_hex(reinterpret_cast(buf.c_str()), buf.length()); +} + #endif // __MTX_COMMON_STRING_FORMATTING_H diff --git a/src/info/mkvinfo.cpp b/src/info/mkvinfo.cpp index 76933f122..ca57be0da 100644 --- a/src/info/mkvinfo.cpp +++ b/src/info/mkvinfo.cpp @@ -321,19 +321,6 @@ create_hexdump(const unsigned char *buf, return hex; } -static std::string -to_hex(const unsigned char *buf, - int size) { - static boost::format s_bf_to_hex(" 0x%|1$02x|"); - - std::string hex; - int b; - for (b = 0; b < size; ++b) - hex += (s_bf_to_hex % (int)buf[b]).str(); - - return hex; -} - std::string create_codec_dependent_private_info(KaxCodecPrivate &c_priv, char track_type,