Update contrib.
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include <convgeneratedcpp.h>
26 #define ARRAY_LENGTH(aArray) (sizeof(aArray)/sizeof((aArray)[0]))
28 const TInt KNumberOfBytesOfWorkingMemory=(21+21+2+1)*sizeof(SCnvConversionData::SOneDirectionData::SRange); // GB2312.CTL defines 21 foreign-to-Unicode ranges and 21 Unicode-to-foreign ranges, and GBK.CTL defines 2 foreign-to-Unicode ranges and 1 Unicode-to-foreign range
30 _LIT(KLitPanicText, "GBK_SHARED");
34 EPanicTooManyBytesOfWorkingMemoryUsed1=1,
35 EPanicTooManyBytesOfWorkingMemoryUsed2
38 LOCAL_D const SCnvConversionData::SVariableByteData::SRange foreignVariableByteDataRanges[]=
54 LOCAL_C void Panic(TPanic aPanic)
56 User::Panic(KLitPanicText, aPanic);
59 LOCAL_C void SetUpCompleteGbkConversionData(SCnvConversionData& aCompleteGbkConversionData, TUint8* aWorkingMemory)
61 const SCnvConversionData& gb2312ConversionData=CnvGb2312::ConversionData();
62 const SCnvConversionData& supplementaryGbkConversionData=conversionData;
63 // create a SCnvConversionData that is the combination of gb2312ConversionData and supplementaryGbkConversionData
64 aCompleteGbkConversionData.iEndiannessOfForeignCharacters=SCnvConversionData::EFixedBigEndian;
65 aCompleteGbkConversionData.iForeignVariableByteData.iNumberOfRanges=ARRAY_LENGTH(foreignVariableByteDataRanges);
66 aCompleteGbkConversionData.iForeignVariableByteData.iRangeArray=foreignVariableByteDataRanges;
67 TInt numberOfBytesOfWorkingMemoryUsed=0;
68 // set up the foreign-to-Unicode data
69 const TInt numberOfForeignToUnicodeDataRanges=gb2312ConversionData.iForeignToUnicodeData.iNumberOfRanges+supplementaryGbkConversionData.iForeignToUnicodeData.iNumberOfRanges;
70 aCompleteGbkConversionData.iForeignToUnicodeData.iNumberOfRanges=numberOfForeignToUnicodeDataRanges;
71 SCnvConversionData::SOneDirectionData::SRange* foreignToUnicodeDataRangeArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange*, aWorkingMemory+numberOfBytesOfWorkingMemoryUsed);
72 numberOfBytesOfWorkingMemoryUsed+=(numberOfForeignToUnicodeDataRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
73 __ASSERT_ALWAYS(numberOfBytesOfWorkingMemoryUsed<=KNumberOfBytesOfWorkingMemory, Panic(EPanicTooManyBytesOfWorkingMemoryUsed1));
74 aCompleteGbkConversionData.iForeignToUnicodeData.iRangeArray=foreignToUnicodeDataRangeArray;
75 Mem::Copy(foreignToUnicodeDataRangeArray, gb2312ConversionData.iForeignToUnicodeData.iRangeArray, gb2312ConversionData.iForeignToUnicodeData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
76 Mem::Copy(foreignToUnicodeDataRangeArray+gb2312ConversionData.iForeignToUnicodeData.iNumberOfRanges, supplementaryGbkConversionData.iForeignToUnicodeData.iRangeArray, supplementaryGbkConversionData.iForeignToUnicodeData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
77 // set up the Unicode-to-foreign data
78 const TInt numberOfUnicodeToForeignDataRanges=gb2312ConversionData.iUnicodeToForeignData.iNumberOfRanges+supplementaryGbkConversionData.iUnicodeToForeignData.iNumberOfRanges;
79 aCompleteGbkConversionData.iUnicodeToForeignData.iNumberOfRanges=numberOfUnicodeToForeignDataRanges;
80 SCnvConversionData::SOneDirectionData::SRange* unicodeToForeignDataRangeArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange*, aWorkingMemory+numberOfBytesOfWorkingMemoryUsed);
81 numberOfBytesOfWorkingMemoryUsed+=(numberOfUnicodeToForeignDataRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
82 __ASSERT_ALWAYS(numberOfBytesOfWorkingMemoryUsed<=KNumberOfBytesOfWorkingMemory, Panic(EPanicTooManyBytesOfWorkingMemoryUsed2));
83 aCompleteGbkConversionData.iUnicodeToForeignData.iRangeArray=unicodeToForeignDataRangeArray;
84 Mem::Copy(unicodeToForeignDataRangeArray, gb2312ConversionData.iUnicodeToForeignData.iRangeArray, gb2312ConversionData.iUnicodeToForeignData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
85 Mem::Copy(unicodeToForeignDataRangeArray+gb2312ConversionData.iUnicodeToForeignData.iNumberOfRanges, supplementaryGbkConversionData.iUnicodeToForeignData.iRangeArray, supplementaryGbkConversionData.iUnicodeToForeignData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
88 EXPORT_C const TDesC8& CnvGbk::ReplacementForUnconvertibleUnicodeCharacters()
90 return ReplacementForUnconvertibleUnicodeCharacters_internal();
93 EXPORT_C const SCnvConversionData& CnvGbk::ConversionData()
95 return conversionData;
98 EXPORT_C TInt CnvGbk::ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
101 return ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, notUsed, 0);
104 EXPORT_C TInt CnvGbk::ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
106 SCnvConversionData completeGbkConversionData;
107 TUint8 workingMemory[KNumberOfBytesOfWorkingMemory]; // 900 bytes on the stack is just about tolerable (no other functions called from here will make any significant use of the stack)
108 SetUpCompleteGbkConversionData(completeGbkConversionData, workingMemory);
109 return CCnvCharacterSetConverter::DoConvertFromUnicode(completeGbkConversionData, aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, aOutputConversionFlags, aInputConversionFlags);
112 EXPORT_C TInt CnvGbk::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
115 return ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, notUsed, 0);
118 EXPORT_C TInt CnvGbk::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
120 SCnvConversionData completeGbkConversionData;
121 TUint8 workingMemory[KNumberOfBytesOfWorkingMemory]; // 900 bytes on the stack is just about tolerable (no other functions called from here will make any significant use of the stack)
122 SetUpCompleteGbkConversionData(completeGbkConversionData, workingMemory);
123 return CCnvCharacterSetConverter::DoConvertToUnicode(completeGbkConversionData, aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aOutputConversionFlags, aInputConversionFlags);
126 EXPORT_C TBool CnvGbk::IsCharGBBased(TInt& aConfidenceLevel, const TDesC8& aSample)
128 return CnvGb2312::IsCharGBBased(aConfidenceLevel, aSample);