/*! \reimp */ QString QTsciiCodec::toUnicode(const char* chars, int len) const { QString result; for (int i = 0; i < len; i++) { uchar ch = chars[i]; if ( ch < 0x80 ) { // ASCII result += QChar(ch); } else if ( IsTSCIIChar(ch) ) { // TSCII uint s[3]; uint u = qt_TSCIIToUnicode(ch, s); uint *p = s; while ( u-- ) { uint c = *p++; result += QValidChar(c); } } else { // Invalid result += QChar::replacement; } } return result; }
QString toUnicode(const char* chars, int len) { QString result; for (int i=0; i<len; i++) { uchar ch = chars[i]; if (esc) { // Escape sequence state = Unknown; switch (nbuf) { case 0: if (ch == '$' || strchr(Esc_CHARS, ch)) { buf[nbuf++] = ch; } else { nbuf = 0; esc = FALSE; } break; case 1: if (buf[0] == '$') { if (strchr(Esc_CHARS, ch)) { buf[nbuf++] = ch; } else { switch (ch) { case '@': state = JISX0208_1978; // Esc $ @ break; case 'B': state = JISX0208_1983; // Esc $ B break; } nbuf = 0; esc = FALSE; } } else { if (buf[0] == '(') { switch (ch) { case 'B': state = Ascii; // Esc ( B break; case 'I': state = JISX0201_Kana; // Esc ( I break; case 'J': state = JISX0201_Latin; // Esc ( J break; } } nbuf = 0; esc = FALSE; } break; case 2: if (buf[1] == '(') { switch (ch) { case 'D': state = JISX0212; // Esc $ ( D break; } } nbuf = 0; esc = FALSE; break; } } else { if (ch == Esc) { // Escape sequence nbuf = 0; esc = TRUE; } else if (ch == So) { // Shift out prev = state; state = JISX0201_Kana; nbuf = 0; } else if (ch == Si) { // Shift in if (prev == Ascii || prev == JISX0201_Latin) { state = prev; } else { state = Ascii; } nbuf = 0; } else { uint u; switch (nbuf) { case 0: switch (state) { case Ascii: if (ch < 0x80) { result += QChar(ch); break; } /* fall throught */ case JISX0201_Latin: u = conv->Jisx0201ToUnicode(ch); result += QValidChar(u); break; case JISX0201_Kana: u = conv->Jisx0201ToUnicode(ch | 0x80); result += QValidChar(u); break; case JISX0208_1978: case JISX0208_1983: case JISX0212: buf[nbuf++] = ch; break; default: result += QChar::replacement; break; } break; case 1: switch (state) { case JISX0208_1978: case JISX0208_1983: u = conv->Jisx0208ToUnicode(buf[0] & 0x7f, ch & 0x7f); result += QValidChar(u); break; case JISX0212: u = conv->Jisx0212ToUnicode(buf[0] & 0x7f, ch & 0x7f); result += QValidChar(u); break; default: result += QChar::replacement; break; } nbuf = 0; break; } } } } return result; }
/*! \internal */ QString QJisCodec::toUnicode(const char* chars, int len) const { QString result; Iso2022State state = Ascii, prev = Ascii; for (int i=0; i<len; i++) { uchar ch = chars[i]; if ( ch == Esc ) { // Escape sequence state = Unknown; if ( i < len-1 ) { uchar c2 = chars[++i]; if (c2 == '$') { if ( i < len-1 ) { uchar c3 = chars[++i]; if (strchr(Esc_CHARS, c3)) { if ( i < len-1 ) { uchar c4 = chars[++i]; if (c4 == '(') { switch (c4) { case 'D': state = JISX0212; // Esc $ ( D break; } } } } else { switch (c3) { case '@': state = JISX0208_1978; // Esc $ @ break; case 'B': state = JISX0208_1983; // Esc $ B break; } } } } else { if (strchr(Esc_CHARS, c2)) { if ( i < len-1 ) { uchar c3 = chars[++i]; if (c2 == '(') { switch (c3) { case 'B': state = Ascii; // Esc ( B break; case 'I': state = JISX0201_Kana; // Esc ( I break; case 'J': state = JISX0201_Latin; // Esc ( J break; } } } } } } } else if (ch == So) { // Shift out prev = state; state = JISX0201_Kana; } else if (ch == Si) { // Shift in if (prev == Ascii || prev == JISX0201_Latin) { state = prev; } else { state = Ascii; } } else { uint u; switch (state) { case Ascii: if (ch < 0x80) { result += QChar(ch); break; } /* fall throught */ case JISX0201_Latin: u = conv->Jisx0201ToUnicode(ch); result += QValidChar(u); break; case JISX0201_Kana: u = conv->Jisx0201ToUnicode(ch | 0x80); result += QValidChar(u); break; case JISX0208_1978: case JISX0208_1983: if ( i < len-1 ) { uchar c2 = chars[++i]; u = conv->Jisx0208ToUnicode(ch & 0x7f, c2 & 0x7f); result += QValidChar(u); } break; case JISX0212: if ( i < len-1 ) { uchar c2 = chars[++i]; u = conv->Jisx0212ToUnicode(ch & 0x7f, c2 & 0x7f); result += QValidChar(u); } break; default: result += QChar::replacement; break; } } } return result; }