diff --git a/intl/uconv/public/uconvutil.h b/intl/uconv/public/uconvutil.h index abd7edee37f..6e7d11d2738 100644 --- a/intl/uconv/public/uconvutil.h +++ b/intl/uconv/public/uconvutil.h @@ -50,6 +50,7 @@ typedef enum { u2BytesGRPrefix8EA7Charset, u1ByteGLCharset, uComposedHangulCharset, + uComposedHangulGLCharset, uNumOfCharsetType } uScanClassID; diff --git a/intl/uconv/src/ugen.c b/intl/uconv/src/ugen.c index 3f2f480f1c0..cc54c8012ef 100644 --- a/intl/uconv/src/ugen.c +++ b/intl/uconv/src/ugen.c @@ -181,6 +181,26 @@ PRIVATE PRBool uCnGAlways8BytesComposedHangul( PRUint32* outlen ); +PRIVATE PRBool uCnGAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen +); + + +PRIVATE PRBool uComposedHangulCommon( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen, + PRUint8 mask +); + PRIVATE PRBool uGenAlways2Byte( PRUint16 in, unsigned char* out @@ -225,7 +245,8 @@ PRIVATE uGeneratorFunc m_generator[uNumOfCharsetType] = uCheckAndGen2ByteGRPrefix8EA6, uCheckAndGen2ByteGRPrefix8EA7, uCheckAndGenAlways1ByteShiftGL, - uCnGAlways8BytesComposedHangul + uCnGAlways8BytesComposedHangul, + uCnGAlways8BytesGLComposedHangul }; /*================================================================================= @@ -695,13 +716,14 @@ PRIVATE PRBool uCheckAndGenAlways1ByteShiftGL( /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCnGAlways8BytesComposedHangul( +PRIVATE PRBool uComposedHangulCommon( uShiftTable *shift, PRInt32* state, PRUint16 in, unsigned char* out, PRUint32 outbuflen, - PRUint32* outlen + PRUint32* outlen, + PRUint8 mask ) { if(outbuflen < 8) @@ -727,14 +749,36 @@ PRIVATE PRBool uCnGAlways8BytesComposedHangul( /* item 2 of Hangul Syllabel Decomposition w/ modification */ LIndex = SIndex / NCount; VIndex = (SIndex % NCount) / TCount; - TIndex = SIndex / TCount; + TIndex = SIndex % TCount; *outlen = 8; - out[0] = out[2] = out[4] = out[6] = 0xa4; - out[1] = 0xd4; - out[3] = lMap[LIndex]; - out[5] = VIndex + 0xbf; - out[7] = tMap[TIndex]; + out[0] = out[2] = out[4] = out[6] = (0xa4 & mask); + out[1] = 0xd4 & mask; + out[3] = lMap[LIndex] & mask; + out[5] = (VIndex + 0xbf) & mask; + out[7] = tMap[TIndex] & mask; return PR_TRUE; } } +PRIVATE PRBool uCnGAlways8BytesComposedHangul( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen +) +{ + return uComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0xff); +} +PRIVATE PRBool uCnGAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen +) +{ + return uComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0x7f); +} diff --git a/intl/uconv/src/uscan.c b/intl/uconv/src/uscan.c index 398b670d3e7..3c0fab743d0 100644 --- a/intl/uconv/src/uscan.c +++ b/intl/uconv/src/uscan.c @@ -174,6 +174,25 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( PRUint32* inscanlen ); +PRIVATE PRBool uCnSAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen +); + +PRIVATE PRBool uComposedHangulCommon( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen, + PRUint8 mask +); + PRIVATE PRBool uScanAlways2Byte( unsigned char* in, PRUint16* out @@ -655,24 +674,25 @@ PRIVATE PRBool uCheckAndScanAlways1ByteShiftGL( #define VCount 21 #define TCount 28 #define NCount (VCount * TCount) -PRIVATE PRBool uCnSAlways8BytesComposedHangul( +PRIVATE PRBool uComposedHanguleCommon( uShiftTable *shift, PRInt32* state, unsigned char *in, PRUint16 *out, PRUint32 inbuflen, - PRUint32* inscanlen + PRUint32* inscanlen, + PRUint8 mask ) { PRUint16 LIndex, VIndex, TIndex; /* no 8 bytes, not in a4 range, or the first 2 byte are not a4d4 */ - if((inbuflen < 8) || (0xa4 != in[0]) || (0xd4 != in[1]) || - (0xa4 != in[2] ) || (0xa4 != in[4]) || (0xa4 != in[6])) + if((inbuflen < 8) || ((mask & 0xa4) != in[0]) || ((mask& 0xd4) != in[1]) || + ((mask&0xa4) != in[2] ) || ((mask&0xa4) != in[4]) || ((mask&0xa4) != in[6])) return PR_FALSE; /* Compute LIndex */ - if((in[3] < 0xa1) && (in[3] > 0xbe)) { /* illegal leading consonant */ + if((in[3] < (mask&0xa1)) && (in[3] > (mask&0xbe))) { /* illegal leading consonant */ return PR_FALSE; } else { static PRUint8 lMap[] = { @@ -686,23 +706,23 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( 12, 13, 14, 15, 16, 17, 18 }; - LIndex = lMap[in[3] - 0xa1]; + LIndex = lMap[in[3] - (0xa1 & mask)]; if(0xff == (0xff & LIndex)) return PR_FALSE; } /* Compute VIndex */ - if((in[5] < 0xbf) && (in[5] > 0xd3)) { /* illegal medial vowel */ + if((in[5] < (mask&0xbf)) && (in[5] > (mask&0xd3))) { /* illegal medial vowel */ return PR_FALSE; } else { - VIndex = in[5] - 0xbf; + VIndex = in[5] - (mask&0xbf); } /* Compute TIndex */ - if(0xd4 == in[7]) + if((mask&0xd4) == in[7]) { TIndex = 0; - } else if((in[7] < 0xa1) && (in[7] > 0xbe)) {/* illegal trailling consonant */ + } else if((in[7] < (mask&0xa1)) && (in[7] > (mask&0xbe))) {/* illegal trailling consonant */ return PR_FALSE; } else { static PRUint8 tMap[] = { @@ -715,7 +735,7 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( /* B8 B9 BA BB BC BD BE */ 22,0xff, 23, 24, 25, 26, 27 }; - TIndex = tMap[in[3] - 0xa1]; + TIndex = tMap[in[3] - (mask&0xa1)]; if(0xff == (0xff & TIndex)) return PR_FALSE; } @@ -726,3 +746,31 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( return PR_TRUE; } +/*================================================================================= + +=================================================================================*/ +PRIVATE PRBool uCnSAlways8BytesComposedHangul( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen +) +{ + return uComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0xff); +} +/*================================================================================= + +=================================================================================*/ +PRIVATE PRBool uCnSAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen +) +{ + return uComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0x7f); +} diff --git a/intl/uconv/ucvko/nsUnicodeToKSC5601.cpp b/intl/uconv/ucvko/nsUnicodeToKSC5601.cpp index d4387bfa778..f0256555991 100644 --- a/intl/uconv/ucvko/nsUnicodeToKSC5601.cpp +++ b/intl/uconv/ucvko/nsUnicodeToKSC5601.cpp @@ -28,12 +28,27 @@ static PRUint16 g2BytesShiftTable[] = { ShiftCell(0, 0, 0, 0, 0, 0, 0, 0), }; +static PRUint16 gComposedHangulShiftTable[] = { + 0, uComposedHangulCharset, + ShiftCell(0, 0, 0, 0, 0, 0, 0, 0), +}; + +static PRUint16 *g_MappingTable[3] = { + g_ufKSC5601Mapping, + g_HangulNullMapping +}; + +static PRUint16 *g_ShiftTable[3] = { + g2BytesShiftTable, + gComposedHangulShiftTable +}; + //---------------------------------------------------------------------- // Class nsUnicodeToKSC5601 [implementation] nsUnicodeToKSC5601::nsUnicodeToKSC5601() -: nsTableEncoderSupport( (uShiftTable*) g2BytesShiftTable, - (uMappingTable*) g_ufKSC5601Mapping) +: nsMultiTableEncoderSupport(2, (uShiftTable**) g_ShiftTable, + (uMappingTable**) g_MappingTable) { } @@ -54,6 +69,6 @@ NS_IMETHODIMP nsUnicodeToKSC5601::GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength, PRInt32 * aDestLength) { - *aDestLength = aSrcLength * 2; - return NS_OK_UENC_EXACTLENGTH; + *aDestLength = aSrcLength * 8; + return NS_OK; } diff --git a/intl/uconv/ucvko/nsUnicodeToKSC5601.h b/intl/uconv/ucvko/nsUnicodeToKSC5601.h index cf8b7175357..5eb0ec0eea3 100644 --- a/intl/uconv/ucvko/nsUnicodeToKSC5601.h +++ b/intl/uconv/ucvko/nsUnicodeToKSC5601.h @@ -31,7 +31,7 @@ * @created 06/Apr/1999 * @author Catalin Rotaru [CATA] */ -class nsUnicodeToKSC5601 : public nsTableEncoderSupport +class nsUnicodeToKSC5601 : public nsMultiTableEncoderSupport { public: diff --git a/intl/uconv/util/ugen.c b/intl/uconv/util/ugen.c index 3f2f480f1c0..cc54c8012ef 100644 --- a/intl/uconv/util/ugen.c +++ b/intl/uconv/util/ugen.c @@ -181,6 +181,26 @@ PRIVATE PRBool uCnGAlways8BytesComposedHangul( PRUint32* outlen ); +PRIVATE PRBool uCnGAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen +); + + +PRIVATE PRBool uComposedHangulCommon( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen, + PRUint8 mask +); + PRIVATE PRBool uGenAlways2Byte( PRUint16 in, unsigned char* out @@ -225,7 +245,8 @@ PRIVATE uGeneratorFunc m_generator[uNumOfCharsetType] = uCheckAndGen2ByteGRPrefix8EA6, uCheckAndGen2ByteGRPrefix8EA7, uCheckAndGenAlways1ByteShiftGL, - uCnGAlways8BytesComposedHangul + uCnGAlways8BytesComposedHangul, + uCnGAlways8BytesGLComposedHangul }; /*================================================================================= @@ -695,13 +716,14 @@ PRIVATE PRBool uCheckAndGenAlways1ByteShiftGL( /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCnGAlways8BytesComposedHangul( +PRIVATE PRBool uComposedHangulCommon( uShiftTable *shift, PRInt32* state, PRUint16 in, unsigned char* out, PRUint32 outbuflen, - PRUint32* outlen + PRUint32* outlen, + PRUint8 mask ) { if(outbuflen < 8) @@ -727,14 +749,36 @@ PRIVATE PRBool uCnGAlways8BytesComposedHangul( /* item 2 of Hangul Syllabel Decomposition w/ modification */ LIndex = SIndex / NCount; VIndex = (SIndex % NCount) / TCount; - TIndex = SIndex / TCount; + TIndex = SIndex % TCount; *outlen = 8; - out[0] = out[2] = out[4] = out[6] = 0xa4; - out[1] = 0xd4; - out[3] = lMap[LIndex]; - out[5] = VIndex + 0xbf; - out[7] = tMap[TIndex]; + out[0] = out[2] = out[4] = out[6] = (0xa4 & mask); + out[1] = 0xd4 & mask; + out[3] = lMap[LIndex] & mask; + out[5] = (VIndex + 0xbf) & mask; + out[7] = tMap[TIndex] & mask; return PR_TRUE; } } +PRIVATE PRBool uCnGAlways8BytesComposedHangul( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen +) +{ + return uComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0xff); +} +PRIVATE PRBool uCnGAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen +) +{ + return uComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0x7f); +} diff --git a/intl/uconv/util/uscan.c b/intl/uconv/util/uscan.c index 398b670d3e7..3c0fab743d0 100644 --- a/intl/uconv/util/uscan.c +++ b/intl/uconv/util/uscan.c @@ -174,6 +174,25 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( PRUint32* inscanlen ); +PRIVATE PRBool uCnSAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen +); + +PRIVATE PRBool uComposedHangulCommon( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen, + PRUint8 mask +); + PRIVATE PRBool uScanAlways2Byte( unsigned char* in, PRUint16* out @@ -655,24 +674,25 @@ PRIVATE PRBool uCheckAndScanAlways1ByteShiftGL( #define VCount 21 #define TCount 28 #define NCount (VCount * TCount) -PRIVATE PRBool uCnSAlways8BytesComposedHangul( +PRIVATE PRBool uComposedHanguleCommon( uShiftTable *shift, PRInt32* state, unsigned char *in, PRUint16 *out, PRUint32 inbuflen, - PRUint32* inscanlen + PRUint32* inscanlen, + PRUint8 mask ) { PRUint16 LIndex, VIndex, TIndex; /* no 8 bytes, not in a4 range, or the first 2 byte are not a4d4 */ - if((inbuflen < 8) || (0xa4 != in[0]) || (0xd4 != in[1]) || - (0xa4 != in[2] ) || (0xa4 != in[4]) || (0xa4 != in[6])) + if((inbuflen < 8) || ((mask & 0xa4) != in[0]) || ((mask& 0xd4) != in[1]) || + ((mask&0xa4) != in[2] ) || ((mask&0xa4) != in[4]) || ((mask&0xa4) != in[6])) return PR_FALSE; /* Compute LIndex */ - if((in[3] < 0xa1) && (in[3] > 0xbe)) { /* illegal leading consonant */ + if((in[3] < (mask&0xa1)) && (in[3] > (mask&0xbe))) { /* illegal leading consonant */ return PR_FALSE; } else { static PRUint8 lMap[] = { @@ -686,23 +706,23 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( 12, 13, 14, 15, 16, 17, 18 }; - LIndex = lMap[in[3] - 0xa1]; + LIndex = lMap[in[3] - (0xa1 & mask)]; if(0xff == (0xff & LIndex)) return PR_FALSE; } /* Compute VIndex */ - if((in[5] < 0xbf) && (in[5] > 0xd3)) { /* illegal medial vowel */ + if((in[5] < (mask&0xbf)) && (in[5] > (mask&0xd3))) { /* illegal medial vowel */ return PR_FALSE; } else { - VIndex = in[5] - 0xbf; + VIndex = in[5] - (mask&0xbf); } /* Compute TIndex */ - if(0xd4 == in[7]) + if((mask&0xd4) == in[7]) { TIndex = 0; - } else if((in[7] < 0xa1) && (in[7] > 0xbe)) {/* illegal trailling consonant */ + } else if((in[7] < (mask&0xa1)) && (in[7] > (mask&0xbe))) {/* illegal trailling consonant */ return PR_FALSE; } else { static PRUint8 tMap[] = { @@ -715,7 +735,7 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( /* B8 B9 BA BB BC BD BE */ 22,0xff, 23, 24, 25, 26, 27 }; - TIndex = tMap[in[3] - 0xa1]; + TIndex = tMap[in[3] - (mask&0xa1)]; if(0xff == (0xff & TIndex)) return PR_FALSE; } @@ -726,3 +746,31 @@ PRIVATE PRBool uCnSAlways8BytesComposedHangul( return PR_TRUE; } +/*================================================================================= + +=================================================================================*/ +PRIVATE PRBool uCnSAlways8BytesComposedHangul( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen +) +{ + return uComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0xff); +} +/*================================================================================= + +=================================================================================*/ +PRIVATE PRBool uCnSAlways8BytesGLComposedHangul( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen +) +{ + return uComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0x7f); +}