sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * J5 charconv character converter sl@0: * converts from EUC_JP to unicode sl@0: * based on code in EUCJP_PACKED sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "shiftjis.h" sl@0: #include "jisbase.h" sl@0: #include "jisx0201.h" sl@0: #include "jisx0208.h" sl@0: #include "jisx0212.h" sl@0: sl@0: const TUint KSingleShift2=0x8e; sl@0: const TUint KSingleShift3=0x8f; sl@0: sl@0: sl@0: #if defined(_DEBUG) sl@0: sl@0: _LIT(KLitPanicText, "EUCJP_PACKED"); sl@0: sl@0: enum TPanic sl@0: { sl@0: EPanicNothingToConvert1=1, sl@0: EPanicNothingToConvert2, sl@0: EPanicNothingToConvert3, sl@0: EPanicNothingToConvert4, sl@0: EPanicNothingToConvert5, sl@0: EPanicNothingToConvert6, sl@0: EPanicOddNumberOfBytes1, sl@0: EPanicOddNumberOfBytes2, sl@0: EPanicOddNumberOfBytes3, sl@0: EPanicOddNumberOfBytes4, sl@0: EPanicOddNumberOfBytes5, sl@0: EPanicOddNumberOfBytes6, sl@0: EPanicBadHighBit1, sl@0: EPanicBadHighBit2, sl@0: EPanicBadHighBit3, sl@0: EPanicBadHighBit4, sl@0: EPanicBadHighBit5, sl@0: EPanicBadHighBit6, sl@0: EPanicBadHighBit7, sl@0: EPanicBadPointers1, sl@0: EPanicBadPointers2, sl@0: EPanicBadPointers3, sl@0: EPanicBadPointers4, sl@0: EPanicBadPointers5, sl@0: EPanicBadPointers6, sl@0: EPanicBadPointers7, sl@0: EPanicBadPointers8, sl@0: EPanicBadPointers9, sl@0: EPanicBadPointers10, sl@0: EPanicBadPointers11, sl@0: EPanicBadPointers12, sl@0: EPanicBadPointers13, sl@0: EPanicBadPointers14, sl@0: EPanicBadPointers15, sl@0: EPanicBadPointers16, sl@0: EPanicBadPointers17, sl@0: EPanicBadPointers18, sl@0: EPanicBadPointers19, sl@0: EPanicBadPointers20, sl@0: EPanicBadPointers21, sl@0: EPanicBadPointers22, sl@0: EPanicBadPointers23, sl@0: EPanicBadPointers24, sl@0: EPanicBadPointers25, sl@0: EPanicBadPointers26, sl@0: EPanicBadPointers27, sl@0: EPanicBadPointers28, sl@0: EPanicBadPointers29, sl@0: EPanicBadPointers30, sl@0: EPanicBadPointers31, sl@0: EPanicBadPointers32, sl@0: EPanicBadPointers33, sl@0: EPanicBadPointers34, sl@0: EPanicBadPointers35, sl@0: EPanicBadPointers36, sl@0: EPanicBadCalculation1, sl@0: EPanicBadCalculation2, sl@0: EPanicNumberOfBytesIsNotMultipleOfThree1, sl@0: EPanicNumberOfBytesIsNotMultipleOfThree2, sl@0: EPanicSingleShift2Expected, sl@0: EPanicSingleShift3Expected sl@0: }; sl@0: sl@0: LOCAL_C void Panic(TPanic aPanic) sl@0: { sl@0: User::Panic(KLitPanicText, aPanic); sl@0: } sl@0: sl@0: #endif sl@0: sl@0: /** sl@0: @return The number of bytes that can be converted from aDescriptor to JisRoman sl@0: @internalTechnology sl@0: */ sl@0: TInt NumberOfBytesAbleToConvertToJisRoman(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: /** sl@0: @return The number of bytes that can be converted from aDescriptor to Jis X208 sl@0: @internalTechnology sl@0: */ sl@0: TInt NumberOfBytesAbleToConvertToJisX0208(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: /** sl@0: @return The number of bytes that can be converted from aDescriptor to HalfWidthKatakana sl@0: @internalTechnology sl@0: */ sl@0: TInt NumberOfBytesAbleToConvertToHalfWidthKatakana8(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: /** sl@0: @return The number of bytes that can be converted from aDescriptor to JISX0212 sl@0: @internalTechnology sl@0: */ sl@0: TInt NumberOfBytesAbleToConvertToJisX0212(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: void DummyConvertToIntermediateBufferInPlace(TDes8&) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Converts to JISX0212 sl@0: @internalTechnology sl@0: */ sl@0: void ConvertToJisX0212FromEucJpPackedInPlace(TDes8& aDescriptor) sl@0: { sl@0: const TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert6)); sl@0: __ASSERT_DEBUG(descriptorLength%3==0, Panic(EPanicNumberOfBytesIsNotMultipleOfThree2)); sl@0: TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); sl@0: const TUint8* pointerToSourceByte=pointerToTargetByte; sl@0: const TUint8* const pointerToLastByte=pointerToSourceByte+(descriptorLength-1); sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(*pointerToSourceByte==KSingleShift3, Panic(EPanicSingleShift3Expected)); sl@0: __ASSERT_DEBUG(pointerToSourceByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: ++pointerToSourceByte; sl@0: ++pointerToTargetByte; sl@0: } sl@0: aDescriptor.SetLength((descriptorLength/3)*2); sl@0: } sl@0: sl@0: /** sl@0: Converts to JISX0208 sl@0: @internalTechnology sl@0: */ sl@0: void ConvertToJisX0208FromEucJpPackedInPlace(TDes8& aDescriptor) sl@0: { sl@0: const TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert4)); sl@0: __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes5)); sl@0: TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); sl@0: const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1); sl@0: FOREVER sl@0: { sl@0: const TUint currentByte=*pointerToCurrentByte; sl@0: __ASSERT_DEBUG(currentByte&0x80, Panic(EPanicBadHighBit4)); sl@0: *pointerToCurrentByte=STATIC_CAST(TUint8, currentByte&~0x80); sl@0: __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers30)); sl@0: if (pointerToCurrentByte>=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: ++pointerToCurrentByte; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Converts to Half Width Katakana sl@0: @internalTechnology sl@0: */ sl@0: void ConvertToHalfWidthKatakana8FromEucJpPackedInPlace(TDes8& aDescriptor) sl@0: { sl@0: const TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert5)); sl@0: __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes6)); sl@0: TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); sl@0: const TUint8* pointerToSourceByte=pointerToTargetByte; sl@0: const TUint8* const pointerToLastByte=pointerToSourceByte+(descriptorLength-1); sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(*pointerToSourceByte==KSingleShift2, Panic(EPanicSingleShift2Expected)); sl@0: __ASSERT_DEBUG(pointerToSourceByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: ++pointerToSourceByte; sl@0: ++pointerToTargetByte; sl@0: } sl@0: aDescriptor.SetLength(descriptorLength/2); sl@0: } sl@0: sl@0: