]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/except.cpp
Additional adjustments for Poller
[libs/core.git] / source / stringcodec / except.cpp
1 #include <msp/strings/format.h>
2 #include "except.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace StringCodec {
8
9 invalid_character::invalid_character(unichar ch, const string &detail):
10         codec_error(format("U+%04X (%s)", ch, detail))
11 { }
12
13
14 invalid_sequence::invalid_sequence(const string::const_iterator &begin, const string::const_iterator &end, const string &detail):
15         codec_error(format("%s (%s)", format_sequence(begin, end), detail))
16 { }
17
18 string invalid_sequence::format_sequence(const string::const_iterator &begin, const string::const_iterator &end)
19 {
20         string result;
21         for(string::const_iterator i=begin; i!=end; ++i)
22         {
23                 if(!result.empty())
24                         result += ' ';
25                 result += lexical_cast<string>(static_cast<unsigned char>(*i), Fmt().fill('0').width(2).hex().uppercase());
26         }
27         return result;
28 }
29
30 } // namespace StringCodec
31 } // namespace Msp