Qt 4.8
Classes | Macros | Functions | Variables
qeuckrcodec.cpp File Reference
#include "qeuckrcodec.h"
#include "cp949codetbl.h"

Go to the source code of this file.

Classes

struct  map
 

Macros

#define IsCP949Char(c)   (((c) >= 0x81) && ((c) <= 0xa0))
 
#define IsEucChar(c)   (((c) >= 0xa1) && ((c) <= 0xfe))
 
#define QValidChar(u)   ((u) ? QChar((ushort)(u)) : QChar(QChar::ReplacementCharacter))
 

Functions

static unsigned short ksc2unicode (unsigned short code)
 
unsigned int qt_Ksc5601ToUnicode (unsigned int code)
 
unsigned int qt_UnicodeToKsc5601 (unsigned int unicode)
 
static unsigned short unicode2ksc (unsigned short code)
 

Variables

static const unsigned short ksc5601_hangul_to_unicode [2350]
 
static const unsigned short ksc5601_hanja_to_unicode [4888]
 
static const unsigned short ksc5601_symbol_to_unicode [1115]
 
static const struct map unicode_to_ksc5601_hanja [4888]
 
static const struct map unicode_to_ksc5601_symbol [986]
 

Macro Definition Documentation

◆ IsCP949Char

#define IsCP949Char (   c)    (((c) >= 0x81) && ((c) <= 0xa0))

Definition at line 82 of file qeuckrcodec.cpp.

Referenced by QCP949Codec::convertToUnicode().

◆ IsEucChar

#define IsEucChar (   c)    (((c) >= 0xa1) && ((c) <= 0xfe))

Definition at line 81 of file qeuckrcodec.cpp.

Referenced by QEucKrCodec::convertToUnicode(), and QCP949Codec::convertToUnicode().

◆ QValidChar

#define QValidChar (   u)    ((u) ? QChar((ushort)(u)) : QChar(QChar::ReplacementCharacter))

Definition at line 83 of file qeuckrcodec.cpp.

Referenced by QEucKrCodec::convertToUnicode(), and QCP949Codec::convertToUnicode().

Function Documentation

◆ ksc2unicode()

static unsigned short ksc2unicode ( unsigned short  code)
static

Definition at line 3303 of file qeuckrcodec.cpp.

Referenced by QFontKsc5601Codec::convertFromUnicode(), and qt_Ksc5601ToUnicode().

3304 {
3305  int ch1 = code >> 8;
3306  int ch2 = code & 0x00ff;
3307  int idx;
3308 
3309  if (ch1 < 0x80 || (ch1 - 0x80) <= 0x20 || (ch1 - 0x80) >= 0x7e
3310  || (ch1 - 0x80) == 0x49)
3311  return 0;
3312 
3313  if (ch2 < 0x80 || (ch2 - 0x80) <= 0x20 || (ch2 - 0x80) >= 0x7f)
3314  return 0;
3315 
3316  idx = (ch1 - 0x80 - 0x21) * 94 + (ch2 - 0x80 - 0x21);
3317 
3318  /* Hangul : row 16 - row 40 : 1410 = 15 * 94 ,
3319  3760 = 40 * 94 */
3320  if (idx >= 1410 && idx < 1410 + 2350)
3321  return ksc5601_hangul_to_unicode[idx - 1410];
3322 
3323  else if (idx >= 3854)
3324  /* Hanja : row 42 - row 93 : 3854 = 94 * (42-1) */
3325  return ksc5601_hanja_to_unicode[idx - 3854];
3326 
3327  else if(idx <= 1114)
3328  return ksc5601_symbol_to_unicode[idx];
3329 
3330  return 0;
3331 }
static const unsigned short ksc5601_symbol_to_unicode[1115]
static const unsigned short ksc5601_hanja_to_unicode[4888]
static const unsigned short ksc5601_hangul_to_unicode[2350]

◆ qt_Ksc5601ToUnicode()

unsigned int qt_Ksc5601ToUnicode ( unsigned int  code)

Definition at line 249 of file qeuckrcodec.cpp.

Referenced by QEucKrCodec::convertToUnicode(), and QCP949Codec::convertToUnicode().

