diff --git a/intl/uconv/util/ugen.c b/intl/uconv/util/ugen.c index 1b304b69944a..43bf94ff48be 100644 --- a/intl/uconv/util/ugen.c +++ b/intl/uconv/util/ugen.c @@ -1,24 +1,24 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ +* +* The contents of this file are subject to the Netscape Public +* License Version 1.1 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.mozilla.org/NPL/ +* +* Software distributed under the License is distributed on an "AS +* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is mozilla.org code. +* +* The Initial Developer of the Original Code is Netscape +* Communications Corporation. Portions created by Netscape are +* Copyright (C) 1998 Netscape Communications Corporation. All +* Rights Reserved. +* +* Contributor(s): +*/ #include "unicpriv.h" /*================================================================================= @@ -29,259 +29,259 @@ typedef PRBool (*uSubGeneratorFunc) (PRUint16 in, unsigned char* out); =================================================================================*/ typedef PRBool (*uGeneratorFunc) ( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); -MODULE_PRIVATE PRBool uGenerate( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); +MODULE_PRIVATE PRBool uGenerate( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); -#define uSubGennerator(sub,in,out) (* m_subgenerator[sub])((in),(out)) +#define uSubGennerator(sub,in,out) (* m_subgenerator[sub])((in),(out)) PRIVATE PRBool uCheckAndGenAlways1Byte( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenAlways2Byte( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenAlways2ByteShiftGR( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenByTable( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen2ByteGRPrefix8F( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenAlways2ByteSwap( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenAlways4Byte( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenAlways4ByteSwap( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA3( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA4( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA5( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA6( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA7( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenAlways1ByteShiftGL( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCnGAlways8BytesComposedHangul( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCnGAlways8BytesGLComposedHangul( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenJohabHangul( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGenJohabSymbol( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uCheckAndGen4BytesGB18030( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ); PRIVATE PRBool uGenComposedHangulCommon( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen, - PRUint8 mask -); + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen, + PRUint8 mask + ); PRIVATE PRBool uGenAlways2Byte( - PRUint16 in, - unsigned char* out -); + PRUint16 in, + unsigned char* out + ); PRIVATE PRBool uGenAlways2ByteShiftGR( - PRUint16 in, - unsigned char* out -); + PRUint16 in, + unsigned char* out + ); PRIVATE PRBool uGenAlways1Byte( - PRUint16 in, - unsigned char* out -); + PRUint16 in, + unsigned char* out + ); PRIVATE PRBool uGenAlways1BytePrefix8E( - PRUint16 in, - unsigned char* out -); + PRUint16 in, + unsigned char* out + ); PRIVATE PRBool uGenAlways2ByteUTF8( - PRUint16 in, - unsigned char* out -); + PRUint16 in, + unsigned char* out + ); PRIVATE PRBool uGenAlways3ByteUTF8( - PRUint16 in, - unsigned char* out -); -/*================================================================================= - + PRUint16 in, + unsigned char* out + ); + /*================================================================================= + =================================================================================*/ PRIVATE uGeneratorFunc m_generator[uNumOfCharsetType] = { - uCheckAndGenAlways1Byte, - uCheckAndGenAlways2Byte, - uCheckAndGenByTable, - uCheckAndGenAlways2ByteShiftGR, - uCheckAndGen2ByteGRPrefix8F, - uCheckAndGen2ByteGRPrefix8EA2, - uCheckAndGenAlways2ByteSwap, - uCheckAndGenAlways4Byte, - uCheckAndGenAlways4ByteSwap, - uCheckAndGen2ByteGRPrefix8EA3, - uCheckAndGen2ByteGRPrefix8EA4, - uCheckAndGen2ByteGRPrefix8EA5, - uCheckAndGen2ByteGRPrefix8EA6, - uCheckAndGen2ByteGRPrefix8EA7, - uCheckAndGenAlways1ByteShiftGL, - uCnGAlways8BytesComposedHangul, - uCnGAlways8BytesGLComposedHangul, - uCheckAndGenJohabHangul, - uCheckAndGenJohabSymbol, - uCheckAndGen4BytesGB18030 + uCheckAndGenAlways1Byte, + uCheckAndGenAlways2Byte, + uCheckAndGenByTable, + uCheckAndGenAlways2ByteShiftGR, + uCheckAndGen2ByteGRPrefix8F, + uCheckAndGen2ByteGRPrefix8EA2, + uCheckAndGenAlways2ByteSwap, + uCheckAndGenAlways4Byte, + uCheckAndGenAlways4ByteSwap, + uCheckAndGen2ByteGRPrefix8EA3, + uCheckAndGen2ByteGRPrefix8EA4, + uCheckAndGen2ByteGRPrefix8EA5, + uCheckAndGen2ByteGRPrefix8EA6, + uCheckAndGen2ByteGRPrefix8EA7, + uCheckAndGenAlways1ByteShiftGL, + uCnGAlways8BytesComposedHangul, + uCnGAlways8BytesGLComposedHangul, + uCheckAndGenJohabHangul, + uCheckAndGenJohabSymbol, + uCheckAndGen4BytesGB18030 }; /*================================================================================= @@ -290,123 +290,123 @@ PRIVATE uGeneratorFunc m_generator[uNumOfCharsetType] = PRIVATE uSubGeneratorFunc m_subgenerator[uNumOfCharType] = { - uGenAlways1Byte, - uGenAlways2Byte, - uGenAlways2ByteShiftGR, - uGenAlways1BytePrefix8E, - uGenAlways2ByteUTF8, - uGenAlways3ByteUTF8 - + uGenAlways1Byte, + uGenAlways2Byte, + uGenAlways2ByteShiftGR, + uGenAlways1BytePrefix8E, + uGenAlways2ByteUTF8, + uGenAlways3ByteUTF8 + }; /*================================================================================= =================================================================================*/ -MODULE_PRIVATE PRBool uGenerate( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +MODULE_PRIVATE PRBool uGenerate( + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - return (* m_generator[shift->classID]) (shift,state,in,out,outbuflen,outlen); + return (* m_generator[shift->classID]) (shift,state,in,out,outbuflen,outlen); } /*================================================================================= =================================================================================*/ PRIVATE PRBool uGenAlways1Byte( - PRUint16 in, - unsigned char* out -) + PRUint16 in, + unsigned char* out + ) { - out[0] = (unsigned char)in; - return PR_TRUE; + out[0] = (unsigned char)in; + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uGenAlways2Byte( - PRUint16 in, - unsigned char* out -) + PRUint16 in, + unsigned char* out + ) { - out[0] = (unsigned char)((in >> 8) & 0xff); - out[1] = (unsigned char)(in & 0xff); - return PR_TRUE; + out[0] = (unsigned char)((in >> 8) & 0xff); + out[1] = (unsigned char)(in & 0xff); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uGenAlways2ByteShiftGR( - PRUint16 in, - unsigned char* out -) + PRUint16 in, + unsigned char* out + ) { - out[0] = (unsigned char)(((in >> 8) & 0xff) | 0x80); - out[1] = (unsigned char)((in & 0xff) | 0x80); - return PR_TRUE; + out[0] = (unsigned char)(((in >> 8) & 0xff) | 0x80); + out[1] = (unsigned char)((in & 0xff) | 0x80); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uGenAlways1BytePrefix8E( - PRUint16 in, - unsigned char* out -) + PRUint16 in, + unsigned char* out + ) { - out[0] = 0x8E; - out[1] = (unsigned char)(in & 0xff); - return PR_TRUE; + out[0] = 0x8E; + out[1] = (unsigned char)(in & 0xff); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uGenAlways2ByteUTF8( - PRUint16 in, - unsigned char* out -) + PRUint16 in, + unsigned char* out + ) { - out[0] = (unsigned char)(0xC0 | (( in >> 6 ) & 0x1F)); - out[1] = (unsigned char)(0x80 | (( in ) & 0x3F)); - return PR_TRUE; + out[0] = (unsigned char)(0xC0 | (( in >> 6 ) & 0x1F)); + out[1] = (unsigned char)(0x80 | (( in ) & 0x3F)); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uGenAlways3ByteUTF8( - PRUint16 in, - unsigned char* out -) + PRUint16 in, + unsigned char* out + ) { - out[0] = (unsigned char)(0xE0 | (( in >> 12 ) & 0x0F)); - out[1] = (unsigned char)(0x80 | (( in >> 6 ) & 0x3F)); - out[2] = (unsigned char)(0x80 | (( in ) & 0x3F)); - return PR_TRUE; + out[0] = (unsigned char)(0xE0 | (( in >> 12 ) & 0x0F)); + out[1] = (unsigned char)(0x80 | (( in >> 6 ) & 0x3F)); + out[2] = (unsigned char)(0x80 | (( in ) & 0x3F)); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndGenAlways1Byte( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - /* Don't check inlen. The caller should ensure it is larger than 0 */ + /* Don't check inlen. The caller should ensure it is larger than 0 */ /* Oops, I don't agree. Code changed to check every time. [CATA] */ - if(outbuflen < 1) - return PR_FALSE; - else - { + if(outbuflen < 1) + return PR_FALSE; + else + { *outlen = 1; - out[0] = in & 0xff; - return PR_TRUE; + out[0] = in & 0xff; + return PR_TRUE; } } @@ -414,126 +414,126 @@ PRIVATE PRBool uCheckAndGenAlways1Byte( =================================================================================*/ PRIVATE PRBool uCheckAndGenAlways2Byte( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 2) - return PR_FALSE; - else - { - *outlen = 2; - out[0] = ((in >> 8 ) & 0xff); - out[1] = in & 0xff; - return PR_TRUE; - } + if(outbuflen < 2) + return PR_FALSE; + else + { + *outlen = 2; + out[0] = ((in >> 8 ) & 0xff); + out[1] = in & 0xff; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndGenAlways2ByteShiftGR( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 2) - return PR_FALSE; - else - { - *outlen = 2; - out[0] = ((in >> 8 ) & 0xff) | 0x80; - out[1] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 2) + return PR_FALSE; + else + { + *outlen = 2; + out[0] = ((in >> 8 ) & 0xff) | 0x80; + out[1] = (in & 0xff) | 0x80; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndGenByTable( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - PRInt16 i; - uShiftCell* cell = &(shift->shiftcell[0]); - PRInt16 itemnum = shift->numOfItem; - unsigned char inH, inL; - inH = (in >> 8) & 0xff; - inL = (in & 0xff ); - for(i=0;i= cell[i].shiftout.MinLB) && - ( inL <= cell[i].shiftout.MaxLB) && - ( inH >= cell[i].shiftout.MinHB) && - ( inH <= cell[i].shiftout.MaxHB) ) - { - if(outbuflen < cell[i].reserveLen) - return PR_FALSE; - else - { - *outlen = cell[i].reserveLen; - return (uSubGennerator(cell[i].classID,in,out)); - } - } - } - return PR_FALSE; + PRInt16 i; + uShiftCell* cell = &(shift->shiftcell[0]); + PRInt16 itemnum = shift->numOfItem; + unsigned char inH, inL; + inH = (in >> 8) & 0xff; + inL = (in & 0xff ); + for(i=0;i= cell[i].shiftout.MinLB) && + ( inL <= cell[i].shiftout.MaxLB) && + ( inH >= cell[i].shiftout.MinHB) && + ( inH <= cell[i].shiftout.MaxHB) ) + { + if(outbuflen < cell[i].reserveLen) + return PR_FALSE; + else + { + *outlen = cell[i].reserveLen; + return (uSubGennerator(cell[i].classID,in,out)); + } + } + } + return PR_FALSE; } /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCheckAndGen2ByteGRPrefix8F( uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +PRIVATE PRBool uCheckAndGen2ByteGRPrefix8F( uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 3) - return PR_FALSE; - else - { - *outlen = 3; - out[0] = 0x8F; - out[1] = ((in >> 8 ) & 0xff) | 0x80; - out[2] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 3) + return PR_FALSE; + else + { + *outlen = 3; + out[0] = 0x8F; + out[1] = ((in >> 8 ) & 0xff) | 0x80; + out[2] = (in & 0xff) | 0x80; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2( uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2( uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = 0x8E; - out[1] = 0xA2; - out[2] = ((in >> 8 ) & 0xff) | 0x80; - out[3] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = 0x8E; + out[1] = 0xA2; + out[2] = ((in >> 8 ) & 0xff) | 0x80; + out[3] = (in & 0xff) | 0x80; + return PR_TRUE; + } } @@ -541,206 +541,206 @@ PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2( uShiftTable *shift, =================================================================================*/ PRIVATE PRBool uCheckAndGenAlways2ByteSwap( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 2) - return PR_FALSE; - else - { - *outlen = 2; - out[0] = in & 0xff; - out[1] = ((in >> 8 ) & 0xff); - return PR_TRUE; - } + if(outbuflen < 2) + return PR_FALSE; + else + { + *outlen = 2; + out[0] = in & 0xff; + out[1] = ((in >> 8 ) & 0xff); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndGenAlways4Byte( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = out[1] = 0x00; - out[2] = ((in >> 8 ) & 0xff); - out[3] = in & 0xff; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = out[1] = 0x00; + out[2] = ((in >> 8 ) & 0xff); + out[3] = in & 0xff; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndGenAlways4ByteSwap( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = ((in >> 8 ) & 0xff); - out[1] = in & 0xff; - out[2] = out[3] = 0x00; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = ((in >> 8 ) & 0xff); + out[1] = in & 0xff; + out[2] = out[3] = 0x00; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA3( uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA3( uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = 0x8E; - out[1] = 0xA3; - out[2] = ((in >> 8 ) & 0xff) | 0x80; - out[3] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = 0x8E; + out[1] = 0xA3; + out[2] = ((in >> 8 ) & 0xff) | 0x80; + out[3] = (in & 0xff) | 0x80; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA4( uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA4( uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = 0x8E; - out[1] = 0xA4; - out[2] = ((in >> 8 ) & 0xff) | 0x80; - out[3] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = 0x8E; + out[1] = 0xA4; + out[2] = ((in >> 8 ) & 0xff) | 0x80; + out[3] = (in & 0xff) | 0x80; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA5( uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA5( uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = 0x8E; - out[1] = 0xA5; - out[2] = ((in >> 8 ) & 0xff) | 0x80; - out[3] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = 0x8E; + out[1] = 0xA5; + out[2] = ((in >> 8 ) & 0xff) | 0x80; + out[3] = (in & 0xff) | 0x80; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA6( uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA6( uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = 0x8E; - out[1] = 0xA6; - out[2] = ((in >> 8 ) & 0xff) | 0x80; - out[3] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = 0x8E; + out[1] = 0xA6; + out[2] = ((in >> 8 ) & 0xff) | 0x80; + out[3] = (in & 0xff) | 0x80; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ -PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA7( uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) +PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA7( uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - else - { - *outlen = 4; - out[0] = 0x8E; - out[1] = 0xA7; - out[2] = ((in >> 8 ) & 0xff) | 0x80; - out[3] = (in & 0xff) | 0x80; - return PR_TRUE; - } + if(outbuflen < 4) + return PR_FALSE; + else + { + *outlen = 4; + out[0] = 0x8E; + out[1] = 0xA7; + out[2] = ((in >> 8 ) & 0xff) | 0x80; + out[3] = (in & 0xff) | 0x80; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndGenAlways1ByteShiftGL( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - /* Don't check inlen. The caller should ensure it is larger than 0 */ + /* Don't check inlen. The caller should ensure it is larger than 0 */ /* Oops, I don't agree. Code changed to check every time. [CATA] */ - if(outbuflen < 1) - return PR_FALSE; - else - { + if(outbuflen < 1) + return PR_FALSE; + else + { *outlen = 1; - out[0] = in & 0x7f; - return PR_TRUE; + out[0] = in & 0x7f; + return PR_TRUE; } } #define SBase 0xAC00 @@ -752,203 +752,204 @@ PRIVATE PRBool uCheckAndGenAlways1ByteShiftGL( =================================================================================*/ PRIVATE PRBool uGenComposedHangulCommon( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen, - PRUint8 mask -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen, + PRUint8 mask + ) { - if(outbuflen < 8) - return PR_FALSE; - else - { - static PRUint8 lMap[LCount] = { - 0xa1, 0xa2, 0xa4, 0xa7, 0xa8, 0xa9, 0xb1, 0xb2, 0xb3, 0xb5, - 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe - }; - - static PRUint8 tMap[TCount] = { - 0xd4, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa9, 0xaa, - 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb4, 0xb5, - 0xb6, 0xb7, 0xb8, 0xba, 0xbb, 0xbc, 0xbd, 0xbe - }; - PRUint16 SIndex, LIndex, VIndex, TIndex; - /* the following line are copy from Unicode 2.0 page 3-13 */ - /* item 1 of Hangul Syllabel Decomposition */ - SIndex = in - SBase; - - /* the following lines are copy from Unicode 2.0 page 3-14 */ - /* item 2 of Hangul Syllabel Decomposition w/ modification */ - LIndex = SIndex / NCount; - VIndex = (SIndex % NCount) / TCount; - TIndex = SIndex % TCount; - - *outlen = 8; - 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; + if(outbuflen < 8) + return PR_FALSE; + else + { + static PRUint8 lMap[LCount] = { + 0xa1, 0xa2, 0xa4, 0xa7, 0xa8, 0xa9, 0xb1, 0xb2, 0xb3, 0xb5, + 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe + }; + + static PRUint8 tMap[TCount] = { + 0xd4, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa9, 0xaa, + 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb4, 0xb5, + 0xb6, 0xb7, 0xb8, 0xba, 0xbb, 0xbc, 0xbd, 0xbe + }; + PRUint16 SIndex, LIndex, VIndex, TIndex; + /* the following line are copy from Unicode 2.0 page 3-13 */ + /* item 1 of Hangul Syllabel Decomposition */ + SIndex = in - SBase; + + /* the following lines are copy from Unicode 2.0 page 3-14 */ + /* item 2 of Hangul Syllabel Decomposition w/ modification */ + LIndex = SIndex / NCount; + VIndex = (SIndex % NCount) / TCount; + TIndex = SIndex % TCount; + + *outlen = 8; + 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 -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - return uGenComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0xff); + return uGenComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0xff); } PRIVATE PRBool uCnGAlways8BytesGLComposedHangul( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - return uGenComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0x7f); + return uGenComposedHangulCommon(shift,state,in,out,outbuflen,outlen,0x7f); } PRIVATE PRBool uCheckAndGenJohabHangul( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 2) - return PR_FALSE; - else - { - /* - See Table 4-45 (page 183) of CJKV Information Processing - for detail explaination of the following table - */ - /* - static PRUint8 lMap[LCount] = { - 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 - }; - Therefore lMap[i] == i+2; - */ - - static PRUint8 vMap[VCount] = { - /* no 0,1,2 */ - 3,4,5,6,7, /* no 8,9 */ - 10,11,12,13,14,15, /* no 16,17 */ - 18,19,20,21,22,23, /* no 24,25 */ - 26,27,28,29 - }; - static PRUint8 tMap[TCount] = { - 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, /* no 18 */ - 19,20,21,22,23,24,25,26,27,28,29 - }; - PRUint16 SIndex, LIndex, VIndex, TIndex, ch; - /* the following line are copy from Unicode 2.0 page 3-13 */ - /* item 1 of Hangul Syllabel Decomposition */ - SIndex = in - SBase; - - /* the following lines are copy from Unicode 2.0 page 3-14 */ - /* item 2 of Hangul Syllabel Decomposition w/ modification */ - LIndex = SIndex / NCount; - VIndex = (SIndex % NCount) / TCount; - TIndex = SIndex % TCount; - - *outlen = 2; - ch = 0x8000 | - ((LIndex+2)<<10) | - (vMap[VIndex]<<5)| - tMap[TIndex]; - out[0] = (ch >> 8); - out[1] = ch & 0x00FF; + if(outbuflen < 2) + return PR_FALSE; + else + { + /* + See Table 4-45 (page 183) of CJKV Information Processing + for detail explaination of the following table + */ + /* + static PRUint8 lMap[LCount] = { + 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 + }; + Therefore lMap[i] == i+2; + */ + + static PRUint8 vMap[VCount] = { + /* no 0,1,2 */ + 3,4,5,6,7, /* no 8,9 */ + 10,11,12,13,14,15, /* no 16,17 */ + 18,19,20,21,22,23, /* no 24,25 */ + 26,27,28,29 + }; + static PRUint8 tMap[TCount] = { + 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, /* no 18 */ + 19,20,21,22,23,24,25,26,27,28,29 + }; + PRUint16 SIndex, LIndex, VIndex, TIndex, ch; + /* the following line are copy from Unicode 2.0 page 3-13 */ + /* item 1 of Hangul Syllabel Decomposition */ + SIndex = in - SBase; + + /* the following lines are copy from Unicode 2.0 page 3-14 */ + /* item 2 of Hangul Syllabel Decomposition w/ modification */ + LIndex = SIndex / NCount; + VIndex = (SIndex % NCount) / TCount; + TIndex = SIndex % TCount; + + *outlen = 2; + ch = 0x8000 | + ((LIndex+2)<<10) | + (vMap[VIndex]<<5)| + tMap[TIndex]; + out[0] = (ch >> 8); + out[1] = ch & 0x00FF; #if 0 -printf("Johab Hangul %x %x in=%x L=%d V=%d T=%d\n", out[0], out[1], in, LIndex, VIndex, TIndex); + printf("Johab Hangul %x %x in=%x L=%d V=%d T=%d\n", out[0], out[1], in, LIndex, VIndex, TIndex); #endif - return PR_TRUE; + return PR_TRUE; } } PRIVATE PRBool uCheckAndGenJohabSymbol( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 2) - return PR_FALSE; - else - { - /* The following code are based on the Perl code listed under - * "ISO-2022-KR or EUC-KR to Johab Conversion" (page 1013) - * in the book "CJKV Information Processing" by - * Ken Lunde - * - * sub convert2johab($) { # Convert ISO-2022-KR or EUC-KR to Johab - * my @euc = unpack("C*", $_[0]); - * my ($fe_off, $hi_off, $lo_off) = (0,0,1); - * my @out = (); - * while(($hi, $lo) = splice(@euc, 0, 2)) { - * $hi &= 127; $lo &= 127; - * $fe_off = 21 if $hi == 73; - * $fe_off = 34 if $hi == 126; - * ($hi_off, $lo_off) = ($lo_off, $hi_off) if ($hi <74 or $hi >125); - * push(@out, ((($hi+$hi_off) >> 1)+ ($hi <74 ? 200:187)- $fe_off), - * $lo + ((($hi+$lo_off) & 1) ? ($lo > 110 ? 34:16):128)); - * } - * return pack("C*", @out); - */ - - unsigned char fe_off = 0; - unsigned char hi_off = 0; - unsigned char lo_off = 1; - unsigned char hi = (in >> 8) & 0x7F; - unsigned char lo = in & 0x7F; - if(73 == hi) - fe_off = 21; - if(126 == hi) - fe_off = 34; - if( (hi < 74) || ( hi > 125) ) - { - hi_off = 1; - lo_off = 0; - } - *outlen = 2; - out[0] = ((hi+hi_off) >> 1) + ((hi<74) ? 200 : 187 ) - fe_off; - out[1] = lo + (((hi+lo_off) & 1) ? ((lo > 110) ? 34 : 16) : 128); -#if 0 -printf("Johab Symbol %x %x in=%x\n", out[0], out[1], in); -#endif - return PR_TRUE; + if(outbuflen < 2) + return PR_FALSE; + else + { + /* The following code are based on the Perl code listed under + * "ISO-2022-KR or EUC-KR to Johab Conversion" (page 1013) + * in the book "CJKV Information Processing" by + * Ken Lunde + * + * sub convert2johab($) { # Convert ISO-2022-KR or EUC-KR to Johab + * my @euc = unpack("C*", $_[0]); + * my ($fe_off, $hi_off, $lo_off) = (0,0,1); + * my @out = (); + * while(($hi, $lo) = splice(@euc, 0, 2)) { + * $hi &= 127; $lo &= 127; + * $fe_off = 21 if $hi == 73; + * $fe_off = 34 if $hi == 126; + * ($hi_off, $lo_off) = ($lo_off, $hi_off) if ($hi <74 or $hi >125); + * push(@out, ((($hi+$hi_off) >> 1)+ ($hi <74 ? 200:187)- $fe_off), + * $lo + ((($hi+$lo_off) & 1) ? ($lo > 110 ? 34:16):128)); + * } + * return pack("C*", @out); + */ + + unsigned char fe_off = 0; + unsigned char hi_off = 0; + unsigned char lo_off = 1; + unsigned char hi = (in >> 8) & 0x7F; + unsigned char lo = in & 0x7F; + if(73 == hi) + fe_off = 21; + if(126 == hi) + fe_off = 34; + if( (hi < 74) || ( hi > 125) ) + { + hi_off = 1; + lo_off = 0; } + *outlen = 2; + out[0] = ((hi+hi_off) >> 1) + ((hi<74) ? 200 : 187 ) - fe_off; + out[1] = lo + (((hi+lo_off) & 1) ? ((lo > 110) ? 34 : 16) : + 128); +#if 0 + printf("Johab Symbol %x %x in=%x\n", out[0], out[1], in); +#endif + return PR_TRUE; + } } PRIVATE PRBool uCheckAndGen4BytesGB18030( - uShiftTable *shift, - PRInt32* state, - PRUint16 in, - unsigned char* out, - PRUint32 outbuflen, - PRUint32* outlen -) + uShiftTable *shift, + PRInt32* state, + PRUint16 in, + unsigned char* out, + PRUint32 outbuflen, + PRUint32* outlen + ) { - if(outbuflen < 4) - return PR_FALSE; - out[0] = (in / (10*126*10)) + 0x81; - in %= (10*126*10); - out[1] = (in / (10*126)) + 0x30; - in %= (10*126); - out[2] = (in / (10)) + 0x81; - out[3] = (in % 10) + 0x30; - *outlen = 4; - return PR_TRUE; + if(outbuflen < 4) + return PR_FALSE; + out[0] = (in / (10*126*10)) + 0x81; + in %= (10*126*10); + out[1] = (in / (10*126)) + 0x30; + in %= (10*126); + out[2] = (in / (10)) + 0x81; + out[3] = (in % 10) + 0x30; + *outlen = 4; + return PR_TRUE; } diff --git a/intl/uconv/util/umap.c b/intl/uconv/util/umap.c index c542cb4a6069..59038485ac41 100644 --- a/intl/uconv/util/umap.c +++ b/intl/uconv/util/umap.c @@ -1,24 +1,24 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ +* +* The contents of this file are subject to the Netscape Public +* License Version 1.1 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.mozilla.org/NPL/ +* +* Software distributed under the License is distributed on an "AS +* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is mozilla.org code. +* +* The Initial Developer of the Original Code is Netscape +* Communications Corporation. Portions created by Netscape are +* Copyright (C) 1998 Netscape Communications Corporation. All +* Rights Reserved. +* +* Contributor(s): +*/ /* #include "PRIntlpriv.h" */ #include "unicpriv.h" @@ -47,9 +47,9 @@ PRIVATE char uGetFormat(const uTable *uT, PRInt16 item); =================================================================================*/ PRIVATE const MapFormatFunc m_map[uNumFormatTag] = { - uMapFormate0, - uMapFormate1, - uMapFormate2, + uMapFormate0, + uMapFormate1, + uMapFormate2, }; /*================================================================================= @@ -57,9 +57,9 @@ PRIVATE const MapFormatFunc m_map[uNumFormatTag] = =================================================================================*/ PRIVATE const FillInfoFormateFunc m_fillinfo[uNumFormatTag] = { - uFillInfoFormate0, - uFillInfoFormate1, - uFillInfoFormate2, + uFillInfoFormate0, + uFillInfoFormate1, + uFillInfoFormate2, }; /*================================================================================= @@ -67,14 +67,14 @@ PRIVATE const FillInfoFormateFunc m_fillinfo[uNumFormatTag] = =================================================================================*/ PRIVATE const HitFormateFunc m_hit[uNumFormatTag] = { - uHitFormate0, - uHitFormate0, - uHitFormate2, + uHitFormate0, + uHitFormate0, + uHitFormate2, }; -#define uHit(format,in,cell) (* m_hit[(format)])((in),(cell)) -#define uMap(format,in,uT,cell) (* m_map[(format)])((in),(uT),(cell)) -#define uFillInfoCell(format,uT,cell,info) (* m_fillinfo[(format)])((uT),(cell),(info)) +#define uHit(format,in,cell) (* m_hit[(format)])((in),(cell)) +#define uMap(format,in,uT,cell) (* m_map[(format)])((in),(uT),(cell)) +#define uFillInfoCell(format,uT,cell,info) (* m_fillinfo[(format)])((uT),(cell),(info)) #define uGetMapCell(uT, item) ((uMapCell *)(((PRUint16 *)uT) + (uT)->offsetToMapCellArray) + (item)) #define uGetFormat(uT, item) (((((PRUint16 *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f) @@ -83,80 +83,80 @@ PRIVATE const HitFormateFunc m_hit[uNumFormatTag] = =================================================================================*/ MODULE_PRIVATE void uFillInfo(const uTable *uT, PRUint32* aInfo) { - PRUint16 itemOfList = uT->itemOfList; - PRUint16 i; - for(i=0;iitemOfList; + PRUint16 i; + for(i=0;iitemOfList; - PRUint16 i; - *out = NOMAPPING; - for(i=0;iitemOfList; + PRUint16 i; + *out = NOMAPPING; + for(i=0;i= cell->fmt.format0.srcBegin) && - (in <= cell->fmt.format0.srcEnd) ) ; + return ( (in >= cell->fmt.format0.srcBegin) && + (in <= cell->fmt.format0.srcEnd) ) ; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uHitFormate2(PRUint16 in,const uMapCell *cell) { - return (in == cell->fmt.format2.srcBegin); + return (in == cell->fmt.format2.srcBegin); } /*================================================================================= =================================================================================*/ PRIVATE PRUint16 uMapFormate0(PRUint16 in,const uTable *uT,const uMapCell *cell) { - return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin); + return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin); } /*================================================================================= =================================================================================*/ PRIVATE PRUint16 uMapFormate1(PRUint16 in,const uTable *uT,const uMapCell *cell) { - return (*(((PRUint16 *)uT) + uT->offsetToMappingTable - + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin)); + return (*(((PRUint16 *)uT) + uT->offsetToMappingTable + + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin)); } /*================================================================================= =================================================================================*/ PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell) { - return (cell->fmt.format2.destBegin); + return (cell->fmt.format2.destBegin); } #define SET_REPRESENTABLE(info, c) (info)[(c) >> 5] |= (1L << ((c) & 0x1f)) @@ -165,43 +165,44 @@ PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell) =================================================================================*/ PRIVATE void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,PRUint32* info) { - PRUint16 begin, end, i; - begin = cell->fmt.format0.srcBegin; - end = cell->fmt.format0.srcEnd; - if( (begin >> 5) == (end >> 5)) /* High 17 bits are the same */ - { - for(i = begin; i <= end; i++) - SET_REPRESENTABLE(info, i); - } else { - PRUint32 b = begin >> 5; - PRUint32 e = end >> 5; - info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); - info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f))); - for(b++ ; b < e ; b++) - info[b] |= 0xFFFFFFFFL; - } + PRUint16 begin, end, i; + begin = cell->fmt.format0.srcBegin; + end = cell->fmt.format0.srcEnd; + if( (begin >> 5) == (end >> 5)) /* High 17 bits are the same */ + { + for(i = begin; i <= end; i++) + SET_REPRESENTABLE(info, i); + } + else { + PRUint32 b = begin >> 5; + PRUint32 e = end >> 5; + info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); + info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f))); + for(b++ ; b < e ; b++) + info[b] |= 0xFFFFFFFFL; + } } /*================================================================================= =================================================================================*/ PRIVATE void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,PRUint32* info) { - PRUint16 begin, end, i; - PRUint16 *base; - begin = cell->fmt.format0.srcBegin; - end = cell->fmt.format0.srcEnd; - base = (((PRUint16 *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset); - for(i = begin; i <= end; i++) - { - if(0xFFFD != base[i - begin]) /* check every item */ - SET_REPRESENTABLE(info, i); - } + PRUint16 begin, end, i; + PRUint16 *base; + begin = cell->fmt.format0.srcBegin; + end = cell->fmt.format0.srcEnd; + base = (((PRUint16 *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset); + for(i = begin; i <= end; i++) + { + if(0xFFFD != base[i - begin]) /* check every item */ + SET_REPRESENTABLE(info, i); + } } /*================================================================================= =================================================================================*/ PRIVATE void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,PRUint32* info) { - SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin); + SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin); } diff --git a/intl/uconv/util/uscan.c b/intl/uconv/util/uscan.c index 2417b9df445a..2b02bb84b77e 100644 --- a/intl/uconv/util/uscan.c +++ b/intl/uconv/util/uscan.c @@ -1,24 +1,24 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ +* +* The contents of this file are subject to the Netscape Public +* License Version 1.1 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.mozilla.org/NPL/ +* +* Software distributed under the License is distributed on an "AS +* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is mozilla.org code. +* +* The Initial Developer of the Original Code is Netscape +* Communications Corporation. Portions created by Netscape are +* Copyright (C) 1998 Netscape Communications Corporation. All +* Rights Reserved. +* +* Contributor(s): +*/ #include "unicpriv.h" #define CHK_GR94(b) ( (PRUint8) 0xa0 < (PRUint8) (b) && (PRUint8) (b) < (PRUint8) 0xff ) #define CHK_GR94_2Byte(b1,b2) (CHK_GR94(b1) && CHK_GR94(b2)) @@ -31,248 +31,248 @@ typedef PRBool (*uSubScannerFunc) (unsigned char* in, PRUint16* out); =================================================================================*/ typedef PRBool (*uScannerFunc) ( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); -MODULE_PRIVATE PRBool uScan( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); +MODULE_PRIVATE PRBool uScan( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); -#define uSubScanner(sub,in,out) (* m_subscanner[sub])((in),(out)) +#define uSubScanner(sub,in,out) (* m_subscanner[sub])((in),(out)) PRIVATE PRBool uCheckAndScanAlways1Byte( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanAlways2Byte( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanAlways2ByteShiftGR( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanByTable( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan2ByteGRPrefix8F( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA2( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanAlways2ByteSwap( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanAlways4Byte( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanAlways4ByteSwap( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA3( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA4( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA5( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA6( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA7( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanAlways1ByteShiftGL( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCnSAlways8BytesComposedHangul( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCnSAlways8BytesGLComposedHangul( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uScanComposedHangulCommon( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen, - PRUint8 mask -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen, + PRUint8 mask + ); PRIVATE PRBool uCheckAndScanJohabHangul( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScanJohabSymbol( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uCheckAndScan4BytesGB18030( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -); + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ); PRIVATE PRBool uScanAlways2Byte( - unsigned char* in, - PRUint16* out -); + unsigned char* in, + PRUint16* out + ); PRIVATE PRBool uScanAlways2ByteShiftGR( - unsigned char* in, - PRUint16* out -); + unsigned char* in, + PRUint16* out + ); PRIVATE PRBool uScanAlways1Byte( - unsigned char* in, - PRUint16* out -); + unsigned char* in, + PRUint16* out + ); PRIVATE PRBool uScanAlways1BytePrefix8E( - unsigned char* in, - PRUint16* out -); + unsigned char* in, + PRUint16* out + ); PRIVATE PRBool uScanAlways2ByteUTF8( - unsigned char* in, - PRUint16* out -); + unsigned char* in, + PRUint16* out + ); PRIVATE PRBool uScanAlways3ByteUTF8( - unsigned char* in, - PRUint16* out -); -/*================================================================================= - + unsigned char* in, + PRUint16* out + ); + /*================================================================================= + =================================================================================*/ PRIVATE uScannerFunc m_scanner[uNumOfCharsetType] = { - uCheckAndScanAlways1Byte, - uCheckAndScanAlways2Byte, - uCheckAndScanByTable, - uCheckAndScanAlways2ByteShiftGR, - uCheckAndScan2ByteGRPrefix8F, - uCheckAndScan2ByteGRPrefix8EA2, - uCheckAndScanAlways2ByteSwap, - uCheckAndScanAlways4Byte, - uCheckAndScanAlways4ByteSwap, - uCheckAndScan2ByteGRPrefix8EA3, - uCheckAndScan2ByteGRPrefix8EA4, - uCheckAndScan2ByteGRPrefix8EA5, - uCheckAndScan2ByteGRPrefix8EA6, - uCheckAndScan2ByteGRPrefix8EA7, - uCheckAndScanAlways1ByteShiftGL, - uCnSAlways8BytesComposedHangul, - uCnSAlways8BytesGLComposedHangul, - uCheckAndScanJohabHangul, - uCheckAndScanJohabSymbol, - uCheckAndScan4BytesGB18030 + uCheckAndScanAlways1Byte, + uCheckAndScanAlways2Byte, + uCheckAndScanByTable, + uCheckAndScanAlways2ByteShiftGR, + uCheckAndScan2ByteGRPrefix8F, + uCheckAndScan2ByteGRPrefix8EA2, + uCheckAndScanAlways2ByteSwap, + uCheckAndScanAlways4Byte, + uCheckAndScanAlways4ByteSwap, + uCheckAndScan2ByteGRPrefix8EA3, + uCheckAndScan2ByteGRPrefix8EA4, + uCheckAndScan2ByteGRPrefix8EA5, + uCheckAndScan2ByteGRPrefix8EA6, + uCheckAndScan2ByteGRPrefix8EA7, + uCheckAndScanAlways1ByteShiftGL, + uCnSAlways8BytesComposedHangul, + uCnSAlways8BytesGLComposedHangul, + uCheckAndScanJohabHangul, + uCheckAndScanJohabSymbol, + uCheckAndScan4BytesGB18030 }; /*================================================================================= @@ -281,428 +281,428 @@ PRIVATE uScannerFunc m_scanner[uNumOfCharsetType] = PRIVATE uSubScannerFunc m_subscanner[uNumOfCharType] = { - uScanAlways1Byte, - uScanAlways2Byte, - uScanAlways2ByteShiftGR, - uScanAlways1BytePrefix8E, - uScanAlways2ByteUTF8, - uScanAlways3ByteUTF8 + uScanAlways1Byte, + uScanAlways2Byte, + uScanAlways2ByteShiftGR, + uScanAlways1BytePrefix8E, + uScanAlways2ByteUTF8, + uScanAlways3ByteUTF8 }; /*================================================================================= =================================================================================*/ -MODULE_PRIVATE PRBool uScan( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) +MODULE_PRIVATE PRBool uScan( + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - return (* m_scanner[shift->classID]) (shift,state,in,out,inbuflen,inscanlen); + return (* m_scanner[shift->classID]) (shift,state,in,out,inbuflen,inscanlen); } /*================================================================================= =================================================================================*/ PRIVATE PRBool uScanAlways1Byte( - unsigned char* in, - PRUint16* out -) + unsigned char* in, + PRUint16* out + ) { - *out = (PRUint16) in[0]; - return PR_TRUE; + *out = (PRUint16) in[0]; + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uScanAlways2Byte( - unsigned char* in, - PRUint16* out -) + unsigned char* in, + PRUint16* out + ) { - *out = (PRUint16) (( in[0] << 8) | (in[1])); - return PR_TRUE; + *out = (PRUint16) (( in[0] << 8) | (in[1])); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uScanAlways2ByteShiftGR( - unsigned char* in, - PRUint16* out -) + unsigned char* in, + PRUint16* out + ) { - *out = (PRUint16) ((( in[0] << 8) | (in[1])) & 0x7F7F); - return PR_TRUE; + *out = (PRUint16) ((( in[0] << 8) | (in[1])) & 0x7F7F); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uScanAlways1BytePrefix8E( - unsigned char* in, - PRUint16* out -) + unsigned char* in, + PRUint16* out + ) { - *out = (PRUint16) in[1]; - return PR_TRUE; + *out = (PRUint16) in[1]; + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uScanAlways2ByteUTF8( - unsigned char* in, - PRUint16* out -) + unsigned char* in, + PRUint16* out + ) { - *out = (PRUint16) (((in[0] & 0x001F) << 6 )| (in[1] & 0x003F)); - return PR_TRUE; + *out = (PRUint16) (((in[0] & 0x001F) << 6 )| (in[1] & 0x003F)); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uScanAlways3ByteUTF8( - unsigned char* in, - PRUint16* out -) + unsigned char* in, + PRUint16* out + ) { - *out = (PRUint16) (((in[0] & 0x000F) << 12 ) | ((in[1] & 0x003F) << 6) - | (in[2] & 0x003F)); - return PR_TRUE; + *out = (PRUint16) (((in[0] & 0x000F) << 12 ) | ((in[1] & 0x003F) << 6) + | (in[2] & 0x003F)); + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanAlways1Byte( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - /* Don't check inlen. The caller should ensure it is larger than 0 */ - *inscanlen = 1; - *out = (PRUint16) in[0]; - - return PR_TRUE; + /* Don't check inlen. The caller should ensure it is larger than 0 */ + *inscanlen = 1; + *out = (PRUint16) in[0]; + + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanAlways2Byte( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if(inbuflen < 2) - return PR_FALSE; - else - { - *inscanlen = 2; - *out = ((in[0] << 8) | ( in[1])) ; - return PR_TRUE; - } + if(inbuflen < 2) + return PR_FALSE; + else + { + *inscanlen = 2; + *out = ((in[0] << 8) | ( in[1])) ; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanAlways2ByteShiftGR( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - /* - *Both bytes should be in the range of [0xa1,0xfe] for 94x94 character sets - * invoked on GR. No encoding implemented in Mozilla uses 96x96 char. sets. - */ - if(inbuflen < 2 || ! CHK_GR94_2Byte(in[1],in[0])) - return PR_FALSE; - else - { - *inscanlen = 2; - *out = (((in[0] << 8) | ( in[1])) & 0x7F7F); - return PR_TRUE; - } +/* +*Both bytes should be in the range of [0xa1,0xfe] for 94x94 character sets +* invoked on GR. No encoding implemented in Mozilla uses 96x96 char. sets. + */ + if(inbuflen < 2 || ! CHK_GR94_2Byte(in[1],in[0])) + return PR_FALSE; + else + { + *inscanlen = 2; + *out = (((in[0] << 8) | ( in[1])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanByTable( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - PRInt16 i; - uShiftCell* cell = &(shift->shiftcell[0]); - PRInt16 itemnum = shift->numOfItem; - for(i=0;i= cell[i].shiftin.Min) && - ( in[0] <= cell[i].shiftin.Max)) - { - if(inbuflen < cell[i].reserveLen) - return PR_FALSE; - else - { - *inscanlen = cell[i].reserveLen; - return (uSubScanner(cell[i].classID,in,out)); - } - } - } - return PR_FALSE; + PRInt16 i; + uShiftCell* cell = &(shift->shiftcell[0]); + PRInt16 itemnum = shift->numOfItem; + for(i=0;i= cell[i].shiftin.Min) && + ( in[0] <= cell[i].shiftin.Max)) + { + if(inbuflen < cell[i].reserveLen) + return PR_FALSE; + else + { + *inscanlen = cell[i].reserveLen; + return (uSubScanner(cell[i].classID,in,out)); + } + } + } + return PR_FALSE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScan2ByteGRPrefix8F( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if((inbuflen < 3) ||(in[0] != 0x8F) || ! CHK_GR94_2Byte(in[1],in[2])) - return PR_FALSE; - else - { - *inscanlen = 3; - *out = (((in[1] << 8) | ( in[2])) & 0x7F7F); - return PR_TRUE; - } + if((inbuflen < 3) ||(in[0] != 0x8F) || ! CHK_GR94_2Byte(in[1],in[2])) + return PR_FALSE; + else + { + *inscanlen = 3; + *out = (((in[1] << 8) | ( in[2])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA2( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA2) || ! CHK_GR94_2Byte(in[2],in[3])) - return PR_FALSE; - else - { - *inscanlen = 4; - *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); - return PR_TRUE; - } + if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA2) || ! CHK_GR94_2Byte(in[2],in[3])) + return PR_FALSE; + else + { + *inscanlen = 4; + *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanAlways2ByteSwap( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if(inbuflen < 2) - return PR_FALSE; - else - { - *inscanlen = 2; - *out = ((in[1] << 8) | ( in[0])) ; - return PR_TRUE; - } + if(inbuflen < 2) + return PR_FALSE; + else + { + *inscanlen = 2; + *out = ((in[1] << 8) | ( in[0])) ; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanAlways4Byte( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if(inbuflen < 4) - return PR_FALSE; - else - { - *inscanlen = 4; - if((0 ==in[0]) && ( 0==in[1])) - *out = ((in[2] << 8) | ( in[3])) ; - else - *out = 0xFFFD ; - return PR_TRUE; - } + if(inbuflen < 4) + return PR_FALSE; + else + { + *inscanlen = 4; + if((0 ==in[0]) && ( 0==in[1])) + *out = ((in[2] << 8) | ( in[3])) ; + else + *out = 0xFFFD ; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanAlways4ByteSwap( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if(inbuflen < 4) - return PR_FALSE; - else - { - *inscanlen = 4; - if((0 ==in[2]) && ( 0==in[3])) - *out = ((in[1] << 8) | ( in[0])) ; - else - *out = 0xFFFD ; - return PR_TRUE; - } + if(inbuflen < 4) + return PR_FALSE; + else + { + *inscanlen = 4; + if((0 ==in[2]) && ( 0==in[3])) + *out = ((in[1] << 8) | ( in[0])) ; + else + *out = 0xFFFD ; + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA3( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA3) || ! CHK_GR94_2Byte(in[2],in[3])) - return PR_FALSE; - else - { - *inscanlen = 4; - *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); - return PR_TRUE; - } + if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA3) || ! CHK_GR94_2Byte(in[2],in[3])) + return PR_FALSE; + else + { + *inscanlen = 4; + *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA4( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA4) || ! CHK_GR94_2Byte(in[2],in[3])) - return PR_FALSE; - else - { - *inscanlen = 4; - *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); - return PR_TRUE; - } + if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA4) || ! CHK_GR94_2Byte(in[2],in[3])) + return PR_FALSE; + else + { + *inscanlen = 4; + *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA5( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA5) || ! CHK_GR94_2Byte(in[2],in[3])) - return PR_FALSE; - else - { - *inscanlen = 4; - *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); - return PR_TRUE; - } + if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA5) || ! CHK_GR94_2Byte(in[2],in[3])) + return PR_FALSE; + else + { + *inscanlen = 4; + *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA6( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA6) || ! CHK_GR94_2Byte(in[2],in[3])) - return PR_FALSE; - else - { - *inscanlen = 4; - *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); - return PR_TRUE; - } + if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA6) || ! CHK_GR94_2Byte(in[2],in[3])) + return PR_FALSE; + else + { + *inscanlen = 4; + *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA7( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA7) || ! CHK_GR94_2Byte(in[2],in[3])) - return PR_FALSE; - else - { - *inscanlen = 4; - *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); - return PR_TRUE; - } + if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA7) || ! CHK_GR94_2Byte(in[2],in[3])) + return PR_FALSE; + else + { + *inscanlen = 4; + *out = (((in[2] << 8) | ( in[3])) & 0x7F7F); + return PR_TRUE; + } } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCheckAndScanAlways1ByteShiftGL( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - /* Don't check inlen. The caller should ensure it is larger than 0 */ - *inscanlen = 1; - *out = (PRUint16) in[0] | 0x80; - - return PR_TRUE; + /* Don't check inlen. The caller should ensure it is larger than 0 */ + *inscanlen = 1; + *out = (PRUint16) in[0] | 0x80; + + return PR_TRUE; } /*================================================================================= @@ -714,234 +714,239 @@ PRIVATE PRBool uCheckAndScanAlways1ByteShiftGL( #define TCount 28 #define NCount (VCount * TCount) PRIVATE PRBool uScanComposedHangulCommon( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen, - PRUint8 mask -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + 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) || ((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] < (mask&0xa1)) && (in[3] > (mask&0xbe))) { /* illegal leading consonant */ - return PR_FALSE; - } else { - static PRUint8 lMap[] = { - /* A1 A2 A3 A4 A5 A6 A7 */ - 0, 1,0xff, 2,0xff,0xff, 3, - /* A8 A9 AA AB AC AD AE AF */ - 4, 5,0xff,0xff,0xff,0xff,0xff,0xff, - /* B0 B1 B2 B3 B4 B5 B6 B7 */ - 0xff, 6, 7, 8,0xff, 9, 10, 11, - /* B8 B9 BA BB BC BD BE */ - 12, 13, 14, 15, 16, 17, 18 - }; - - LIndex = lMap[in[3] - (0xa1 & mask)]; - if(0xff == (0xff & LIndex)) - return PR_FALSE; - } - - /* Compute VIndex */ - if((in[5] < (mask&0xbf)) && (in[5] > (mask&0xd3))) { /* illegal medial vowel */ - return PR_FALSE; - } else { - VIndex = in[5] - (mask&0xbf); - } - - /* Compute TIndex */ - if((mask&0xd4) == in[7]) - { - TIndex = 0; - } else if((in[7] < (mask&0xa1)) && (in[7] > (mask&0xbe))) {/* illegal trailling consonant */ - return PR_FALSE; - } else { - static PRUint8 tMap[] = { - /* A1 A2 A3 A4 A5 A6 A7 */ - 1, 2, 3, 4, 5, 6, 7, - /* A8 A9 AA AB AC AD AE AF */ - 0xff, 8, 9, 10, 11, 12, 13, 14, - /* B0 B1 B2 B3 B4 B5 B6 B7 */ - 15, 16, 17,0xff, 18, 19, 20, 21, - /* B8 B9 BA BB BC BD BE */ - 22,0xff, 23, 24, 25, 26, 27 - }; - TIndex = tMap[in[3] - (mask&0xa1)]; - if(0xff == (0xff & TIndex)) - return PR_FALSE; - } - - *inscanlen = 8; - /* the following line is from Unicode 2.0 page 3-13 item 5 */ - *out = ( LIndex * VCount + VIndex) * TCount + TIndex + SBase; - - return PR_TRUE; + + PRUint16 LIndex, VIndex, TIndex; + /* no 8 bytes, not in a4 range, or the first 2 byte are not a4d4 */ + 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] < (mask&0xa1)) && (in[3] > (mask&0xbe))) { /* illegal leading consonant */ + return PR_FALSE; + } + else { + static PRUint8 lMap[] = { + /* A1 A2 A3 A4 A5 A6 A7 */ + 0, 1,0xff, 2,0xff,0xff, 3, + /* A8 A9 AA AB AC AD AE AF */ + 4, 5,0xff,0xff,0xff,0xff,0xff,0xff, + /* B0 B1 B2 B3 B4 B5 B6 B7 */ + 0xff, 6, 7, 8,0xff, 9, 10, 11, + /* B8 B9 BA BB BC BD BE */ + 12, 13, 14, 15, 16, 17, 18 + }; + + LIndex = lMap[in[3] - (0xa1 & mask)]; + if(0xff == (0xff & LIndex)) + return PR_FALSE; + } + + /* Compute VIndex */ + if((in[5] < (mask&0xbf)) && (in[5] > (mask&0xd3))) { /* illegal medial vowel */ + return PR_FALSE; + } + else { + VIndex = in[5] - (mask&0xbf); + } + + /* Compute TIndex */ + if((mask&0xd4) == in[7]) + { + TIndex = 0; + } + else if((in[7] < (mask&0xa1)) && (in[7] > (mask&0xbe))) {/* illegal trailling consonant */ + return PR_FALSE; + } + else { + static PRUint8 tMap[] = { + /* A1 A2 A3 A4 A5 A6 A7 */ + 1, 2, 3, 4, 5, 6, 7, + /* A8 A9 AA AB AC AD AE AF */ + 0xff, 8, 9, 10, 11, 12, 13, 14, + /* B0 B1 B2 B3 B4 B5 B6 B7 */ + 15, 16, 17,0xff, 18, 19, 20, 21, + /* B8 B9 BA BB BC BD BE */ + 22,0xff, 23, 24, 25, 26, 27 + }; + TIndex = tMap[in[3] - (mask&0xa1)]; + if(0xff == (0xff & TIndex)) + return PR_FALSE; + } + + *inscanlen = 8; + /* the following line is from Unicode 2.0 page 3-13 item 5 */ + *out = ( LIndex * VCount + VIndex) * TCount + TIndex + SBase; + + return PR_TRUE; } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCnSAlways8BytesComposedHangul( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - return uScanComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0xff); + return uScanComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0xff); } /*================================================================================= =================================================================================*/ PRIVATE PRBool uCnSAlways8BytesGLComposedHangul( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - return uScanComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0x7f); + return uScanComposedHangulCommon(shift,state,in,out,inbuflen,inscanlen,0x7f); } PRIVATE PRBool uCheckAndScanJohabHangul( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - /* since we don't have code to convert Johab to Unicode right now * - * make this part of code #if 0 to save space untill we fully test it */ +/* since we don't have code to convert Johab to Unicode right now * + * make this part of code #if 0 to save space untill we fully test it */ #if 0 - if(inbuflen < 2) - return PR_FALSE; - else { - /* - * See Table 4-45 Johab Encoding's Five-Bit Binary Patterns in page 183 - * of "CJKV Information Processing" for details - */ - static PRUint8 lMap[32]={ /* totaly 19 */ - 0xff,0xff,0, 1, 2, 3, 4, 5, /* 0-7 */ - 6, 7, 8, 9, 10, 11, 12, 13, /* 8-15 */ - 14, 15, 16, 17, 18, 0xff,0xff,0xff, /* 16-23 */ - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff /* 24-31 */ - }; - static PRUint8 vMap[32]={ /* totaly 21 */ - 0xff,0xff,0xff,0, 1, 2, 3, 4, /* 0-7 */ - 0xff,0xff,5, 6, 7, 8, 9, 10, /* 8-15 */ - 0xff,0xff,11, 12, 13, 14, 15, 16, /* 16-23 */ - 0xff,0xff,17, 18, 19, 20, 0xff,0xff /* 24-31 */ - }; - static PRUint8 tMap[32]={ /* totaly 29 */ - 0xff,0, 1, 2, 3, 4, 5, 6, /* 0-7 */ - 7, 8, 9, 10, 11, 12, 13, 14, /* 8-15 */ - 15, 16, 0xff,17, 18, 19, 20, 21, /* 16-23 */ - 22, 23, 24, 25, 26, 27, 0xff,0xff /* 24-31 */ - }; - PRUint16 ch = (in[0] << 8) | in[1]; - PRUint16 LIndex, VIndex, TIndex; - if(0 == (0x8000 & ch)) - return PR_FALSE; - LIndex=lMap[(ch>>10)& 0x1F]; - VIndex=vMap[(ch>>5) & 0x1F]; - TIndex=tMap[(ch>>0) & 0x1F]; - if((0xff==(LIndex)) || - (0xff==(VIndex)) || - (0xff==(TIndex))) - return PR_FALSE; - /* the following line is from Unicode 2.0 page 3-13 item 5 */ - *out = ( LIndex * VCount + VIndex) * TCount + TIndex + SBase; - return PR_TRUE; - } -#else + if(inbuflen < 2) return PR_FALSE; + else { + /* + * See Table 4-45 Johab Encoding's Five-Bit Binary Patterns in page 183 + * of "CJKV Information Processing" for details + */ + static PRUint8 lMap[32]={ /* totaly 19 */ + 0xff,0xff,0, 1, 2, 3, 4, 5, /* 0-7 */ + 6, 7, 8, 9, 10, 11, 12, 13, /* 8-15 */ + 14, 15, 16, 17, 18, 0xff,0xff,0xff, /* 16-23 */ + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff /* 24-31 */ + }; + static PRUint8 vMap[32]={ /* totaly 21 */ + 0xff,0xff,0xff,0, 1, 2, 3, 4, /* 0-7 */ + 0xff,0xff,5, 6, 7, 8, 9, 10, /* 8-15 */ + 0xff,0xff,11, 12, 13, 14, 15, 16, /* 16-23 */ + 0xff,0xff,17, 18, 19, 20, 0xff,0xff /* 24-31 */ + }; + static PRUint8 tMap[32]={ /* totaly 29 */ + 0xff,0, 1, 2, 3, 4, 5, 6, /* 0-7 */ + 7, 8, 9, 10, 11, 12, 13, 14, /* 8-15 */ + 15, 16, 0xff,17, 18, 19, 20, 21, /* 16-23 */ + 22, 23, 24, 25, 26, 27, 0xff,0xff /* 24-31 */ + }; + PRUint16 ch = (in[0] << 8) | in[1]; + PRUint16 LIndex, VIndex, TIndex; + if(0 == (0x8000 & ch)) + return PR_FALSE; + LIndex=lMap[(ch>>10)& 0x1F]; + VIndex=vMap[(ch>>5) & 0x1F]; + TIndex=tMap[(ch>>0) & 0x1F]; + if((0xff==(LIndex)) || + (0xff==(VIndex)) || + (0xff==(TIndex))) + return PR_FALSE; + /* the following line is from Unicode 2.0 page 3-13 item 5 */ + *out = ( LIndex * VCount + VIndex) * TCount + TIndex + SBase; + return PR_TRUE; + } +#else + return PR_FALSE; #endif } PRIVATE PRBool uCheckAndScanJohabSymbol( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { - /* since we don't have code to convert Johab to Unicode right now - * make this part of code #if 0 to save space untill we fully test it */ +/* since we don't have code to convert Johab to Unicode right now + * make this part of code #if 0 to save space untill we fully test it */ #if 0 - if(inbuflen < 2) - return PR_FALSE; - else { - /* - * The following code are based on the Perl code lised under - * "Johab to ISO-2022-KR or EUC-KR Conversion" in page 1014 of - * "CJKV Information Processing" by Ken Lunde - * - * sub johab2ks ($) { # Convert Johab to ISO-2022-KR - * my @johab = unpack("C*", $_[0]); - * my ($offset, $d8_off) = (0,0); - * my @out = (); - * while(($hi, $lo) = splice($johab, 0, 2)) { - * $offset = 1 if ($hi > 223 and $hi < 250); - * $d8_off = ($hi == 216 and ($lo > 160 ? 94 : 42)); - * push (@out, (((($hi - ($hi < 223 ? 200 : 187)) << 1) - - * ($lo < 161 ? 1 : 0) + $offset) + $d8_off), - * $lo - ($lo < 161 ? ($lo > 126 ? 34 : 16) : 128 )); - * } - * return pack ("C*", @out); - * } - * additional comments from Ken Lunde - * $d8_off = ($hi == 216 and ($lo > 160 ? 94 : 42)); - * has three possible return values: - * 0 if $hi is not equal to 216 - * 94 if $hi is euqal to 216 and if $lo is greater than 160 - * 42 if $hi is euqal to 216 and if $lo is not greater than 160 - */ - unsigned char hi = in[0]; - unsigned char lo = in[1]; - PRUint16 offset = (( hi > 223 ) && ( hi < 250)) ? 1 : 0; - PRUint16 d8_off = 0; - if(216 == hi) { - if( lo > 160) - d8_off = 94; - else - d8_off = 42; - } - - *out = (((((hi - ((hi < 223) ? 200 : 187)) << 1) - - (lo < 161 ? 1 : 0) + offset) + d8_off) << 8 ) | - (lo - ((lo < 161) ? ((lo > 126) ? 34 : 16) : 128)); - return PR_TRUE; - } -#else + if(inbuflen < 2) return PR_FALSE; + else { + /* + * The following code are based on the Perl code lised under + * "Johab to ISO-2022-KR or EUC-KR Conversion" in page 1014 of + * "CJKV Information Processing" by Ken Lunde + * + * sub johab2ks ($) { # Convert Johab to ISO-2022-KR + * my @johab = unpack("C*", $_[0]); + * my ($offset, $d8_off) = (0,0); + * my @out = (); + * while(($hi, $lo) = splice($johab, 0, 2)) { + * $offset = 1 if ($hi > 223 and $hi < 250); + * $d8_off = ($hi == 216 and ($lo > 160 ? 94 : 42)); + * push (@out, (((($hi - ($hi < 223 ? 200 : 187)) << 1) - + * ($lo < 161 ? 1 : 0) + $offset) + $d8_off), + * $lo - ($lo < 161 ? ($lo > 126 ? 34 : 16) : 128 )); + * } + * return pack ("C*", @out); + * } + * additional comments from Ken Lunde + * $d8_off = ($hi == 216 and ($lo > 160 ? 94 : 42)); + * has three possible return values: + * 0 if $hi is not equal to 216 + * 94 if $hi is euqal to 216 and if $lo is greater than 160 + * 42 if $hi is euqal to 216 and if $lo is not greater than 160 + */ + unsigned char hi = in[0]; + unsigned char lo = in[1]; + PRUint16 offset = (( hi > 223 ) && ( hi < 250)) ? 1 : 0; + PRUint16 d8_off = 0; + if(216 == hi) { + if( lo > 160) + d8_off = 94; + else + d8_off = 42; + } + + *out = (((((hi - ((hi < 223) ? 200 : 187)) << 1) - + (lo < 161 ? 1 : 0) + offset) + d8_off) << 8 ) | + (lo - ((lo < 161) ? ((lo > 126) ? 34 : 16) : + 128)); + return PR_TRUE; + } +#else + return PR_FALSE; #endif } PRIVATE PRBool uCheckAndScan4BytesGB18030( - uShiftTable *shift, - PRInt32* state, - unsigned char *in, - PRUint16 *out, - PRUint32 inbuflen, - PRUint32* inscanlen -) + uShiftTable *shift, + PRInt32* state, + unsigned char *in, + PRUint16 *out, + PRUint32 inbuflen, + PRUint32* inscanlen + ) { PRUint32 data; if(inbuflen < 4) return PR_FALSE; - + if((in[0] < 0x81 ) || (0xfe < in[0])) return PR_FALSE; if((in[1] < 0x30 ) || (0x39 < in[1])) @@ -950,13 +955,13 @@ PRIVATE PRBool uCheckAndScan4BytesGB18030( return PR_FALSE; if((in[3] < 0x30 ) || (0x39 < in[3])) return PR_FALSE; - + data = (((((in[0] - 0x81) * 10 + (in[1] - 0x30)) * 126) + - (in[2] - 0x81)) * 10 ) + (in[3] - 0x30); - + (in[2] - 0x81)) * 10 ) + (in[3] - 0x30); + *inscanlen = 4; if(data >= 0x00010000) return PR_FALSE; *out = (PRUint16) data; - return PR_TRUE; + return PR_TRUE; }