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.
19 #include "PictographObserver.h"
20 #include "featmgr/featmgr.h"
24 #include <convutils.h>
27 #include "SHIFTJIS_2.H"
30 //const TUint KSingleByteRangeFirstBlockStart=0x00;
31 const TUint KSingleByteRangeFirstBlockEnd=0x7f;
32 const TUint KSingleByteRangeSecondBlockStart=0xa1;
33 const TUint KSingleByteRangeSecondBlockEnd=0xdf;
34 const TUint KFirstByteRangeFirstBlockStart=0x81;
35 const TUint KFirstByteRangeFirstBlockEnd=0x9f;
36 const TUint KFirstByteRangeFirstBlockLength=(KFirstByteRangeFirstBlockEnd+1)-KFirstByteRangeFirstBlockStart;
37 const TUint KFirstByteRangeSecondBlockStart=0xe0;
38 // Ken Lunde's book "CJKV Information Processing" (page 176) says this
39 // constant should be 0xef, but no Shift-JIS characters in
40 // \charconv\data\JISX0208.TXT have a first byte greater than 0xea, and
41 // some extensions of Shift-JIS may use the 0xeb-0xef range for the first
42 // byte of their characters (e.g. "MOPERA"), and in order for users of this
43 // DLL to be able to implement these extensions using the
44 // aArrayOfAdditionalXxxxx parameters, this constant therefore needs to
45 // be set as low as possible, i.e. to 0xea
46 const TUint KFirstByteRangeSecondBlockEnd=0xea;
47 const TUint KFirstByteRangeOtherBlockEnd = 0xfc;
49 const TUint KPictoFirstByteStart = 0xF0;
50 const TUint KPictoFirstByteEnd = 0xF9;
52 const TUint KSecondByteRangeFirstBlockStart=0x40;
53 const TUint KSecondByteRangeFirstBlockEnd=0x7e;
54 const TUint KSecondByteRangeFirstBlockLength=(KSecondByteRangeFirstBlockEnd+1)-KSecondByteRangeFirstBlockStart;
55 const TUint KSecondByteRangeSecondBlockStart=0x80;
56 const TUint KSecondByteRangeSecondBlockEnd=0xfc;
58 // SecureID for Brower app
59 const TUint32 KBrowserSecureId = 0x10008D39;
60 // Define for converting from YenSign to BackSlash
61 const TUint KCharacterCodeForYenSign = 0x00A5;
62 const TUint KCharacterCodeForBackSlash = 0x005C;
64 TInt BytesInOtherDoubleByteAreas(const TDesC8& aShiftJis);
65 TInt OneIfNotValid(const TDesC8& aShiftJis);
67 TBool IsJisX0208LeadByte(TUint a)
69 return (KFirstByteRangeFirstBlockStart <= a
70 && a <= KFirstByteRangeFirstBlockEnd)
71 || (KFirstByteRangeSecondBlockStart <= a
72 && a <= KFirstByteRangeSecondBlockEnd);
75 TBool IsValidTrailByte(TUint a)
77 return KSecondByteRangeFirstBlockStart <= a
78 && a <= KSecondByteRangeSecondBlockEnd
79 && a != KSecondByteRangeFirstBlockEnd + 1;
82 TBool IsOtherLeadByte(TUint a)
84 if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) )
86 return ((KFirstByteRangeSecondBlockEnd < a && a <= KFirstByteRangeOtherBlockEnd)
87 && (a < KPictoFirstByteStart || a > KPictoFirstByteEnd));
91 return KFirstByteRangeSecondBlockEnd < a
92 && a <= KFirstByteRangeOtherBlockEnd;
96 _LIT8(KLit8ShiftJisReplacementForUnconvertibleUnicodeCharacters, "\x81\x48"); // fullwidth question mark
100 _LIT(KLitPanicText, "SHIFTJIS_SHARED");
104 EPanicIndexOverflow1=1,
105 EPanicIndexOverflow2,
106 EPanicNothingToConvert1,
107 EPanicNothingToConvert2,
108 EPanicOddNumberOfBytes1,
109 EPanicOddNumberOfBytes2,
121 LOCAL_C void Panic(TPanic aPanic)
123 User::Panic(KLitPanicText, aPanic);
128 // TCombinedArrayOfCharacterSets
130 class TCombinedArrayOfCharacterSets
133 TCombinedArrayOfCharacterSets(const TArray<CnvUtilities::SCharacterSet>* aArrayOfAdditionalCharacterSets);
134 ~TCombinedArrayOfCharacterSets();
135 TArray<CnvUtilities::SCharacterSet> Array() const;
137 static TInt CombinedCount(const CBase* aThis);
138 static const TAny* CombinedAccessor(const CBase* aThis, TInt aIndex);
140 RArray<CnvUtilities::SCharacterSet> iArrayOfCoreCharacterSets;
141 const TArray<CnvUtilities::SCharacterSet>* iArrayOfAdditionalCharacterSets;
144 TCombinedArrayOfCharacterSets::TCombinedArrayOfCharacterSets(const TArray<CnvUtilities::SCharacterSet>* aArrayOfAdditionalCharacterSets)
145 :iArrayOfAdditionalCharacterSets(aArrayOfAdditionalCharacterSets)
147 if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) )
149 CnvUtilities::SCharacterSet characterSet;
150 characterSet.iConversionData=&CnvJisX0201::ConversionData();
151 characterSet.iConvertFromIntermediateBufferInPlace=CnvShiftJis::DummyConvertFromIntermediateBufferInPlace;
152 characterSet.iEscapeSequence=&KNullDesC8;
153 iArrayOfCoreCharacterSets.Append(characterSet);
154 characterSet.iConversionData=&CnvJisX0208::ConversionData();
155 characterSet.iConvertFromIntermediateBufferInPlace=CnvShiftJis::ConvertFromJisX0208ToShiftJisInPlace;
156 characterSet.iEscapeSequence=&KNullDesC8;
157 iArrayOfCoreCharacterSets.Append(characterSet);
159 SetCharacterSetsForPictograph(iArrayOfCoreCharacterSets, ECharsetShiftJis);
163 CnvUtilities::SCharacterSet characterSet;
164 characterSet.iConversionData=&CnvJisX0201::ConversionData();
165 characterSet.iConvertFromIntermediateBufferInPlace=CnvShiftJis::DummyConvertFromIntermediateBufferInPlace;
166 characterSet.iEscapeSequence=&KNullDesC8;
167 iArrayOfCoreCharacterSets.Append(characterSet);
168 characterSet.iConversionData=&CnvJisX0208::ConversionData();
169 characterSet.iConvertFromIntermediateBufferInPlace=CnvShiftJis::ConvertFromJisX0208ToShiftJisInPlace;
170 characterSet.iEscapeSequence=&KNullDesC8;
171 iArrayOfCoreCharacterSets.Append(characterSet);
175 TCombinedArrayOfCharacterSets::~TCombinedArrayOfCharacterSets()
177 iArrayOfCoreCharacterSets.Close();
181 TArray<CnvUtilities::SCharacterSet> TCombinedArrayOfCharacterSets::Array() const
183 return TArray<CnvUtilities::SCharacterSet>(CombinedCount, CombinedAccessor, REINTERPRET_CAST(const CBase*, this));
186 TInt TCombinedArrayOfCharacterSets::CombinedCount(const CBase* aThis)
188 const TCombinedArrayOfCharacterSets& thisReference=*REINTERPRET_CAST(const TCombinedArrayOfCharacterSets*, aThis);
189 const TInt numberOfCoreCharacterSets=thisReference.iArrayOfCoreCharacterSets.Count();
190 if (thisReference.iArrayOfAdditionalCharacterSets!=NULL)
192 return numberOfCoreCharacterSets+thisReference.iArrayOfAdditionalCharacterSets->Count();
194 return numberOfCoreCharacterSets;
197 const TAny* TCombinedArrayOfCharacterSets::CombinedAccessor(const CBase* aThis, TInt aIndex)
199 const TCombinedArrayOfCharacterSets& thisReference=*REINTERPRET_CAST(const TCombinedArrayOfCharacterSets*, aThis);
200 const TInt numberOfCoreCharacterSets=thisReference.iArrayOfCoreCharacterSets.Count();
201 if (aIndex>=numberOfCoreCharacterSets)
203 __ASSERT_DEBUG(thisReference.iArrayOfAdditionalCharacterSets!=NULL, Panic(EPanicIndexOverflow1));
204 return &(*thisReference.iArrayOfAdditionalCharacterSets)[aIndex-numberOfCoreCharacterSets];
206 return &thisReference.iArrayOfCoreCharacterSets[aIndex];
209 // TCombinedArrayOfMethods
211 class TCombinedArrayOfMethods
214 TCombinedArrayOfMethods(const TArray<CnvUtilities::SMethod>* aArrayOfAdditionalMethods);
215 ~TCombinedArrayOfMethods();
216 TArray<CnvUtilities::SMethod> Array() const;
218 static TInt CombinedCount(const CBase* aThis);
219 static const TAny* CombinedAccessor(const CBase* aThis, TInt aIndex);
221 RArray<CnvUtilities::SMethod> iArrayOfCoreMethods;
222 const TArray<CnvUtilities::SMethod>* iArrayOfAdditionalMethods;
225 TCombinedArrayOfMethods::TCombinedArrayOfMethods(const TArray<CnvUtilities::SMethod>* aArrayOfAdditionalMethods)
226 :iArrayOfAdditionalMethods(aArrayOfAdditionalMethods)
228 if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) )
230 SetMethodsForPictograph(iArrayOfCoreMethods, ECharsetShiftJis);
231 CnvUtilities::SMethod method;
232 method.iNumberOfBytesAbleToConvert=CnvShiftJis::NumberOfBytesAbleToConvertToJisX0201;
233 method.iConvertToIntermediateBufferInPlace=CnvShiftJis::DummyConvertToIntermediateBufferInPlace;
234 method.iConversionData=&CnvJisX0201::ConversionData();
235 method.iNumberOfBytesPerCharacter=1;
236 method.iNumberOfCoreBytesPerCharacter=1;
237 iArrayOfCoreMethods.Append(method);
238 method.iNumberOfBytesAbleToConvert=CnvShiftJis::NumberOfBytesAbleToConvertToJisX0208;
239 method.iConvertToIntermediateBufferInPlace=CnvShiftJis::ConvertToJisX0208FromShiftJisInPlace;
240 method.iConversionData=&CnvJisX0208::ConversionData();
241 method.iNumberOfBytesPerCharacter=2;
242 method.iNumberOfCoreBytesPerCharacter=2;
243 iArrayOfCoreMethods.Append(method);
247 CnvUtilities::SMethod method;
248 method.iNumberOfBytesAbleToConvert=CnvShiftJis::NumberOfBytesAbleToConvertToJisX0201;
249 method.iConvertToIntermediateBufferInPlace=CnvShiftJis::DummyConvertToIntermediateBufferInPlace;
250 method.iConversionData=&CnvJisX0201::ConversionData();
251 method.iNumberOfBytesPerCharacter=1;
252 method.iNumberOfCoreBytesPerCharacter=1;
253 iArrayOfCoreMethods.Append(method);
254 method.iNumberOfBytesAbleToConvert=CnvShiftJis::NumberOfBytesAbleToConvertToJisX0208;
255 method.iConvertToIntermediateBufferInPlace=CnvShiftJis::ConvertToJisX0208FromShiftJisInPlace;
256 method.iConversionData=&CnvJisX0208::ConversionData();
257 method.iNumberOfBytesPerCharacter=2;
258 method.iNumberOfCoreBytesPerCharacter=2;
259 iArrayOfCoreMethods.Append(method);
263 TCombinedArrayOfMethods::~TCombinedArrayOfMethods()
265 iArrayOfCoreMethods.Close();
269 TArray<CnvUtilities::SMethod> TCombinedArrayOfMethods::Array() const
271 return TArray<CnvUtilities::SMethod>(CombinedCount, CombinedAccessor, REINTERPRET_CAST(const CBase*, this));
274 TInt TCombinedArrayOfMethods::CombinedCount(const CBase* aThis)
276 const TCombinedArrayOfMethods& thisReference=*REINTERPRET_CAST(const TCombinedArrayOfMethods*, aThis);
277 const TInt numberOfCoreMethods=thisReference.iArrayOfCoreMethods.Count();
278 if (thisReference.iArrayOfAdditionalMethods!=NULL)
280 return numberOfCoreMethods+thisReference.iArrayOfAdditionalMethods->Count();
282 return numberOfCoreMethods;
285 const TAny* TCombinedArrayOfMethods::CombinedAccessor(const CBase* aThis, TInt aIndex)
287 const TCombinedArrayOfMethods& thisReference=*REINTERPRET_CAST(const TCombinedArrayOfMethods*, aThis);
288 const TInt numberOfCoreMethods=thisReference.iArrayOfCoreMethods.Count();
289 if (aIndex>=numberOfCoreMethods)
291 __ASSERT_DEBUG(thisReference.iArrayOfAdditionalMethods!=NULL, Panic(EPanicIndexOverflow2));
292 return &(*thisReference.iArrayOfAdditionalMethods)[aIndex-numberOfCoreMethods];
294 return &thisReference.iArrayOfCoreMethods[aIndex];
299 EXPORT_C const TDesC8& CnvShiftJis::ReplacementForUnconvertibleUnicodeCharacters()
301 return KLit8ShiftJisReplacementForUnconvertibleUnicodeCharacters;
304 EXPORT_C TInt CnvShiftJis::ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
306 return DoConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, NULL);
310 * Converts text from Unicode to Shift-JIS (aArrayOfAdditionalCharacterSets provides support
311 * for Shift-JIS extensions)
313 * @since Internationalization_6.2
315 EXPORT_C TInt CnvShiftJis::ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters, const TArray<CnvUtilities::SCharacterSet>& aArrayOfAdditionalCharacterSets)
317 return DoConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, &aArrayOfAdditionalCharacterSets);
320 EXPORT_C TInt CnvShiftJis::ConvertToUnicode(
321 CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
322 TDes16& aUnicode, const TDesC8& aForeign,
323 TInt& aNumberOfUnconvertibleCharacters,
324 TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
326 // DummyData converts any pair of bytes into FFFD
327 static const SCnvConversionData::SVariableByteData::SRange
328 DummyByteLengths = {0, 255, 1, 0};
329 static const SCnvConversionData::SOneDirectionData::SRange DummyConv =
331 SCnvConversionData::SOneDirectionData::SRange::EDirect, 2, 0 };
332 static const SCnvConversionData DummyData =
334 SCnvConversionData::EFixedBigEndian,
335 {1, &DummyByteLengths},
339 TFixedArray<CnvUtilities::SMethod, 2> nullExtension;
340 // First extension converts unrecognised double byte characters to FFFD
341 nullExtension[0].iNumberOfBytesAbleToConvert
342 = BytesInOtherDoubleByteAreas;
343 nullExtension[0].iConvertToIntermediateBufferInPlace
344 = CnvShiftJis::DummyConvertToIntermediateBufferInPlace;
345 // This conversion data won't do anything for us: it will just get us
346 // a load of FFFD, which is what we want.
347 nullExtension[0].iConversionData = &DummyData;
348 nullExtension[0].iNumberOfBytesPerCharacter = 2;
349 nullExtension[0].iNumberOfCoreBytesPerCharacter = 2;
350 // Second extension converts any other single byte to FFFD,
351 // but only ever one!
352 nullExtension[1].iNumberOfBytesAbleToConvert
354 nullExtension[1].iConvertToIntermediateBufferInPlace
355 = CnvShiftJis::DummyConvertToIntermediateBufferInPlace;
356 // This conversion data won't do anything for us: it will just get us
357 // a load of FFFD, which is what we want.
358 nullExtension[1].iConversionData = &CnvJisX0201::ConversionData();
359 nullExtension[1].iNumberOfBytesPerCharacter = 1;
360 nullExtension[1].iNumberOfCoreBytesPerCharacter = 1;
361 const TArray<CnvUtilities::SMethod> nullExtensionArray = nullExtension.Array();
362 return DoConvertToUnicode(aDefaultEndiannessOfForeignCharacters,
363 aUnicode, aForeign, aNumberOfUnconvertibleCharacters,
364 aIndexOfFirstByteOfFirstUnconvertibleCharacter,
365 &nullExtensionArray);
369 * Converts text from Shift-JIS to Unicode (aArrayOfAdditionalMethods provides support
370 * for Shift-JIS extensions)
372 * @since Internationalization_6.2
374 EXPORT_C TInt CnvShiftJis::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<CnvUtilities::SMethod>& aArrayOfAdditionalMethods)
376 return DoConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, &aArrayOfAdditionalMethods);
379 TInt CnvShiftJis::DoConvertFromUnicode(
380 CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
381 const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
382 TDes8& aForeign, const TDesC16& aUnicode,
383 CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters,
384 const TArray<CnvUtilities::SCharacterSet>* aArrayOfAdditionalCharacterSets)
386 TCombinedArrayOfCharacterSets combinedArrayOfCharacterSets(aArrayOfAdditionalCharacterSets);
387 return CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, combinedArrayOfCharacterSets.Array());
390 TInt CnvShiftJis::DoConvertToUnicode(
391 CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
392 TDes16& aUnicode, const TDesC8& aForeign,
393 TInt& aNumberOfUnconvertibleCharacters,
394 TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter,
395 const TArray<CnvUtilities::SMethod>* aArrayOfAdditionalMethods)
397 TCombinedArrayOfMethods combinedArrayOfMethods(aArrayOfAdditionalMethods);
398 TInt unconvert = CnvUtilities::ConvertToUnicodeFromHeterogeneousForeign(
399 aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign,
400 aNumberOfUnconvertibleCharacters,
401 aIndexOfFirstByteOfFirstUnconvertibleCharacter,
402 combinedArrayOfMethods.Array());
404 // The following is specific impelementation for brower.
405 // If brower app calls this API, the yen sign code(0xA5)
406 // must be converted to backslash code(0x5C).
407 // Becasue Javascript supports backslash code ony.
408 TBool browserProcess = (RProcess().SecureId().iId == KBrowserSecureId);
409 if (browserProcess && aUnicode.Length() > 0)
411 const TUint16* pB = aUnicode.Ptr();
412 const TUint16* pbase = pB;
413 const TUint16* pE = pB + aUnicode.Length() -1;
416 if (*pbase == KCharacterCodeForYenSign)
418 aUnicode[pbase - pB] = KCharacterCodeForBackSlash;
427 void CnvShiftJis::DummyConvertFromIntermediateBufferInPlace(TInt, TDes8&, TInt& aNumberOfCharactersThatDroppedOut)
429 aNumberOfCharactersThatDroppedOut=0;
432 void CnvShiftJis::ConvertFromJisX0208ToShiftJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
434 aNumberOfCharactersThatDroppedOut=0;
435 const TInt descriptorLength=aDescriptor.Length();
436 __ASSERT_DEBUG(descriptorLength>aStartPositionInDescriptor, Panic(EPanicNothingToConvert1));
437 __ASSERT_DEBUG((descriptorLength-aStartPositionInDescriptor)%2==0, Panic(EPanicOddNumberOfBytes1));
438 TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr());
439 const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1);
440 pointerToCurrentByte+=aStartPositionInDescriptor;
443 TUint firstByte=*pointerToCurrentByte-0x21;
444 TUint secondByte=*(pointerToCurrentByte+1)-0x21;
450 if (firstByte<KFirstByteRangeFirstBlockLength)
452 firstByte+=KFirstByteRangeFirstBlockStart;
456 firstByte+=KFirstByteRangeSecondBlockStart-KFirstByteRangeFirstBlockLength;
458 if (secondByte<KSecondByteRangeFirstBlockLength)
460 secondByte+=KSecondByteRangeFirstBlockStart;
464 secondByte+=KSecondByteRangeSecondBlockStart-KSecondByteRangeFirstBlockLength;
466 *pointerToCurrentByte=STATIC_CAST(TUint8, firstByte);
467 ++pointerToCurrentByte;
468 *pointerToCurrentByte=STATIC_CAST(TUint8, secondByte);
469 __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers1));
470 if (pointerToCurrentByte>=pointerToLastByte)
474 ++pointerToCurrentByte;
478 TInt CnvShiftJis::NumberOfBytesAbleToConvertToJisX0201(const TDesC8& aDescriptor)
480 const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
481 const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
482 if (pointerToPreviousByte==pointerToLastByte)
488 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers2));
489 const TUint currentByte=*(pointerToPreviousByte+1);
490 if (((currentByte>KSingleByteRangeFirstBlockEnd) && (currentByte<KSingleByteRangeSecondBlockStart)) ||
491 (currentByte>KSingleByteRangeSecondBlockEnd))
495 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers3));
496 ++pointerToPreviousByte;
497 __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers4));
498 if (pointerToPreviousByte>=pointerToLastByte)
503 return (pointerToPreviousByte+1)-aDescriptor.Ptr();
506 TInt CnvShiftJis::NumberOfBytesAbleToConvertToJisX0208(const TDesC8& aDescriptor)
508 const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
509 const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
510 if (pointerToPreviousByte==pointerToLastByte)
516 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers5));
517 TUint currentByte=*(pointerToPreviousByte+1);
518 if (!IsJisX0208LeadByte(currentByte))
520 if (!IsOtherLeadByte(currentByte))
525 __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers6));
526 if (pointerToPreviousByte+1>=pointerToLastByte)
530 __ASSERT_DEBUG(pointerToPreviousByte+2<=pointerToLastByte, Panic(EPanicBadPointers7));
531 currentByte=*(pointerToPreviousByte+2);
532 if (!IsValidTrailByte(currentByte))
536 pointerToPreviousByte+=2;
537 __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers8));
538 if (pointerToPreviousByte>=pointerToLastByte)
543 return (pointerToPreviousByte+1)-aDescriptor.Ptr();
546 void CnvShiftJis::DummyConvertToIntermediateBufferInPlace(TDes8&)
550 void CnvShiftJis::ConvertToJisX0208FromShiftJisInPlace(TDes8& aDescriptor)
552 const TInt descriptorLength=aDescriptor.Length();
553 __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert2));
554 __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes2));
555 TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr());
556 const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1);
559 TUint firstByte=*pointerToCurrentByte;
560 TUint secondByte=*(pointerToCurrentByte+1);
561 if (firstByte<KFirstByteRangeSecondBlockStart)
563 firstByte-=KFirstByteRangeFirstBlockStart;
567 firstByte-=KFirstByteRangeSecondBlockStart-KFirstByteRangeFirstBlockLength;
569 if (secondByte<KSecondByteRangeSecondBlockStart)
571 secondByte-=KSecondByteRangeFirstBlockStart;
575 secondByte-=KSecondByteRangeSecondBlockStart-KSecondByteRangeFirstBlockLength;
585 *pointerToCurrentByte=STATIC_CAST(TUint8, firstByte);
586 ++pointerToCurrentByte;
587 *pointerToCurrentByte=STATIC_CAST(TUint8, secondByte);
588 __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers9));
589 if (pointerToCurrentByte>=pointerToLastByte)
593 ++pointerToCurrentByte;
597 TInt BytesInOtherDoubleByteAreas(const TDesC8& aShiftJis)
599 const TText8* start = aShiftJis.Ptr();
600 const TText8* end = start + aShiftJis.Length() - 1;
601 const TText8* p = start;
602 while (p < end && IsOtherLeadByte(p[0]) && IsValidTrailByte(p[1]))
607 TInt OneIfNotValid(const TDesC8& aShiftJis)
609 TInt length = aShiftJis.Length();
612 TInt c = aShiftJis[0];
613 // If the next byte is not a lead byte, we can swallow it. The
614 // double-byte methods obviously can't be waiting for more
616 if (!IsOtherLeadByte(c) && !IsJisX0208LeadByte(c))
618 // Otherwise we have a lead byte. If it is on its own we cannot
619 // swallow it as the double-byte converters will be waiting for
620 // more information. If they have the information (i.e. if length > 1)
621 // then they have passed on it and we can swallow it.
622 return length == 1? 0 : 1;