X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstringcodec%2Fexcept.cpp;fp=source%2Fstringcodec%2Fexcept.cpp;h=045f44af107613b5134cabde1245c17720b98da3;hp=0000000000000000000000000000000000000000;hb=94ee3a1040f67d9de2e92fc34049642b08d65b3e;hpb=93bb92bad766d269a6bac87e00020a6158531739 diff --git a/source/stringcodec/except.cpp b/source/stringcodec/except.cpp new file mode 100644 index 0000000..045f44a --- /dev/null +++ b/source/stringcodec/except.cpp @@ -0,0 +1,31 @@ +#include +#include "except.h" + +using namespace std; + +namespace Msp { +namespace StringCodec { + +invalid_character::invalid_character(unichar ch, const string &detail): + codec_error(format("invalid character: U+%04X (%s)", ch, detail)) +{ } + + +invalid_sequence::invalid_sequence(const string::const_iterator &begin, const string::const_iterator &end, const string &detail): + codec_error(format("invalid sequence: %s (%s)", format_sequence(begin, end), detail)) +{ } + +string invalid_sequence::format_sequence(const string::const_iterator &begin, const string::const_iterator &end) +{ + string result; + for(string::const_iterator i=begin; i!=end; ++i) + { + if(!result.empty()) + result += ' '; + result += lexical_cast(static_cast(*i), Fmt().fill('0').width(2).hex().uppercase()); + } + return result; +} + +} // namespace StringCodec +} // namespace Msp