Value* toUpperCase(Value* value)
    {
        std::string result;
        const char* next = value->toString().c_str();
        while (next && *next)
        {
            char utf8[5];
            u32 utf32;

            next = utf8to32(next, &utf32);
            char* nextResult = utf32to8(utftoupper(utf32), utf8);
            if (nextResult)
            {
                *nextResult = '\0';
                result += utf8;
            }
        }
        return new StringValue(result);
    }
    Value* fromCharCode()
    {
        ListValue* list = static_cast<ListValue*>(getScopeChain()->get("arguments"));

        u32 numChars = list->length();

        std::string result = "";
        u16 utf16;
        for (u32 i = 0; i < numChars; ++i)
        {
            utf16 = static_cast<u16>((*list)[i]->toUint16());
            char utf8[5];
            char* next = utf32to8(utf16, utf8);
            if (next)
            {
                *next = 0;
                result += utf8;
            }
        }
        return new StringValue(result);
    }
int main(int argc, char* argv[])
{
    if (argc != 2) {
        std::cout << "usage: " << argv[0] << " html_file\n";
        exit(EXIT_FAILURE);
    }
    int rc = EXIT_SUCCESS;
    std::ifstream stream(argv[1]);
    if (!stream) {
        std::cerr << "error: cannot open " << argv[1] << ".\n";
        return EXIT_FAILURE;
    }
    HTMLInputStream htmlInputStream(stream);
    char16_t c;
    while (htmlInputStream.getChar(c)) {
        char utf8[5];
        char* end = utf32to8(c, utf8);
        *end = '\0';
        std::cout << utf8;
    }
    return rc;
}
Exemple #4
0
gboolean module_feedkey(int key, int kvstate)
{
  int i;
#if 0
  if (key <= XK_KP_9 && key >= XK_KP_0)
    key -= XK_KP_0 - '0';
#endif
  key=toupper(key);
  if (key==XK_BackSpace||key==XK_Delete) {
#if WIN32
    if (*gmf.mf_test_mode)
      return intcode_cin>0;
#endif
    if (intcode_cin)
      intcode_cin--;
    else
      return 0;

    goto dispIn;
  }
  else
  if ((key<'0'||key>'F'||(key>'9' && key<'A')) && (key!=' ')){
    return 0;
  }

  if (current_intcode==INTCODE_BIG5) {
    if (intcode_cin==0 && key<'8')
      return 1;
    if (intcode_cin==1 && inch[0]=='F' && key=='F')
      return 1;
    if (intcode_cin==2 && (key<'4' || (key>'7' && key<'A')))
      return 1;
    if (intcode_cin==3 && (inch[2]=='7'||inch[2]=='F') && key=='F')
      return 1;
  }

  if (!intcode_cin && key==' ')
    return 0;
#if WIN32
  if (*gmf.mf_test_mode)
    return 1;
#endif
  if ((intcode_cin<MAX_INTCODE-1 || (current_intcode!=INTCODE_BIG5 && intcode_cin < MAX_INTCODE)) && key!=' ')
    inch[intcode_cin++]=key;

dispIn:
  clear_int_code_all();

#if 1
  if (intcode_cin)
    module_show_win();
#endif

  for(i=0;i<intcode_cin;i++) {
    disp_int(i, _(dstr[h2i(inch[i])]));
  }

  if ((current_intcode==INTCODE_BIG5 && intcode_cin==4 ||
       current_intcode==INTCODE_UTF32 && intcode_cin==6) &&
      *gmf.mf_gtab_press_full_auto_send || key==' ') {
    u_char utf8[CH_SZ+1];

    if (current_intcode==INTCODE_BIG5) {
      u_char ttt[3];
      ttt[2]=ttt[3]=0;
      ttt[0]=(h2i(inch[0])<<4)+h2i(inch[1]);
      ttt[1]=(h2i(inch[2])<<4)+h2i(inch[3]);
      big5_utf8((char *)ttt, (char *)utf8);
    } else {
      int i;
      u_int v = 0;

      for(i=0; i < intcode_cin; i++) {
        v <<= 4;
        v |= h2i(inch[i]);
      }

      utf32to8((char *)utf8, (char *)&v);
    }

    gmf.mf_send_utf8_ch((char *)utf8);
    intcode_cin=0;

    clear_int_code_all();
  }

  return 1;
}
inline void
wchar_to_utf8_impl< 4 >( const std::wstring & in , std::string & out )
{
    utf32to8( in.begin() , in.end() , std::back_inserter(out) );
}