]> git.tdb.fi Git - libs/core.git/blobdiff - source/stringcodec/except.cpp
Exception changes
[libs/core.git] / source / stringcodec / except.cpp
diff --git a/source/stringcodec/except.cpp b/source/stringcodec/except.cpp
new file mode 100644 (file)
index 0000000..045f44a
--- /dev/null
@@ -0,0 +1,31 @@
+#include <msp/strings/format.h>
+#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<unsigned char>(*i), Fmt().fill('0').width(2).hex().uppercase());
+       }
+       return result;
+}
+
+} // namespace StringCodec
+} // namespace Msp