]> git.tdb.fi Git - libs/core.git/commitdiff
Put unichar and ustring in their own file
authorMikko Rasa <tdb@tdb.fi>
Sun, 5 Jun 2011 19:58:18 +0000 (22:58 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Jun 2011 19:58:18 +0000 (22:58 +0300)
source/stringcodec/codec.h
source/stringcodec/ustring.h [new file with mode: 0644]
source/stringcodec/utf8.cpp

index cb8006696e52c17042e304cc66efc1ef5d644815..5acbe7b0d1dc34b1d7285c6b96a63665b1ffde2f 100644 (file)
@@ -3,14 +3,11 @@
 
 #include <string>
 #include <msp/core/except.h>
+#include "ustring.h"
 
 namespace Msp {
 namespace StringCodec {
 
-typedef int unichar;
-
-typedef std::basic_string<unichar> ustring;
-
 enum ErrorMode
 {
        THROW_ON_ERROR,
diff --git a/source/stringcodec/ustring.h b/source/stringcodec/ustring.h
new file mode 100644 (file)
index 0000000..1a0a64e
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef MSP_STRINGCODEC_USTRING_H_
+#define MSP_STRINGCODEC_USTRING_H_
+
+#include <string>
+
+namespace Msp {
+namespace StringCodec {
+
+typedef int unichar;
+
+typedef std::basic_string<unichar> ustring;
+
+inline bool is_valid_unichar(unichar ch)
+{ return ch>=0 && ch<=0x10FFFF && (ch<0xD800 || ch>0xDFFF) && (ch&0xFFFE)!=0xFFFE; }
+
+} // namespace StringCodec
+} // namespace Msp
+
+#endif
index 19fe488282561dafbe1d4b788ec3bee0b8cb1b18..4c75d8b073e277c2adc2f38db5f3db806da7b0e5 100644 (file)
@@ -71,7 +71,7 @@ unichar Utf8::Decoder::decode_char(const string &str, string::const_iterator &i)
                        result = error("Incomplete UTF-8 character");
                else if(!(result>>(bytes*5-4)) || !(result>>7))
                        result = error("Denormalized UTF-8 multibyte sequence");
-               else if(result>0x10FFFF || (result>=0xD800 && result<=0xDFFF))
+               else if(!is_valid_unichar(result))
                        result = error("Invalid Unicode code point");
 
                i = j;