Update contrib.
2 * Copyright (c) 2005-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.
15 * J5 charconv character converter
16 * converts from EUC_JP to unicode
17 * based on code in EUCJP_PACKED
24 #include <ecom/implementationproxy.h>
25 #include <convutils.h>
32 const TUint KSingleShift2=0x8e;
33 const TUint KSingleShift3=0x8f;
38 _LIT(KLitPanicText, "EUCJP_PACKED");
42 EPanicNothingToConvert1=1,
43 EPanicNothingToConvert2,
44 EPanicNothingToConvert3,
45 EPanicNothingToConvert4,
46 EPanicNothingToConvert5,
47 EPanicNothingToConvert6,
48 EPanicOddNumberOfBytes1,
49 EPanicOddNumberOfBytes2,
50 EPanicOddNumberOfBytes3,
51 EPanicOddNumberOfBytes4,
52 EPanicOddNumberOfBytes5,
53 EPanicOddNumberOfBytes6,
97 EPanicBadCalculation1,
98 EPanicBadCalculation2,
99 EPanicNumberOfBytesIsNotMultipleOfThree1,
100 EPanicNumberOfBytesIsNotMultipleOfThree2,
101 EPanicSingleShift2Expected,
102 EPanicSingleShift3Expected
105 LOCAL_C void Panic(TPanic aPanic)
107 User::Panic(KLitPanicText, aPanic);
113 @return The number of bytes that can be converted from aDescriptor to JisRoman
116 TInt NumberOfBytesAbleToConvertToJisRoman(const TDesC8& aDescriptor)
118 const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
119 const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
120 if (pointerToPreviousByte==pointerToLastByte)
127 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers14));
128 const TUint currentByte=*(pointerToPreviousByte+1);
129 if (currentByte&0x80)
133 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers15));
134 ++pointerToPreviousByte;
135 __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers16));
136 if (pointerToPreviousByte>=pointerToLastByte)
141 return (pointerToPreviousByte+1)-aDescriptor.Ptr();
145 @return The number of bytes that can be converted from aDescriptor to Jis X208
148 TInt NumberOfBytesAbleToConvertToJisX0208(const TDesC8& aDescriptor)
150 const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
151 const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
152 if (pointerToPreviousByte==pointerToLastByte)
158 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers17));
159 TUint currentByte=*(pointerToPreviousByte+1);
160 if (currentByte<0xa0)
164 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers18));
165 if (pointerToLastByte-pointerToPreviousByte<2)
169 ++pointerToPreviousByte;
170 currentByte=*(pointerToPreviousByte+1);
171 if (currentByte<0xa0)
173 return CCnvCharacterSetConverter::EErrorIllFormedInput;
175 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers19));
176 ++pointerToPreviousByte;
177 __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers20));
178 if (pointerToPreviousByte>=pointerToLastByte)
183 return (pointerToPreviousByte+1)-aDescriptor.Ptr();
187 @return The number of bytes that can be converted from aDescriptor to HalfWidthKatakana
190 TInt NumberOfBytesAbleToConvertToHalfWidthKatakana8(const TDesC8& aDescriptor)
192 const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
193 const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
194 if (pointerToPreviousByte==pointerToLastByte)
200 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers21));
201 TUint currentByte=*(pointerToPreviousByte+1);
202 if (currentByte!=KSingleShift2)
206 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers22));
207 if (pointerToLastByte-pointerToPreviousByte<2)
211 ++pointerToPreviousByte;
212 currentByte=*(pointerToPreviousByte+1);
213 if (currentByte<0xa0)
215 return CCnvCharacterSetConverter::EErrorIllFormedInput;
217 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers23));
218 ++pointerToPreviousByte;
219 __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers24));
220 if (pointerToPreviousByte>=pointerToLastByte)
225 return (pointerToPreviousByte+1)-aDescriptor.Ptr();
229 @return The number of bytes that can be converted from aDescriptor to JISX0212
232 TInt NumberOfBytesAbleToConvertToJisX0212(const TDesC8& aDescriptor)
234 const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
235 const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
236 if (pointerToPreviousByte==pointerToLastByte)
243 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers25));
244 TUint currentByte=*(pointerToPreviousByte+1);
245 if (currentByte!=KSingleShift3)
249 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers26));
250 if (pointerToLastByte-pointerToPreviousByte<3)
254 ++pointerToPreviousByte;
255 currentByte=*(pointerToPreviousByte+1);
256 if (currentByte<0xa0)
258 return CCnvCharacterSetConverter::EErrorIllFormedInput;
260 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers27));
261 ++pointerToPreviousByte;
262 currentByte=*(pointerToPreviousByte+1);
263 if (currentByte<0xa0)
265 return CCnvCharacterSetConverter::EErrorIllFormedInput;
267 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers28));
268 ++pointerToPreviousByte;
269 __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers29));
270 if (pointerToPreviousByte>=pointerToLastByte)
275 return (pointerToPreviousByte+1)-aDescriptor.Ptr();
278 void DummyConvertToIntermediateBufferInPlace(TDes8&)
286 void ConvertToJisX0212FromEucJpPackedInPlace(TDes8& aDescriptor)
288 const TInt descriptorLength=aDescriptor.Length();
289 __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert6));
290 __ASSERT_DEBUG(descriptorLength%3==0, Panic(EPanicNumberOfBytesIsNotMultipleOfThree2));
291 TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr());
292 const TUint8* pointerToSourceByte=pointerToTargetByte;
293 const TUint8* const pointerToLastByte=pointerToSourceByte+(descriptorLength-1);
296 __ASSERT_DEBUG(*pointerToSourceByte==KSingleShift3, Panic(EPanicSingleShift3Expected));
297 __ASSERT_DEBUG(pointerToSourceByte<pointerToLastByte, Panic(EPanicBadPointers33));
298 ++pointerToSourceByte;
299 TUint sourceByte=*pointerToSourceByte;
300 __ASSERT_DEBUG(sourceByte&0x80, Panic(EPanicBadHighBit6));
301 *pointerToTargetByte=STATIC_CAST(TUint8, sourceByte&~0x80);
302 __ASSERT_DEBUG(pointerToSourceByte<pointerToLastByte, Panic(EPanicBadPointers34));
303 ++pointerToSourceByte;
304 sourceByte=*pointerToSourceByte;
305 __ASSERT_DEBUG(sourceByte&0x80, Panic(EPanicBadHighBit7));
306 __ASSERT_DEBUG(pointerToTargetByte<pointerToLastByte, Panic(EPanicBadPointers35));
307 ++pointerToTargetByte;
308 *pointerToTargetByte=STATIC_CAST(TUint8, sourceByte&~0x80);
309 __ASSERT_DEBUG(pointerToSourceByte<=pointerToLastByte, Panic(EPanicBadPointers36));
310 if (pointerToSourceByte>=pointerToLastByte)
314 ++pointerToSourceByte;
315 ++pointerToTargetByte;
317 aDescriptor.SetLength((descriptorLength/3)*2);
324 void ConvertToJisX0208FromEucJpPackedInPlace(TDes8& aDescriptor)
326 const TInt descriptorLength=aDescriptor.Length();
327 __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert4));
328 __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes5));
329 TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr());
330 const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1);
333 const TUint currentByte=*pointerToCurrentByte;
334 __ASSERT_DEBUG(currentByte&0x80, Panic(EPanicBadHighBit4));
335 *pointerToCurrentByte=STATIC_CAST(TUint8, currentByte&~0x80);
336 __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers30));
337 if (pointerToCurrentByte>=pointerToLastByte)
341 ++pointerToCurrentByte;
346 Converts to Half Width Katakana
349 void ConvertToHalfWidthKatakana8FromEucJpPackedInPlace(TDes8& aDescriptor)
351 const TInt descriptorLength=aDescriptor.Length();
352 __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert5));
353 __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes6));
354 TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr());
355 const TUint8* pointerToSourceByte=pointerToTargetByte;
356 const TUint8* const pointerToLastByte=pointerToSourceByte+(descriptorLength-1);
359 __ASSERT_DEBUG(*pointerToSourceByte==KSingleShift2, Panic(EPanicSingleShift2Expected));
360 __ASSERT_DEBUG(pointerToSourceByte<pointerToLastByte, Panic(EPanicBadPointers31));
361 ++pointerToSourceByte;
362 const TUint sourceByte=*pointerToSourceByte;
363 __ASSERT_DEBUG(sourceByte&0x80, Panic(EPanicBadHighBit5));
364 *pointerToTargetByte=STATIC_CAST(TUint8, sourceByte);
365 __ASSERT_DEBUG(pointerToSourceByte<=pointerToLastByte, Panic(EPanicBadPointers32));
366 if (pointerToSourceByte>=pointerToLastByte)
370 ++pointerToSourceByte;
371 ++pointerToTargetByte;
373 aDescriptor.SetLength(descriptorLength/2);