#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,
--- /dev/null
+#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
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;