Beispiel #1
0
 static void apply( const Input& in, std::string& s )
 {
    assert( !in.empty() );  // First character MUST be present, usually 'u' or 'U'.
    if( !utf8_append_utf32( s, unhex_string< unsigned >( in.begin() + 1, in.end() ) ) ) {
       throw parse_error( "invalid escaped unicode code point", in );
    }
 }
Beispiel #2
0
 static void apply( const Input& in, State& st )
 {
    assert( ( ( in.size() + 1 ) % 6 ) == 0 );  // Expects multiple "\\u1234", starting with the first "u".
    for( const char* b = in.begin() + 1; b < in.end(); b += 6 ) {
       const auto c = unhex_string< unsigned >( b, b + 4 );
       if( ( 0xd800 <= c ) && ( c <= 0xdbff ) && ( b + 6 < in.end() ) ) {
          const auto d = unhex_string< unsigned >( b + 6, b + 10 );
          if( ( 0xdc00 <= d ) && ( d <= 0xdfff ) ) {
             b += 6;
             utf8_append_utf32( st.unescaped, ( ( ( c & 0x03ff ) << 10 ) | ( d & 0x03ff ) ) + 0x10000 );
             continue;
          }
       }
       utf8_append_utf32( st.unescaped, c );
    }
 }
Beispiel #3
0
 static void apply( const Input& in, std::string& s )
 {
    assert( ( ( in.size() + 1 ) % 6 ) == 0 );  // Expects multiple "\\u1234", starting with the first "u".
    for( const char* b = in.begin() + 1; b < in.end(); b += 6 ) {
       const auto c = unhex_string< unsigned >( b, b + 4 );
       if( ( 0xd800 <= c ) && ( c <= 0xdbff ) && ( b + 6 < in.end() ) ) {
          const auto d = unhex_string< unsigned >( b + 6, b + 10 );
          if( ( 0xdc00 <= d ) && ( d <= 0xdfff ) ) {
             b += 6;
             (void)utf8_append_utf32( s, ( ( ( c & 0x03ff ) << 10 ) | ( d & 0x03ff ) ) + 0x10000 );
             continue;
          }
       }
       if( !utf8_append_utf32( s, c ) ) {
          throw parse_error( "invalid escaped unicode code point", in );
       }
    }
 }