QByteArray QEucJpCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const { char replacement = '?'; if (state) { if (state->flags & ConvertInvalidToNull) replacement = 0; } int invalid = 0; int rlen = 3*len + 1; QByteArray rstr; rstr.resize(rlen); uchar* cursor = (uchar*)rstr.data(); for (int i = 0; i < len; i++) { QChar ch = uc[i]; uint j; if (ch.unicode() < 0x80) { // ASCII *cursor++ = ch.cell(); } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) { if (j < 0x80) { // JIS X 0201 Latin ? *cursor++ = j; } else { // JIS X 0201 Kana *cursor++ = Ss2; *cursor++ = j; } } else if ((j = conv->unicodeToJisx0208(ch.row(), ch.cell())) != 0) { // JIS X 0208 *cursor++ = (j >> 8) | 0x80; *cursor++ = (j & 0xff) | 0x80; } else if ((j = conv->unicodeToJisx0212(ch.row(), ch.cell())) != 0) {
/*! \reimp */ QCString QEucJpCodec::fromUnicode(const QString& uc, int& lenInOut) const { int l = QMIN((int)uc.length(),lenInOut); int rlen = l*3+1; QCString rstr(rlen); uchar* cursor = (uchar*)rstr.data(); for (int i=0; i<l; i++) { QChar ch = uc[i]; uint j; if ( ch.row() == 0x00 && ch.cell() < 0x80 ) { // ASCII *cursor++ = ch.cell(); } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) { if (j < 0x80) { // JIS X 0201 Latin ? *cursor++ = j; } else { // JIS X 0201 Kana *cursor++ = Ss2; *cursor++ = j; } } else if ((j = conv->unicodeToJisx0208(ch.row(), ch.cell())) != 0) { // JIS X 0208 *cursor++ = (j >> 8) | 0x80; *cursor++ = (j & 0xff) | 0x80; } else if ((j = conv->unicodeToJisx0212(ch.row(), ch.cell())) != 0) {
QByteArray QSjisCodec::convertFromUnicode(const ushort* uc, int len, ConverterState *state) { char replacement = '?'; if (state) { if (state->flags & ConvertInvalidToNull) replacement = 0; } int invalid = 0; int rlen = 2*len + 1; QByteArray rstr; rstr.resize(rlen); uchar* cursor = (uchar*)rstr.data(); for (int i = 0; i < len; i++) { QChar ch = uc[i]; uint j; if (ch.row() == 0x00 && ch.cell() < 0x80) { // ASCII *cursor++ = ch.cell(); } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) { // JIS X 0201 Latin or JIS X 0201 Kana *cursor++ = j; } else if ((j = conv->unicodeToSjis(ch.row(), ch.cell())) != 0) { // JIS X 0208 *cursor++ = (j >> 8); *cursor++ = (j & 0xff); } else if ((j = conv->unicodeToSjisibmvdc(ch.row(), ch.cell())) != 0) {
/*! \internal */ QCString QJisCodec::fromUnicode(const QString& uc, int& len_in_out) const { int l = QMIN((int)uc.length(),len_in_out); QCString result; Iso2022State state = Ascii; Iso2022State prev = Ascii; for (int i=0; i<l; i++) { QChar ch = uc[i]; uint j; if ( ch.row() == 0x00 && ch.cell() < 0x80 ) { // Ascii if (state != JISX0201_Latin || ch.cell() == ReverseSolidus || ch.cell() == Tilde) { state = Ascii; } j = ch.cell(); } else if ((j = conv->UnicodeToJisx0201(ch.row(), ch.cell())) != 0) { if (j < 0x80) { // JIS X 0201 Latin if (state != Ascii || ch.cell() == YenSign || ch.cell() == Overline) { state = JISX0201_Latin; } } else { // JIS X 0201 Kana state = JISX0201_Kana; j &= 0x7f; } } else if ((j = conv->UnicodeToJisx0208(ch.row(), ch.cell())) != 0) { // JIS X 0208 state = JISX0208_1983; } else if ((j = conv->UnicodeToJisx0212(ch.row(), ch.cell())) != 0) { // JIS X 0212 state = JISX0212; } else { // Invalid state = Unknown; j = '?'; } if (state != prev) { if (state == Unknown) { result += Esc_Ascii; } else { result += Esc_SEQ[state - MinState]; } prev = state; } if (j < 0x0100) { result += j & 0xff; } else { result += (j >> 8) & 0xff; result += j & 0xff; } } if (prev != Ascii) { result += Esc_Ascii; } len_in_out = result.length(); return result; }
static bool to8bit(const QChar ch, QCString *rstr) { bool converted = FALSE; if( ch.isMark() ) return TRUE; // ignore marks for conversion if ( ch.row() ) { if ( ch.row() == 0x05 ) { if ( ch.cell() > 0x91 ) converted = TRUE; // 0x0591 - 0x05cf: Hebrew punctuation... dropped if ( ch.cell() >= 0xD0 ) *rstr += (char)unicode_to_heb_05[ch.cell()- 0xD0]; } else if ( ch.row() == 0x20 ) { if ( ch.cell() == 0x3E ) { *rstr += (char)0xAF; converted = TRUE; } else if ( ch.cell() == 0x17 ) { *rstr += (char)0xCF; converted = TRUE; } } else { converted = FALSE; } } else { if ( ch.cell() < 0x80 ) { *rstr += (char)ch.cell(); converted = TRUE; } else if( ch.cell() < 0xA0 ) { *rstr += (char)unicode_to_heb_00[ch.cell() - 0x80]; converted = TRUE; } } if(converted) return TRUE; // couldn't convert the char... lets try its decomposition QString d = ch.decomposition(); if(d.isNull()) return FALSE; int l = d.length(); for (int i=0; i<l; i++) { const QChar ch = d[i]; if(to8bit(ch, rstr)) converted = TRUE; } return converted; }
/*! \reimp */ QCString QTsciiCodec::fromUnicode(const QString& uc, int& lenInOut) const { int l = QMIN((int)uc.length(), lenInOut); int rlen = l+1; QCString rstr(rlen); uchar* cursor = (uchar*)rstr.data(); for (int i = 0; i < l; i++) { QChar ch = uc[i]; uchar j; if ( ch.row() == 0x00 && ch.cell() < 0x80 ) { // ASCII j = ch.cell(); } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), uc[i + 1].unicode(), uc[i + 2].unicode()))) { // We have to check the combined chars first! i += 2; } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), uc[i + 1].unicode(), 0))) { i++; } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), 0, 0))) { } else { // Error j = '?'; // unknown char } *cursor++ = j; } lenInOut = cursor - (uchar*)rstr.data(); *cursor = 0; return rstr; }
static bool matchcharclass( uint *rxd, QChar c ) { uint *d = rxd; uint clcode = *d & MCD; bool neg = clcode == CCN; if ( clcode != CCL && clcode != CCN) qWarning("QRegExp: Internal error, please report to [email protected]"); uint numFields = *d & MVL; uint cval = (((uint)(c.row())) << 8) | ((uint)c.cell()); bool found = FALSE; for ( int i = 0; i < (int)numFields; i++ ) { d++; if ( *d == PWS && c.isSpace() ) { found = TRUE; break; } if ( *d == PDG && c.isDigit() ) { found = TRUE; break; } else { uint from = ( *d & MCD ) >> 16; uint to = *d & MVL; if ( (cval >= from) && (cval <= to) ) { found = TRUE; break; } } } return neg ? !found : found; }
void encodeFileName(QString & szPath) { QString szSrc(szPath); szPath = ""; for(int i = 0; i < szSrc.length(); i++) { QChar cur = szSrc[i]; if( ! (cur.isLetter() || cur.isDigit() || cur==' ' || cur=='_' || cur=='.' || cur=='#' || cur=='%') ) { if(cur.row()!=0) { szPath += '%'; szPath += cHexChars[cur.row() >> 4]; szPath += cHexChars[cur.row() & 15]; } szPath += '%'; szPath += cHexChars[cur.cell() >> 4]; szPath += cHexChars[cur.cell() & 15]; } else if (cur=='%')
/*! \reimp */ QCString QSjisCodec::fromUnicode(const QString& uc, int& len_in_out) const { int l = QMIN((int)uc.length(),len_in_out); int rlen = l*2+1; QCString rstr(rlen); uchar* cursor = (uchar*)rstr.data(); for (int i=0; i<l; i++) { QChar ch = uc[i]; uint j; if ( ch.row() == 0x00 && ch.cell() < 0x80 ) { // ASCII *cursor++ = ch.cell(); } else if ((j = conv->UnicodeToJisx0201(ch.row(), ch.cell())) != 0) { // JIS X 0201 Latin or JIS X 0201 Kana *cursor++ = j; } else if ((j = conv->UnicodeToSjis(ch.row(), ch.cell())) != 0) { // JIS X 0208 *cursor++ = (j >> 8); *cursor++ = (j & 0xff); } else if ((j = conv->UnicodeToJisx0212(ch.row(), ch.cell())) != 0) {
QCString QKoi8Codec::fromUnicode(const QString& uc, int& len_in_out) const { int l = QMIN((int)uc.length(),len_in_out); int rlen = l+1; QCString rstr(rlen); uchar* cursor = (uchar*)rstr.data(); for (int i=0; i<l; i++) { const QChar ch = uc[i]; if ( ch.row() ) { if ( ch.row() == 0x25 ) { if ( ch.cell() < n_unicode_to_koi8_25 ) *cursor++ = unicode_to_koi8_25[ch.cell()]; else *cursor++ = unkn; } else if ( ch.row() == 0x04 ) { if ( ch.cell() < n_unicode_to_koi8_04 ) *cursor++ = unicode_to_koi8_04[ch.cell()]; else *cursor++ = unkn; } else if ( ch.row() == 0x22 ) { if ( ch.cell() == 0x1A ) *cursor++ = 0x96; else if ( ch.cell() == 0x48 ) *cursor++ = 0x97; else if ( ch.cell() == 0x64 ) *cursor++ = 0x98; else if ( ch.cell() == 0x65 ) *cursor++ = 0x99; else *cursor++ = unkn; } else if ( ch.row() == 0x23 ) { if ( ch.cell() == 0x20 ) *cursor++ = 0x93; else if ( ch.cell() == 0x21 ) *cursor++ = 0x9B; else *cursor++ = unkn; } else if ( ch.row() == 0x20 ) { if ( ch.cell() == 0x22 ) *cursor++ = 0x95; else *cursor++ = unkn; } else { *cursor++ = unkn; } } else { if ( ch.cell() < 128 ) { *cursor++ = ch.cell(); } else { *cursor++ = unkn; } } } *cursor = '\0'; // len_in_out = cursor - result; return rstr; }
/*! Converts the first \a len characters in \a uc from Unicode to this encoding, and returns the result in a byte array. The \a state contains some conversion flags, and is used by the codec to maintain state information. */ QByteArray QTsciiCodec::convertFromUnicode(const ushort *uc, int len, ConverterState *state) { char replacement = '?'; if (state) { if (state->flags & ConvertInvalidToNull) replacement = 0; } int invalid = 0; QByteArray rstr; rstr.resize(len); uchar* cursor = (uchar*)rstr.data(); for (int i = 0; i < len; i++) { QChar ch = uc[i]; uchar j; if (ch.row() == 0x00 && ch.cell() < 0x80) { // ASCII j = ch.cell(); } else if ((j = qt_UnicodeToTSCII(uc[i], uc[i + 1], uc[i + 2]))) { // We have to check the combined chars first! i += 2; } else if ((j = qt_UnicodeToTSCII(uc[i], uc[i + 1], 0))) { i++; } else if ((j = qt_UnicodeToTSCII(uc[i], 0, 0))) { } else { // Error j = replacement; ++invalid; } *cursor++ = j; } rstr.resize(cursor - (const uchar*)rstr.constData()); if (state) { state->invalidChars += invalid; } return rstr; }
static uint *dump( uint *p ) { while ( *p != END ) { if ( *p & CHR ) { QChar uc = (QChar)*p; char c = (char)uc; uint u = (((uint)(uc.row())) << 8) | ((uint)uc.cell()); qDebug( "\tCHR\tU%04x (%c)", u, (c ? c : ' ')); p++; } else if ( *p & MCC ) { uint clcode = *p & MCD; uint numFields = *p & MVL; if ( clcode == CCL ) qDebug( "\tCCL\t%i", numFields ); else if ( clcode == CCN ) qDebug( "\tCCN\t%i", numFields ); else qDebug("coding error!"); for ( int i = 0; i < (int)numFields; i++ ) { p++; if ( *p == PWS ) qDebug( "\t\tPWS" ); else if ( *p == PDG ) qDebug( "\t\tPDG" ); else { uint from = ( *p & MCD ) >> 16; uint to = *p & MVL; char fc = (char)QChar(from); char tc = (char)QChar(to); qDebug( "\t\tU%04x (%c) - U%04x (%c)", from, (fc ? fc : ' '), to, (tc ? tc : ' ') ); } } p++; } else switch ( *p++ ) {
// TODO allow editing not only at end void KRomajiEdit::keyPressEvent(QKeyEvent *e) { bool shift = e->state() & ShiftButton; QString ji = e->text(); if (shift && e->key() == Key_Space) // switch hiragana/english { if (kana == "hiragana") kana = "english"; else if (kana == "english") kana = "hiragana"; return; } if (kana == "english" || ji.isEmpty()) { KLineEdit::keyPressEvent(e); return; } if (shift) // shift for katakana { if (kana == "hiragana") kana = "katakana"; } //kdDebug() << "--------------------\n"; QString curEng; QString curKana; QString _text = text(); int i; unsigned int len = _text.length(); //kdDebug() << "length = " << len << endl; for (i = len - 1; i >= 0; i--) { QChar at = _text.at(i); //kdDebug() << "at = " << QString(at) << endl; if (at.row() == 0 && at != '.') { //kdDebug() << "prepending " << QString(at) << endl; curEng.prepend(at); } else break; } i++; //kdDebug() << "i is " << i << ", length is " << len << endl; curKana = _text.left(i); ji.prepend(curEng); ji = ji.lower(); //kdDebug() << "ji = " << ji << endl; QString replace; //kdDebug () << "kana is " << kana << endl; if (kana == "hiragana") replace = hiragana[ji]; else if (kana == "katakana") replace = katakana[ji]; //kdDebug() << "replace = " << replace << endl; if (!!replace) // if (replace has something in it) { //kdDebug() << "replace isn't empty\n"; setText(curKana + replace); if (kana == "katakana") kana = "hiragana"; return; } else { //kdDebug() << "replace is empty\n"; QString farRight(ji.right(ji.length() - 1)); //kdDebug() << "ji = " << ji << endl; //kdDebug() << "farRight = " << farRight << endl; // test if we need small tsu if (ji.at(0) == farRight.at(0)) // if two letters are same, and we can add a twoletter length kana { if (kana == "hiragana") setText(curKana + hiragana[ji.at(0) == 'n'? "n'" : "t-"] + farRight.at(0)); else setText(curKana + katakana[ji.at(0) == 'n'? "n'" : "t-"] + farRight.at(0)); if (kana == "katakana") kana = "hiragana"; return; } // test for hanging n QString newkana; if (kana == "hiragana") { newkana = hiragana[farRight]; //kdDebug() << "newkana = " << newkana << endl; if (ji.at(0) == 'n' && !!newkana) { //kdDebug() << "doing the n thing\n"; setText(curKana + hiragana["n'"] + newkana); if (kana == "katakana") kana = "hiragana"; return; } } else { newkana = katakana[farRight]; if (ji.at(0) == 'n' && !!newkana) { //kdDebug() << "doing the n thing - katakana\n"; setText(curKana + katakana["n'"] + newkana); if (kana == "katakana") kana = "hiragana"; return; } } } if ( e->key() == Key_Return || e->key() == Key_Enter ) // take care of pending n { if (kana == "hiragana") { if (_text[len-1] == 'n') setText(curKana + hiragana["n'"]); } else { if (_text[len-1] == 'N') setText(curKana + katakana["n'"]); } } KLineEdit::keyPressEvent(e); // don't think we'll get here :) }
bool QFontGb18030_0Codec::canEncode( QChar ch ) const { //qDebug("QFontGb18030_0Codec::canEncode( QChar ch = %02X%02X )", ch.row(), ch.cell()); return (ch.row () > 0 && !(ch.row () >= 0xd8 && ch.row () < 0xe0)); }