]> git.tdb.fi Git - libs/core.git/blob - source/ascii.cpp
43f7053173a21e1ac5cc3b79bc3cdad3def303de
[libs/core.git] / source / ascii.cpp
1 #include "ascii.h"
2
3 using namespace std;
4
5 namespace Msp {
6
7 void Ascii::Encoder::encode_char(wchar_t c_)
8 {
9         // Win32 has typedef unsigned short wchar_t
10         int c=c_;
11         if(c<0 || c>0x7F)
12                 error("Can't express character in ASCII");
13         else
14                 append(c);
15 }
16
17
18 void Ascii::Decoder::decode_char(const string &str, string::const_iterator &i)
19 {
20         if(i==str.end())
21                 return;
22         else if(*i&0x80)
23         {
24                 error("Invalid ASCII string (undefined character)");
25                 ++i;
26         }
27         else
28                 append(*i++);
29 }
30
31 } // namespace Msp