]> git.tdb.fi Git - libs/core.git/blob - source/ascii.cpp
6ffaf9a1facf2a3a1b0eac6da90d3578aa482639
[libs/core.git] / source / ascii.cpp
1 /* $Id$
2
3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #include "ascii.h"
9
10 using namespace std;
11
12 namespace Msp {
13
14 void Ascii::Encoder::encode_char(wchar_t c_)
15 {
16         // Win32 has typedef unsigned short wchar_t
17         int c=c_;
18         if(c<0 || c>0x7F)
19                 error("Can't express character in ASCII");
20         else
21                 append(c);
22 }
23
24
25 void Ascii::Decoder::decode_char(const string &str, string::const_iterator &i)
26 {
27         if(i==str.end())
28                 return;
29         else if(*i&0x80)
30         {
31                 error("Invalid ASCII string (undefined character)");
32                 ++i;
33         }
34         else
35                 append(*i++);
36 }
37
38 } // namespace Msp