sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32std.h>
|
sl@0
|
20 |
#include <charconv.h>
|
sl@0
|
21 |
#include <convdata.h>
|
sl@0
|
22 |
#include <convgeneratedcpp.h>
|
sl@0
|
23 |
#include "gb2312.h"
|
sl@0
|
24 |
#include "gbk.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
#define ARRAY_LENGTH(aArray) (sizeof(aArray)/sizeof((aArray)[0]))
|
sl@0
|
27 |
|
sl@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
|
sl@0
|
29 |
|
sl@0
|
30 |
_LIT(KLitPanicText, "GBK_SHARED");
|
sl@0
|
31 |
|
sl@0
|
32 |
enum TPanic
|
sl@0
|
33 |
{
|
sl@0
|
34 |
EPanicTooManyBytesOfWorkingMemoryUsed1=1,
|
sl@0
|
35 |
EPanicTooManyBytesOfWorkingMemoryUsed2
|
sl@0
|
36 |
};
|
sl@0
|
37 |
|
sl@0
|
38 |
LOCAL_D const SCnvConversionData::SVariableByteData::SRange foreignVariableByteDataRanges[]=
|
sl@0
|
39 |
{
|
sl@0
|
40 |
{
|
sl@0
|
41 |
0x00,
|
sl@0
|
42 |
0x7f,
|
sl@0
|
43 |
0,
|
sl@0
|
44 |
0
|
sl@0
|
45 |
},
|
sl@0
|
46 |
{
|
sl@0
|
47 |
0x80,
|
sl@0
|
48 |
0xff,
|
sl@0
|
49 |
1,
|
sl@0
|
50 |
0
|
sl@0
|
51 |
}
|
sl@0
|
52 |
};
|
sl@0
|
53 |
|
sl@0
|
54 |
LOCAL_C void Panic(TPanic aPanic)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
User::Panic(KLitPanicText, aPanic);
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
LOCAL_C void SetUpCompleteGbkConversionData(SCnvConversionData& aCompleteGbkConversionData, TUint8* aWorkingMemory)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
const SCnvConversionData& gb2312ConversionData=CnvGb2312::ConversionData();
|
sl@0
|
62 |
const SCnvConversionData& supplementaryGbkConversionData=conversionData;
|
sl@0
|
63 |
// create a SCnvConversionData that is the combination of gb2312ConversionData and supplementaryGbkConversionData
|
sl@0
|
64 |
aCompleteGbkConversionData.iEndiannessOfForeignCharacters=SCnvConversionData::EFixedBigEndian;
|
sl@0
|
65 |
aCompleteGbkConversionData.iForeignVariableByteData.iNumberOfRanges=ARRAY_LENGTH(foreignVariableByteDataRanges);
|
sl@0
|
66 |
aCompleteGbkConversionData.iForeignVariableByteData.iRangeArray=foreignVariableByteDataRanges;
|
sl@0
|
67 |
TInt numberOfBytesOfWorkingMemoryUsed=0;
|
sl@0
|
68 |
// set up the foreign-to-Unicode data
|
sl@0
|
69 |
const TInt numberOfForeignToUnicodeDataRanges=gb2312ConversionData.iForeignToUnicodeData.iNumberOfRanges+supplementaryGbkConversionData.iForeignToUnicodeData.iNumberOfRanges;
|
sl@0
|
70 |
aCompleteGbkConversionData.iForeignToUnicodeData.iNumberOfRanges=numberOfForeignToUnicodeDataRanges;
|
sl@0
|
71 |
SCnvConversionData::SOneDirectionData::SRange* foreignToUnicodeDataRangeArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange*, aWorkingMemory+numberOfBytesOfWorkingMemoryUsed);
|
sl@0
|
72 |
numberOfBytesOfWorkingMemoryUsed+=(numberOfForeignToUnicodeDataRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
|
sl@0
|
73 |
__ASSERT_ALWAYS(numberOfBytesOfWorkingMemoryUsed<=KNumberOfBytesOfWorkingMemory, Panic(EPanicTooManyBytesOfWorkingMemoryUsed1));
|
sl@0
|
74 |
aCompleteGbkConversionData.iForeignToUnicodeData.iRangeArray=foreignToUnicodeDataRangeArray;
|
sl@0
|
75 |
Mem::Copy(foreignToUnicodeDataRangeArray, gb2312ConversionData.iForeignToUnicodeData.iRangeArray, gb2312ConversionData.iForeignToUnicodeData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
|
sl@0
|
76 |
Mem::Copy(foreignToUnicodeDataRangeArray+gb2312ConversionData.iForeignToUnicodeData.iNumberOfRanges, supplementaryGbkConversionData.iForeignToUnicodeData.iRangeArray, supplementaryGbkConversionData.iForeignToUnicodeData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
|
sl@0
|
77 |
// set up the Unicode-to-foreign data
|
sl@0
|
78 |
const TInt numberOfUnicodeToForeignDataRanges=gb2312ConversionData.iUnicodeToForeignData.iNumberOfRanges+supplementaryGbkConversionData.iUnicodeToForeignData.iNumberOfRanges;
|
sl@0
|
79 |
aCompleteGbkConversionData.iUnicodeToForeignData.iNumberOfRanges=numberOfUnicodeToForeignDataRanges;
|
sl@0
|
80 |
SCnvConversionData::SOneDirectionData::SRange* unicodeToForeignDataRangeArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange*, aWorkingMemory+numberOfBytesOfWorkingMemoryUsed);
|
sl@0
|
81 |
numberOfBytesOfWorkingMemoryUsed+=(numberOfUnicodeToForeignDataRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
|
sl@0
|
82 |
__ASSERT_ALWAYS(numberOfBytesOfWorkingMemoryUsed<=KNumberOfBytesOfWorkingMemory, Panic(EPanicTooManyBytesOfWorkingMemoryUsed2));
|
sl@0
|
83 |
aCompleteGbkConversionData.iUnicodeToForeignData.iRangeArray=unicodeToForeignDataRangeArray;
|
sl@0
|
84 |
Mem::Copy(unicodeToForeignDataRangeArray, gb2312ConversionData.iUnicodeToForeignData.iRangeArray, gb2312ConversionData.iUnicodeToForeignData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
|
sl@0
|
85 |
Mem::Copy(unicodeToForeignDataRangeArray+gb2312ConversionData.iUnicodeToForeignData.iNumberOfRanges, supplementaryGbkConversionData.iUnicodeToForeignData.iRangeArray, supplementaryGbkConversionData.iUnicodeToForeignData.iNumberOfRanges*sizeof(SCnvConversionData::SOneDirectionData::SRange));
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
EXPORT_C const TDesC8& CnvGbk::ReplacementForUnconvertibleUnicodeCharacters()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
return ReplacementForUnconvertibleUnicodeCharacters_internal();
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
EXPORT_C const SCnvConversionData& CnvGbk::ConversionData()
|
sl@0
|
94 |
{
|
sl@0
|
95 |
return conversionData;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
EXPORT_C TInt CnvGbk::ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
TUint notUsed;
|
sl@0
|
101 |
return ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, notUsed, 0);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@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)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
SCnvConversionData completeGbkConversionData;
|
sl@0
|
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)
|
sl@0
|
108 |
SetUpCompleteGbkConversionData(completeGbkConversionData, workingMemory);
|
sl@0
|
109 |
return CCnvCharacterSetConverter::DoConvertFromUnicode(completeGbkConversionData, aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, aOutputConversionFlags, aInputConversionFlags);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
EXPORT_C TInt CnvGbk::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
TUint notUsed;
|
sl@0
|
115 |
return ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, notUsed, 0);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
EXPORT_C TInt CnvGbk::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
SCnvConversionData completeGbkConversionData;
|
sl@0
|
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)
|
sl@0
|
122 |
SetUpCompleteGbkConversionData(completeGbkConversionData, workingMemory);
|
sl@0
|
123 |
return CCnvCharacterSetConverter::DoConvertToUnicode(completeGbkConversionData, aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aOutputConversionFlags, aInputConversionFlags);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
EXPORT_C TBool CnvGbk::IsCharGBBased(TInt& aConfidenceLevel, const TDesC8& aSample)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
return CnvGb2312::IsCharGBBased(aConfidenceLevel, aSample);
|
sl@0
|
129 |
}
|