]> git.tdb.fi Git - libs/core.git/blobdiff - source/jisx0208.cpp
Add copyright notices and Id tags
[libs/core.git] / source / jisx0208.cpp
index 0f0e73d7545afdba78e5ddc68f3ad92686bd28c0..1e5aec7db0bbafb63f06c55c961e5b2648acb69f 100644 (file)
@@ -1,3 +1,10 @@
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
 #include "jisx0208.h"
 
 #include "jisx0208.table"
@@ -9,10 +16,13 @@ namespace Msp {
 void JisX0208::Encoder::encode_char(wchar_t ucs)
 {
        unsigned short jis=ucs_to_jisx0208(ucs);
-       if(!jis) throw CodecError("Can't express character in JIS X 0208");
-
-       char buf[2]={jis>>8, jis};
-       append(buf, 2);
+       if(jis)
+       {
+               char buf[2]={jis>>8, jis};
+               append(buf, 2);
+       }
+       else
+               error("Can't express character in JIS X 0208");
 }
 
 
@@ -30,19 +40,21 @@ void JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i
        wchar_t ucs=jisx0208_to_ucs(high<<8 | *i++);
        high=0;
 
-       if(!ucs)
-               throw CodecError("Invalid JIS X 0208 string (undefined character)");
-
-       append(ucs);
+       if(ucs)
+               append(ucs);
+       else
+               error("Invalid JIS X 0208 string (undefined character)");
 }
 
 void JisX0208::Decoder::sync()
 {
        if(high)
-               throw CodecError("Sync in middle of JIS X 0208 character");
+       {
+               error("Sync in middle of JIS X 0208 character");
+               high=0;
+       }
 }
 
-
 wchar_t jisx0208_to_ucs(unsigned short jis)
 {
        if((jis&0xFF)<0x21 || (jis&0xFF)>0x7E || (jis&0xFF00)<0x2100 || (jis&0xFF00)>0x7E00)
@@ -60,11 +72,11 @@ unsigned short ucs_to_jisx0208(wchar_t c)
        {
                if(i+bit>=ucs_to_jisx0208_table_size)
                        continue;
-               if(ucs_to_jisx0208_table[i+bit].ucs<=(unsigned short)c)
+               if(ucs_to_jisx0208_table[i+bit].ucs<=static_cast<unsigned short>(c))
                        i+=bit;
        }
 
-       if(ucs_to_jisx0208_table[i].ucs==(unsigned short)c)
+       if(ucs_to_jisx0208_table[i].ucs==static_cast<unsigned short>(c))
                return ucs_to_jisx0208_table[i].jis;
        return 0;
 }