250 {
251 #if 0
252  printf("qt_Ksc5601ToUnicode : code = %x, unicode = %x\n",
253  code, ksc2unicode((unsigned short)code));
254 #endif
255  return ksc2unicode((unsigned short)code);
256 }
static unsigned short ksc2unicode(unsigned short code)

◆ qt_UnicodeToKsc5601()

unsigned int qt_UnicodeToKsc5601 ( unsigned int  unicode)

Definition at line 258 of file qeuckrcodec.cpp.

Referenced by QEucKrCodec::convertFromUnicode(), QCP949Codec::convertFromUnicode(), and QFontKsc5601Codec::convertFromUnicode().

259 {
260 #if 0
261  printf("qt_UnicodeToKsc5601 : unicode = %x, %x\n",
262  unicode, unicode2ksc((unsigned short)unicode));
263 #endif
264  return unicode2ksc((unsigned short)unicode);
265 }
static unsigned short unicode2ksc(unsigned short code)

◆ unicode2ksc()

static unsigned short unicode2ksc ( unsigned short  code)
static

Definition at line 3333 of file qeuckrcodec.cpp.

Referenced by QFontKsc5601Codec::convertFromUnicode(), and qt_UnicodeToKsc5601().

3334 {
3335  int lo, hi, mid, c2;
3336  unsigned char s[2];
3337 
3338  lo = mid = c2 = 0;
3339 
3340  if (unicode >= 0xac00 && unicode <= 0xd7a3) {
3341  // Hangul
3342  hi = 2349;
3343 
3344  while (lo <= hi) { // binary search
3345  mid = (lo + hi) / 2;
3346  c2 = ksc5601_hangul_to_unicode[mid];
3347  if(unicode < c2)
3348  hi = mid - 1;
3349  else if(unicode > c2)
3350  lo = mid + 1;
3351  else { // unicode == c2
3352  s[0] = (mid / 94) + 0x30;
3353  s[1] = (mid % 94) + 0x21;
3354 
3355  return ((s[0] << 8) | s[1]);
3356  }
3357  }
3358  } else if ((unicode >= 0x4e00 && unicode <= 0x9fff)
3359  || (unicode >= 0xf900 && unicode <= 0xfa0b)) {
3360  // Hanja
3361  hi = 4887;
3362 
3363  while (lo <= hi) { // binary search
3364  mid = (lo + hi) / 2;
3366  if(unicode < c2)
3367  hi = mid - 1;
3368  else if(unicode > c2)
3369  lo = mid + 1;
3370  else { // unicode == c2
3371  return unicode_to_ksc5601_hanja[mid].kscode;
3372  }
3373  }
3374  } else {
3375  // Symbol
3376  hi = 985;
3377 
3378  while (lo <= hi) { // binary search
3379  mid = (lo + hi) / 2;
3381  if(unicode < c2)
3382  hi = mid - 1;
3383  else if(unicode > c2)
3384  lo = mid + 1;
3385  else { // unicode == c2
3386  return unicode_to_ksc5601_symbol[mid].kscode;
3387  }
3388  }
3389  }
3390  return 0;
3391 }
unsigned short unicode
static const struct map unicode_to_ksc5601_hanja[4888]
unsigned short kscode
static const unsigned short ksc5601_hangul_to_unicode[2350]
static const struct map unicode_to_ksc5601_symbol[986]

Variable Documentation

◆ ksc5601_hangul_to_unicode

const unsigned short ksc5601_hangul_to_unicode[2350]
static

Definition at line 268 of file qeuckrcodec.cpp.

Referenced by ksc2unicode(), and unicode2ksc().

◆ ksc5601_hanja_to_unicode

const unsigned short ksc5601_hanja_to_unicode[4888]
static

Definition at line 1052 of file qeuckrcodec.cpp.

Referenced by ksc2unicode().

◆ ksc5601_symbol_to_unicode

const unsigned short ksc5601_symbol_to_unicode[1115]
static

Definition at line 567 of file qeuckrcodec.cpp.

Referenced by ksc2unicode().

◆ unicode_to_ksc5601_hanja

const struct map unicode_to_ksc5601_hanja[4888]
static

Definition at line 1668 of file qeuckrcodec.cpp.

◆ unicode_to_ksc5601_symbol

const struct map unicode_to_ksc5601_symbol[986]
static

Definition at line 718 of file qeuckrcodec.cpp.