charconvfw/charconv_fw/src/charconv/charconv.cpp
branchRCL_3
changeset 54 748ec5531811
parent 0 1fb32624e06b
child 55 336bee5c2d35
equal deleted inserted replaced
36:f902e87c146f 54:748ec5531811
    24 #include <utf.h>
    24 #include <utf.h>
    25 #include <ecom/ecom.h>
    25 #include <ecom/ecom.h>
    26 #include <charactersetconverter.h>
    26 #include <charactersetconverter.h>
    27 #include "chcnvpanic.h"
    27 #include "chcnvpanic.h"
    28 #include "charconv_tls.h"
    28 #include "charconv_tls.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "charconvTraces.h"
       
    32 #endif
       
    33 
    29 
    34 
    30 #if defined(_DEBUG)
    35 #if defined(_DEBUG)
    31 #define NON_DEBUG_INLINE
    36 #define NON_DEBUG_INLINE
    32 #else
    37 #else
    33 #define NON_DEBUG_INLINE inline
    38 #define NON_DEBUG_INLINE inline
   127 		case KCharacterSetIdentifierUnicodeBig:
   132 		case KCharacterSetIdentifierUnicodeBig:
   128 			IsCharacterSetUnicodeBig(aConfidenceLevel,aSample);
   133 			IsCharacterSetUnicodeBig(aConfidenceLevel,aSample);
   129 			break;
   134 			break;
   130 #if defined(_DEBUG)
   135 #if defined(_DEBUG)
   131 		default:
   136 		default:
       
   137 		    OstTraceExt3( TRACE_DUMP, _ISBUILTINCHARACTERSET, "::IsBuiltInCharacterSet;aCharacterSetIdentifier=%u;aConfidenceLevel=%d;aSample=%x", aCharacterSetIdentifier, aConfidenceLevel, ( TUint )&( aSample ) );	    
   132 			Panic(EPanicCharacterSetNotPresent);
   138 			Panic(EPanicCharacterSetNotPresent);
   133 			break;
   139 			break;
   134 #endif
   140 #endif
   135 		}
   141 		}
   136     }
   142     }
   155 void TTlsData::CharacterSetConverterIsBeingDestroyed()
   161 void TTlsData::CharacterSetConverterIsBeingDestroyed()
   156 	{
   162 	{
   157 	TTlsData* tlsData=STATIC_CAST(TTlsData*, Dll::Tls());
   163 	TTlsData* tlsData=STATIC_CAST(TTlsData*, Dll::Tls());
   158 	if (tlsData!=NULL)
   164 	if (tlsData!=NULL)
   159 		{
   165 		{
       
   166 		if ( tlsData->iCurrentCharacterSetConverter!=NULL )
       
   167 		    {
       
   168 		    OstTrace0( TRACE_DUMP, TTLSDATA_CHARACTERSETCONVERTERISBEINGDESTROYED, "EPanicDestructionDuringConversion" );	    
       
   169 		    }
   160 		__ASSERT_DEBUG(tlsData->iCurrentCharacterSetConverter==NULL, Panic(EPanicDestructionDuringConversion));
   170 		__ASSERT_DEBUG(tlsData->iCurrentCharacterSetConverter==NULL, Panic(EPanicDestructionDuringConversion));
   161 		--tlsData->iReferenceCount;
   171 		--tlsData->iReferenceCount;
       
   172 		if ( tlsData->iReferenceCount < 0 )
       
   173 		    {
       
   174 		    OstTrace0( TRACE_DUMP, DUP1_TTLSDATA_CHARACTERSETCONVERTERISBEINGDESTROYED, "EPanicBadTlsDataReferenceCount" );
       
   175 		    }
   162 		__ASSERT_DEBUG(tlsData->iReferenceCount>=0, Panic(EPanicBadTlsDataReferenceCount));
   176 		__ASSERT_DEBUG(tlsData->iReferenceCount>=0, Panic(EPanicBadTlsDataReferenceCount));
   163 		if (tlsData->iReferenceCount<=0)
   177 		if (tlsData->iReferenceCount<=0)
   164 			{
   178 			{
   165 			delete tlsData;
   179 			delete tlsData;
   166 			Dll::FreeTls();
   180 			Dll::FreeTls();
   169 	}
   183 	}
   170 
   184 
   171 void TTlsData::SetCurrentCharacterSetConverter(const CCnvCharacterSetConverter* aCharacterSetConverter)
   185 void TTlsData::SetCurrentCharacterSetConverter(const CCnvCharacterSetConverter* aCharacterSetConverter)
   172 	{
   186 	{
   173 	TTlsData* tlsData=STATIC_CAST(TTlsData*, Dll::Tls());
   187 	TTlsData* tlsData=STATIC_CAST(TTlsData*, Dll::Tls());
       
   188 	if ( tlsData==NULL )
       
   189 	    {
       
   190 	    OstTrace0( TRACE_FATAL, DUP1_TTLSDATA_SETCURRENTCHARACTERSETCONVERTER, "No Tls Data in TTlsData::SetCurrentCharacterSetConverter" );
       
   191 	    }
   174 	__ASSERT_ALWAYS(tlsData!=NULL, Panic(EPanicNoTlsData));
   192 	__ASSERT_ALWAYS(tlsData!=NULL, Panic(EPanicNoTlsData));
       
   193     if ( (tlsData->iCurrentCharacterSetConverter==NULL)==(aCharacterSetConverter==NULL) )
       
   194         {
       
   195         OstTrace0( TRACE_FATAL, TTLSDATA_SETCURRENTCHARACTERSETCONVERTER, "Bad Toggle of current characater set converter in TTlsData::SetCurrentCharacterSetConverter" );  
       
   196         }
   175 	__ASSERT_ALWAYS((tlsData->iCurrentCharacterSetConverter==NULL)!=(aCharacterSetConverter==NULL), Panic(EPanicBadToggleOfCurrentCharacterSetConverter));
   197 	__ASSERT_ALWAYS((tlsData->iCurrentCharacterSetConverter==NULL)!=(aCharacterSetConverter==NULL), Panic(EPanicBadToggleOfCurrentCharacterSetConverter));
   176 	tlsData->iCurrentCharacterSetConverter=aCharacterSetConverter;
   198 	tlsData->iCurrentCharacterSetConverter=aCharacterSetConverter;
   177 	}
   199 	}
   178 
   200 
   179 EXPORT_C const CCnvCharacterSetConverter* TTlsData::CurrentCharacterSetConverter()
   201 EXPORT_C const CCnvCharacterSetConverter* TTlsData::CurrentCharacterSetConverter()
   229 	TInt ReadPositiveIntegerCompacted30L();
   251 	TInt ReadPositiveIntegerCompacted30L();
   230 	TInt ReadSignedIntegerCompacted29L();
   252 	TInt ReadSignedIntegerCompacted29L();
   231 	void ReadBufferL(TDes8& aBuffer, TInt aBufferLength);
   253 	void ReadBufferL(TDes8& aBuffer, TInt aBufferLength);
   232 	HBufC8* ReadBufferL(TInt aBufferLength);
   254 	HBufC8* ReadBufferL(TInt aBufferLength);
   233 	HBufC8* ReadBufferLC(TInt aBufferLength);
   255 	HBufC8* ReadBufferLC(TInt aBufferLength);
   234 	inline TBool IsEndOfFile() const {__ASSERT_DEBUG(iNextByteToConsume<=iOnePastEndOfBuffer, Panic(EPanicPastEndOfFile)); return iNextByteToConsume>=iOnePastEndOfBuffer;}
   256 	inline TBool IsEndOfFile() const {if ( iNextByteToConsume>iOnePastEndOfBuffer ) {OstTrace0( TRACE_DUMP, _NONSHARABLE_CLASS, "EPanicPastEndOfFile" );}__ASSERT_DEBUG(iNextByteToConsume<=iOnePastEndOfBuffer, Panic(EPanicPastEndOfFile)); return iNextByteToConsume>=iOnePastEndOfBuffer;}
   235 private:
   257 private:
   236 	enum {ENumberOfBytesToConsumeBetweenEachReAllocation=1000};
   258 	enum {ENumberOfBytesToConsumeBetweenEachReAllocation=1000};
   237 private:
   259 private:
   238 	CFileReader();
   260 	CFileReader();
   239 	CFileReader(const TUint8* aRomFile, TInt aLengthOfRomFile);
   261 	CFileReader(const TUint8* aRomFile, TInt aLengthOfRomFile);
   251 	const TUint8* iFlagPoleForReAllocation;
   273 	const TUint8* iFlagPoleForReAllocation;
   252 	};
   274 	};
   253 
   275 
   254 void CFileReader::ReAllocateTheBuffer() // put this function first so that the compiler does actually inline it for non-DEBUG builds
   276 void CFileReader::ReAllocateTheBuffer() // put this function first so that the compiler does actually inline it for non-DEBUG builds
   255 	{
   277 	{
       
   278 	if ( (iBuffer==NULL) || (iNextByteToConsume<iFlagPoleForReAllocation ) )
       
   279 	    {
       
   280 	    OstTrace0( TRACE_DUMP, CFILEREADER_REALLOCATETHEBUFFER, "EPanicNotPastFlagPoleForReAllocation" );
       
   281 	    }
       
   282 	
   256 	__ASSERT_DEBUG((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation), Panic(EPanicNotPastFlagPoleForReAllocation));
   283 	__ASSERT_DEBUG((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation), Panic(EPanicNotPastFlagPoleForReAllocation));
   257 	const TInt lengthOfBuffer=iOnePastEndOfBuffer-iNextByteToConsume;
   284 	const TInt lengthOfBuffer=iOnePastEndOfBuffer-iNextByteToConsume;
   258 	Mem::Copy(STATIC_CAST(TAny*, iBuffer), iNextByteToConsume, lengthOfBuffer);
   285 	Mem::Copy(STATIC_CAST(TAny*, iBuffer), iNextByteToConsume, lengthOfBuffer);
   259 #if defined(_DEBUG)
       
   260 	const TAny* reAllocatedCell=
   286 	const TAny* reAllocatedCell=
   261 #endif
   287 	        User::ReAlloc(STATIC_CAST(TAny*, iBuffer), lengthOfBuffer);
   262 	User::ReAlloc(STATIC_CAST(TAny*, iBuffer), lengthOfBuffer);
   288 	if ( reAllocatedCell!=iBuffer )
       
   289 	    {
       
   290 	    OstTrace0( TRACE_DUMP, DUP1_CFILEREADER_REALLOCATETHEBUFFER, "EPanicReAllocatedCellMoved" );
       
   291 	    }
   263 	__ASSERT_DEBUG(reAllocatedCell==iBuffer, Panic(EPanicReAllocatedCellMoved));
   292 	__ASSERT_DEBUG(reAllocatedCell==iBuffer, Panic(EPanicReAllocatedCellMoved));
   264 	iNextByteToConsume=iBuffer;
   293 	iNextByteToConsume=iBuffer;
   265 	iOnePastEndOfBuffer=iBuffer+lengthOfBuffer;
   294 	iOnePastEndOfBuffer=iBuffer+lengthOfBuffer;
   266 	// iFlagPoleForReAllocation can stay as it is
   295 	// iFlagPoleForReAllocation can stay as it is
   267 	}
   296 	}
   286 	User::Free(iBuffer);
   315 	User::Free(iBuffer);
   287 	}
   316 	}
   288 
   317 
   289 void CFileReader::SkipL(TInt aNumberOfBytes)
   318 void CFileReader::SkipL(TInt aNumberOfBytes)
   290 	{
   319 	{
       
   320 	if ( aNumberOfBytes<0 )
       
   321 	    {
       
   322 	    OstTrace0( TRACE_DUMP, CFILEREADER_SKIPL, "EPanicNegativeNumberOfBytes" );
       
   323 	    }
   291 	__ASSERT_DEBUG(aNumberOfBytes>=0, Panic(EPanicNegativeNumberOfBytes));
   324 	__ASSERT_DEBUG(aNumberOfBytes>=0, Panic(EPanicNegativeNumberOfBytes));
   292 	CheckPointers(EPanicInconsistentFileReader1);
   325 	CheckPointers(EPanicInconsistentFileReader1);
   293 	const TUint8* newNextByteToConsume=iNextByteToConsume+aNumberOfBytes;
   326 	const TUint8* newNextByteToConsume=iNextByteToConsume+aNumberOfBytes;
   294 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   327 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   295 		{
   328 		{
       
   329 		OstTrace0( TRACE_FATAL, DUP2_CFILEREADER_SKIPL, "KErrCorrupt" );
   296 		User::Leave(KErrCorrupt);
   330 		User::Leave(KErrCorrupt);
   297 		}
   331 		}
   298 	iNextByteToConsume=newNextByteToConsume;
   332 	iNextByteToConsume=newNextByteToConsume;
   299 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   333 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   300 		{
   334 		{
   325 	{
   359 	{
   326 	CheckPointers(EPanicInconsistentFileReader5);
   360 	CheckPointers(EPanicInconsistentFileReader5);
   327 	const TUint8* newNextByteToConsume=iNextByteToConsume+sizeof(TUint16);
   361 	const TUint8* newNextByteToConsume=iNextByteToConsume+sizeof(TUint16);
   328 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   362 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   329 		{
   363 		{
       
   364 		OstTrace0( TRACE_FATAL, CFILEREADER_READUINT16L, "KErrCorrupt" );
   330 		User::Leave(KErrCorrupt);
   365 		User::Leave(KErrCorrupt);
   331 		}
   366 		}
   332 	const TInt integer=(*iNextByteToConsume|(*(iNextByteToConsume+1)<<8));
   367 	const TInt integer=(*iNextByteToConsume|(*(iNextByteToConsume+1)<<8));
   333 	iNextByteToConsume=newNextByteToConsume;
   368 	iNextByteToConsume=newNextByteToConsume;
   334 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   369 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   391 	{
   426 	{
   392 	CheckPointers(EPanicInconsistentFileReader11);
   427 	CheckPointers(EPanicInconsistentFileReader11);
   393 	const TUint8* bytePointer=iNextByteToConsume;
   428 	const TUint8* bytePointer=iNextByteToConsume;
   394 	if (bytePointer>=iOnePastEndOfBuffer)
   429 	if (bytePointer>=iOnePastEndOfBuffer)
   395 		{
   430 		{
       
   431 		OstTrace0( TRACE_FATAL, CFILEREADER_READPOSITIVEINTEGERCOMPACTED30L, "KErrCorrupt" );
   396 		User::Leave(KErrCorrupt);
   432 		User::Leave(KErrCorrupt);
   397 		}
   433 		}
   398 	TInt integer=*bytePointer;
   434 	TInt integer=*bytePointer;
   399 	if (integer&0x00000080)
   435 	if (integer&0x00000080)
   400 		{
   436 		{
   401 		integer&=~0x00000080;
   437 		integer&=~0x00000080;
   402 		++bytePointer;
   438 		++bytePointer;
   403 		if (bytePointer>=iOnePastEndOfBuffer)
   439 		if (bytePointer>=iOnePastEndOfBuffer)
   404 			{
   440 			{
       
   441 			OstTrace0( TRACE_FATAL, DUP1_CFILEREADER_READPOSITIVEINTEGERCOMPACTED30L, "KErrCorrupt" );
   405 			User::Leave(KErrCorrupt);
   442 			User::Leave(KErrCorrupt);
   406 			}
   443 			}
   407 		integer<<=8;
   444 		integer<<=8;
   408 		integer|=*bytePointer;
   445 		integer|=*bytePointer;
   409 		if (integer&0x00004000)
   446 		if (integer&0x00004000)
   410 			{
   447 			{
   411 			integer&=~0x00004000;
   448 			integer&=~0x00004000;
   412 			if (bytePointer+2>=iOnePastEndOfBuffer)
   449 			if (bytePointer+2>=iOnePastEndOfBuffer)
   413 				{
   450 				{
       
   451 				OstTrace0( TRACE_FATAL, DUP2_CFILEREADER_READPOSITIVEINTEGERCOMPACTED30L, "KErrCorrupt" );
   414 				User::Leave(KErrCorrupt);
   452 				User::Leave(KErrCorrupt);
   415 				}
   453 				}
   416 			++bytePointer;
   454 			++bytePointer;
   417 			integer<<=8;
   455 			integer<<=8;
   418 			integer|=*bytePointer;
   456 			integer|=*bytePointer;
   435 	{
   473 	{
   436 	CheckPointers(EPanicInconsistentFileReader13);
   474 	CheckPointers(EPanicInconsistentFileReader13);
   437 	const TUint8* bytePointer=iNextByteToConsume;
   475 	const TUint8* bytePointer=iNextByteToConsume;
   438 	if (bytePointer>=iOnePastEndOfBuffer)
   476 	if (bytePointer>=iOnePastEndOfBuffer)
   439 		{
   477 		{
       
   478 		OstTrace0( TRACE_FATAL, CFILEREADER_READSIGNEDINTEGERCOMPACTED29L, "KErrCorrupt" );
   440 		User::Leave(KErrCorrupt);
   479 		User::Leave(KErrCorrupt);
   441 		}
   480 		}
   442 	TInt integer=*bytePointer;
   481 	TInt integer=*bytePointer;
   443 	const TBool isNegative=(integer&0x00000080);
   482 	const TBool isNegative=(integer&0x00000080);
   444 	integer&=~0x00000080;
   483 	integer&=~0x00000080;
   446 		{
   485 		{
   447 		integer&=~0x00000040;
   486 		integer&=~0x00000040;
   448 		++bytePointer;
   487 		++bytePointer;
   449 		if (bytePointer>=iOnePastEndOfBuffer)
   488 		if (bytePointer>=iOnePastEndOfBuffer)
   450 			{
   489 			{
       
   490 			OstTrace0( TRACE_FATAL, DUP1_CFILEREADER_READSIGNEDINTEGERCOMPACTED29L, "KErrCorrupt" );
   451 			User::Leave(KErrCorrupt);
   491 			User::Leave(KErrCorrupt);
   452 			}
   492 			}
   453 		integer<<=8;
   493 		integer<<=8;
   454 		integer|=*bytePointer;
   494 		integer|=*bytePointer;
   455 		if (integer&0x00002000)
   495 		if (integer&0x00002000)
   456 			{
   496 			{
   457 			integer&=~0x00002000;
   497 			integer&=~0x00002000;
   458 			if (bytePointer+2>=iOnePastEndOfBuffer)
   498 			if (bytePointer+2>=iOnePastEndOfBuffer)
   459 				{
   499 				{
       
   500 				OstTrace0( TRACE_FATAL, DUP2_CFILEREADER_READSIGNEDINTEGERCOMPACTED29L, "KErrCorrupt" );
   460 				User::Leave(KErrCorrupt);
   501 				User::Leave(KErrCorrupt);
   461 				}
   502 				}
   462 			++bytePointer;
   503 			++bytePointer;
   463 			integer<<=8;
   504 			integer<<=8;
   464 			integer|=*bytePointer;
   505 			integer|=*bytePointer;
   481 	return isNegative? -integer: integer;
   522 	return isNegative? -integer: integer;
   482 	}
   523 	}
   483 
   524 
   484 void CFileReader::ReadBufferL(TDes8& aBuffer, TInt aBufferLength)
   525 void CFileReader::ReadBufferL(TDes8& aBuffer, TInt aBufferLength)
   485 	{
   526 	{
       
   527 	if ( aBufferLength<0 )
       
   528 	    {
       
   529 	    OstTrace0( TRACE_DUMP, CFILEREADER_READBUFFERL, "EPanicNegativeBufferLength1" );
       
   530 	    }
   486 	__ASSERT_DEBUG(aBufferLength>=0, Panic(EPanicNegativeBufferLength1));
   531 	__ASSERT_DEBUG(aBufferLength>=0, Panic(EPanicNegativeBufferLength1));
   487 	CheckPointers(EPanicInconsistentFileReader15);
   532 	CheckPointers(EPanicInconsistentFileReader15);
   488 	const TUint8* newNextByteToConsume=iNextByteToConsume+aBufferLength;
   533 	const TUint8* newNextByteToConsume=iNextByteToConsume+aBufferLength;
   489 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   534 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   490 		{
   535 		{
       
   536 		OstTrace0( TRACE_FATAL, DUP1_CFILEREADER_READBUFFERL, "KErrCorrupt" );
   491 		User::Leave(KErrCorrupt);
   537 		User::Leave(KErrCorrupt);
   492 		}
   538 		}
   493 	aBuffer=TPtrC8(iNextByteToConsume, aBufferLength);
   539 	aBuffer=TPtrC8(iNextByteToConsume, aBufferLength);
   494 	iNextByteToConsume=newNextByteToConsume;
   540 	iNextByteToConsume=newNextByteToConsume;
   495 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   541 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   499 	CheckPointers(EPanicInconsistentFileReader16);
   545 	CheckPointers(EPanicInconsistentFileReader16);
   500 	}
   546 	}
   501 
   547 
   502 HBufC8* CFileReader::ReadBufferL(TInt aBufferLength)
   548 HBufC8* CFileReader::ReadBufferL(TInt aBufferLength)
   503 	{
   549 	{
       
   550 	if ( aBufferLength<0 )
       
   551 	    {
       
   552 	    OstTrace0( TRACE_DUMP, DUP2_CFILEREADER_READBUFFERL, "EPanicNegativeBufferLength2" );
       
   553 	    }
   504 	__ASSERT_DEBUG(aBufferLength>=0, Panic(EPanicNegativeBufferLength2));
   554 	__ASSERT_DEBUG(aBufferLength>=0, Panic(EPanicNegativeBufferLength2));
   505 	CheckPointers(EPanicInconsistentFileReader17);
   555 	CheckPointers(EPanicInconsistentFileReader17);
   506 	const TUint8* newNextByteToConsume=iNextByteToConsume+aBufferLength;
   556 	const TUint8* newNextByteToConsume=iNextByteToConsume+aBufferLength;
   507 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   557 	if (newNextByteToConsume>iOnePastEndOfBuffer)
   508 		{
   558 		{
       
   559 		OstTrace0( TRACE_FATAL, DUP3_CFILEREADER_READBUFFERL, "KErrCorrupt" );
   509 		User::Leave(KErrCorrupt);
   560 		User::Leave(KErrCorrupt);
   510 		}
   561 		}
   511 	HBufC8* buffer=TPtrC8(iNextByteToConsume, aBufferLength).AllocL();
   562 	HBufC8* buffer=TPtrC8(iNextByteToConsume, aBufferLength).AllocL();
   512 	iNextByteToConsume=newNextByteToConsume;
   563 	iNextByteToConsume=newNextByteToConsume;
   513 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   564 	if ((iBuffer!=NULL) && (iNextByteToConsume>=iFlagPoleForReAllocation))
   542 	}
   593 	}
   543 
   594 
   544 void CFileReader::ConstructForNonRomFileL(RFile& aFile)
   595 void CFileReader::ConstructForNonRomFileL(RFile& aFile)
   545 	{
   596 	{
   546 	TInt lengthOfBuffer;
   597 	TInt lengthOfBuffer;
       
   598 	if ( aFile.Size(lengthOfBuffer) < 0 )
       
   599 	    {
       
   600 	    OstTrace0( TRACE_FATAL, DUP1_CFILEREADER_CONSTRUCTFORNONROMFILEL, "aFile.Size(lengthOfBuffer) < 0" );
       
   601 	    }
   547 	User::LeaveIfError(aFile.Size(lengthOfBuffer));
   602 	User::LeaveIfError(aFile.Size(lengthOfBuffer));
   548 	iBuffer=STATIC_CAST(TUint8*, User::AllocL(lengthOfBuffer+1));
   603 	iBuffer=STATIC_CAST(TUint8*, User::AllocL(lengthOfBuffer+1));
   549 	TPtr8 buffer(iBuffer, 0, lengthOfBuffer);
   604 	TPtr8 buffer(iBuffer, 0, lengthOfBuffer);
   550 	User::LeaveIfError(aFile.Read(buffer));
   605 	User::LeaveIfError(aFile.Read(buffer));
   551 	if ((buffer.Length()!=lengthOfBuffer) || (lengthOfBuffer<=0))
   606 	if ((buffer.Length()!=lengthOfBuffer) || (lengthOfBuffer<=0))
   552 		{
   607 		{
       
   608 		OstTrace0( TRACE_FATAL, CFILEREADER_CONSTRUCTFORNONROMFILEL, "KErrCorrupt" );
   553 		User::Leave(KErrCorrupt);
   609 		User::Leave(KErrCorrupt);
   554 		}
   610 		}
   555 	iNextByteToConsume=iBuffer;
   611 	iNextByteToConsume=iBuffer;
   556 	iOnePastEndOfBuffer=iBuffer+lengthOfBuffer;
   612 	iOnePastEndOfBuffer=iBuffer+lengthOfBuffer;
   557 	iFlagPoleForReAllocation=iBuffer+ENumberOfBytesToConsumeBetweenEachReAllocation;
   613 	iFlagPoleForReAllocation=iBuffer+ENumberOfBytesToConsumeBetweenEachReAllocation;
   844 		delete entry->iCharsetCnv;
   900 		delete entry->iCharsetCnv;
   845 		delete entry;
   901 		delete entry;
   846 		--iCacheSize;
   902 		--iCacheSize;
   847 		}
   903 		}
   848 	//If iCacheSize is not 0, then there is something wrong with adding/removing cache entry functionality
   904 	//If iCacheSize is not 0, then there is something wrong with adding/removing cache entry functionality
       
   905 	if ( iCacheSize != 0)
       
   906 	    {
       
   907 	    OstTrace0( TRACE_DUMP, CCHARSETCNVCACHE_CCHARSETCNVCACHE, "iCacheSize not zero in CCharsetCnvCache::~CCharsetCnvCache" );
       
   908 	    }
   849 	__ASSERT_DEBUG(iCacheSize == 0, User::Invariant());
   909 	__ASSERT_DEBUG(iCacheSize == 0, User::Invariant());
   850 	}
   910 	}
   851 
   911 
   852 /**
   912 /**
   853 The method searches the cache for a character set converter, which implementation UID matches 
   913 The method searches the cache for a character set converter, which implementation UID matches 
   882 			{
   942 			{
   883 			RemoveLast();
   943 			RemoveLast();
   884 			--iCacheSize;
   944 			--iCacheSize;
   885 			}
   945 			}
   886 		}
   946 		}
       
   947 	if ( !entry )
       
   948 	    {
       
   949 	    OstTrace0( TRACE_FATAL, CCHARSETCNVCACHE_GETCONVERTERL, "entry NULL in CCharsetCnvCache::GetConverterL" );   
       
   950 	    }
   887 	__ASSERT_ALWAYS(entry, User::Invariant());
   951 	__ASSERT_ALWAYS(entry, User::Invariant());
   888 	return entry->iCharsetCnv;
   952 	return entry->iCharsetCnv;
   889 	}
   953 	}
   890 
   954 
   891 /**
   955 /**
   898 											implementation UID is equal to aImplUid.
   962 											implementation UID is equal to aImplUid.
   899 */
   963 */
   900 CCharacterSetConverterPluginInterface* CCharsetCnvCache::Converter(TUid aImplUid)
   964 CCharacterSetConverterPluginInterface* CCharsetCnvCache::Converter(TUid aImplUid)
   901 	{
   965 	{
   902 	TCharsetCnvEntry* entry = Find(aImplUid);
   966 	TCharsetCnvEntry* entry = Find(aImplUid);
       
   967 	if ( entry == NULL || entry->iCharsetCnv == NULL )
       
   968 	    {
       
   969 	    OstTrace0( TRACE_FATAL, CCHARSETCNVCACHE_CONVERTER, "entry or entry->iCharsetCnv NULL in CCharsetCnvCache::Converter" );
       
   970 	    }
   903 	__ASSERT_ALWAYS(entry != NULL && entry->iCharsetCnv != NULL, Panic(EPanicCharacterSetConverterNotLoaded));
   971 	__ASSERT_ALWAYS(entry != NULL && entry->iCharsetCnv != NULL, Panic(EPanicCharacterSetConverterNotLoaded));
   904 	iCache.Remove(*entry);
   972 	iCache.Remove(*entry);
   905 	iCache.AddFirst(*entry);
   973 	iCache.AddFirst(*entry);
   906 	return entry->iCharsetCnv;	
   974 	return entry->iCharsetCnv;	
   907 	}
   975 	}
   916 @see KDefaultMaxCacheSize
   984 @see KDefaultMaxCacheSize
   917 @see KMinCacheSize
   985 @see KMinCacheSize
   918 */
   986 */
   919 void CCharsetCnvCache::SetMaxSize(TInt aSize)
   987 void CCharsetCnvCache::SetMaxSize(TInt aSize)
   920 	{
   988 	{
       
   989 	if ( aSize < KMinCacheSize )
       
   990 	    {
       
   991 	    OstTrace0( TRACE_FATAL, CCHARSETCNVCACHE_SETMAXSIZE, "aSize < KMinCacheSize in CCharsetCnvCache::SetMaxSize" );
       
   992 	    }
   921 	__ASSERT_ALWAYS(aSize >= KMinCacheSize, User::Invariant());
   993 	__ASSERT_ALWAYS(aSize >= KMinCacheSize, User::Invariant());
   922 	//Remove and destroy the last cache entries, if iCacheSize > aSize.
   994 	//Remove and destroy the last cache entries, if iCacheSize > aSize.
   923 	for(;iCacheSize>aSize;--iCacheSize)
   995 	for(;iCacheSize>aSize;--iCacheSize)
   924 		{
   996 		{
   925 		RemoveLast();
   997 		RemoveLast();
   980 @panic User::Invariant() If the last cache entry is NULL.
  1052 @panic User::Invariant() If the last cache entry is NULL.
   981 */
  1053 */
   982 void CCharsetCnvCache::RemoveLast()
  1054 void CCharsetCnvCache::RemoveLast()
   983 	{
  1055 	{
   984 	TCharsetCnvEntry* lastEntry = iCache.Last();
  1056 	TCharsetCnvEntry* lastEntry = iCache.Last();
       
  1057 	if ( !lastEntry )
       
  1058 	    {
       
  1059 	    OstTrace0( TRACE_FATAL, CCHARSETCNVCACHE_REMOVELAST, "lastEntry NULL in CCharsetCnvCache::RemoveLast" );
       
  1060 	    }
   985 	__ASSERT_ALWAYS(lastEntry, User::Invariant());
  1061 	__ASSERT_ALWAYS(lastEntry, User::Invariant());
   986 	iCache.Remove(*lastEntry);
  1062 	iCache.Remove(*lastEntry);
   987 	delete lastEntry->iCharsetCnv;
  1063 	delete lastEntry->iCharsetCnv;
   988 	delete lastEntry;
  1064 	delete lastEntry;
   989 	}
  1065 	}
  1309 	const TAvailability availability=DoPrepareToConvertToOrFromL(aCharacterSetIdentifier, 
  1385 	const TAvailability availability=DoPrepareToConvertToOrFromL(aCharacterSetIdentifier, 
  1310 																 &aArrayOfCharacterSetsAvailable, 
  1386 																 &aArrayOfCharacterSetsAvailable, 
  1311 																 aFileServerSession);
  1387 																 aFileServerSession);
  1312 	if (availability!=EAvailable)
  1388 	if (availability!=EAvailable)
  1313 		{
  1389 		{
       
  1390 		OstTrace0( TRACE_FATAL, CCNVCHARACTERSETCONVERTER_PREPARETOCONVERTTOORFROML, "Conversion Not found in CCnvCharacterSetConverter::PrepareToConvertToOrFromL" );
  1314 		User::Leave(KErrNotFound);
  1391 		User::Leave(KErrNotFound);
  1315 		}
  1392 		}
  1316 	}
  1393 	}
  1317 
  1394 
  1318 /** Specifies the character set to convert to or from. aCharacterSetIdentifier 
  1395 /** Specifies the character set to convert to or from. aCharacterSetIdentifier 
  1325 Either this function or its overload must be called before using the conversion 
  1402 Either this function or its overload must be called before using the conversion 
  1326 functions ConvertFromUnicode() or ConvertToUnicode().
  1403 functions ConvertFromUnicode() or ConvertToUnicode().
  1327 
  1404 
  1328 This overload of the function is simpler to use than the other and does not 
  1405 This overload of the function is simpler to use than the other and does not 
  1329 panic if the character set with the specified UID is not available at run 
  1406 panic if the character set with the specified UID is not available at run 
  1330 timeÂ, it simply returns ENotAvailable. It should be used when the conversion 
  1407 timeÂ, it simply returns ENotAvailable. It should be used when the conversion 
  1331 character set is specified within the text object being converted, e.g. an 
  1408 character set is specified within the text object being converted, e.g. an 
  1332 email message, or an HTML document. If the character set is not specified, 
  1409 email message, or an HTML document. If the character set is not specified, 
  1333 the user must be presented with a list of all available sets, so it makes 
  1410 the user must be presented with a list of all available sets, so it makes 
  1334 sense to use the other overload.
  1411 sense to use the other overload.
  1335 
  1412 
  1381 @param aEndianness The default endian-ness of the current character set. */
  1458 @param aEndianness The default endian-ness of the current character set. */
  1382 EXPORT_C void 
  1459 EXPORT_C void 
  1383 CCnvCharacterSetConverter::SetDefaultEndiannessOfForeignCharacters(
  1460 CCnvCharacterSetConverter::SetDefaultEndiannessOfForeignCharacters(
  1384 											TEndianness aDefaultEndiannessOfForeignCharacters)
  1461 											TEndianness aDefaultEndiannessOfForeignCharacters)
  1385     {
  1462     {
       
  1463     if ( (aDefaultEndiannessOfForeignCharacters!=ELittleEndian) && (aDefaultEndiannessOfForeignCharacters!=EBigEndian) )
       
  1464         {
       
  1465         OstTrace0( TRACE_FATAL, CCNVCHARACTERSETCONVERTER_SETDEFAULTENDIANNESSOFFOREIGNCHARACTERS, "Bad Default Endianness Of Foreign Characters in CCnvCharacterSetConverter::SetDefaultEndiannessOfForeignCharacters" );        
       
  1466         }
  1386 	__ASSERT_ALWAYS((aDefaultEndiannessOfForeignCharacters==ELittleEndian) || (aDefaultEndiannessOfForeignCharacters==EBigEndian), Panic(EPanicBadDefaultEndiannessOfForeignCharacters));
  1467 	__ASSERT_ALWAYS((aDefaultEndiannessOfForeignCharacters==ELittleEndian) || (aDefaultEndiannessOfForeignCharacters==EBigEndian), Panic(EPanicBadDefaultEndiannessOfForeignCharacters));
  1387 	iDefaultEndiannessOfForeignCharacters=aDefaultEndiannessOfForeignCharacters;
  1468 	iDefaultEndiannessOfForeignCharacters=aDefaultEndiannessOfForeignCharacters;
  1388 	}
  1469 	}
  1389 
  1470 
  1390 
  1471 
  1408 converted into line feeds only. Any other value causes the function to panic. */
  1489 converted into line feeds only. Any other value causes the function to panic. */
  1409 EXPORT_C void 
  1490 EXPORT_C void 
  1410 CCnvCharacterSetConverter::SetDowngradeForExoticLineTerminatingCharacters(
  1491 CCnvCharacterSetConverter::SetDowngradeForExoticLineTerminatingCharacters(
  1411 	TDowngradeForExoticLineTerminatingCharacters aDowngradeForExoticLineTerminatingCharacters)
  1492 	TDowngradeForExoticLineTerminatingCharacters aDowngradeForExoticLineTerminatingCharacters)
  1412 	{
  1493 	{
       
  1494     if ( (aDowngradeForExoticLineTerminatingCharacters!=EDowngradeExoticLineTerminatingCharactersToCarriageReturnLineFeed) && (aDowngradeForExoticLineTerminatingCharacters!=EDowngradeExoticLineTerminatingCharactersToJustLineFeed) )
       
  1495     {
       
  1496     OstTrace0( TRACE_FATAL, CCNVCHARACTERSETCONVERTER_SETDOWNGRADEFOREXOTICLINETERMINATINGCHARACTERS, "Bad Downgrade For Exotic Line Terminating Characters1 in CCnvCharacterSetConverter::SetDowngradeForExoticLineTerminatingCharacters" );
       
  1497     }
  1413 	__ASSERT_ALWAYS((aDowngradeForExoticLineTerminatingCharacters==EDowngradeExoticLineTerminatingCharactersToCarriageReturnLineFeed) || (aDowngradeForExoticLineTerminatingCharacters==EDowngradeExoticLineTerminatingCharactersToJustLineFeed), Panic(EPanicBadDowngradeForExoticLineTerminatingCharacters1));
  1498 	__ASSERT_ALWAYS((aDowngradeForExoticLineTerminatingCharacters==EDowngradeExoticLineTerminatingCharactersToCarriageReturnLineFeed) || (aDowngradeForExoticLineTerminatingCharacters==EDowngradeExoticLineTerminatingCharactersToJustLineFeed), Panic(EPanicBadDowngradeForExoticLineTerminatingCharacters1));
  1414 	iDowngradeForExoticLineTerminatingCharacters=aDowngradeForExoticLineTerminatingCharacters;
  1499 	iDowngradeForExoticLineTerminatingCharacters=aDowngradeForExoticLineTerminatingCharacters;
  1415 	}
  1500 	}
  1416 
  1501 
  1417 /** Sets the character used to replace unconvertible characters in the output 
  1502 /** Sets the character used to replace unconvertible characters in the output 
  1572 EXPORT_C TInt CCnvCharacterSetConverter::ConvertFromUnicode(
  1657 EXPORT_C TInt CCnvCharacterSetConverter::ConvertFromUnicode(
  1573 						TDes8& aForeign, 
  1658 						TDes8& aForeign, 
  1574 						const TDesC16& aUnicode, 
  1659 						const TDesC16& aUnicode, 
  1575 						TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters) const
  1660 						TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters) const
  1576 	{
  1661 	{
       
  1662 	if ( iCharacterSetIdentifierOfLoadedConversionData==0 )
       
  1663 	    {
       
  1664 	    OstTrace0( TRACE_FATAL, CCNVCHARACTERSETCONVERTER_CONVERTFROMUNICODE, "NullCharacterSetIdentifier1 in CCnvCharacterSetConverter::ConvertFromUnicode" );
       
  1665 	    }
  1577 	__ASSERT_ALWAYS(iCharacterSetIdentifierOfLoadedConversionData!=0, Panic(EPanicNullCharacterSetIdentifier1));
  1666 	__ASSERT_ALWAYS(iCharacterSetIdentifierOfLoadedConversionData!=0, Panic(EPanicNullCharacterSetIdentifier1));
  1578 	if (aUnicode.Length()==0)
  1667 	if (aUnicode.Length()==0)
  1579 		{
  1668 		{
  1580 		aForeign.SetLength(0);
  1669 		aForeign.SetLength(0);
  1581 		return 0;
  1670 		return 0;
  1733 								const TDesC8& aForeign, 
  1822 								const TDesC8& aForeign, 
  1734 								TInt& aState, 
  1823 								TInt& aState, 
  1735 								TInt& aNumberOfUnconvertibleCharacters, 
  1824 								TInt& aNumberOfUnconvertibleCharacters, 
  1736 								TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter) const
  1825 								TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter) const
  1737 	{
  1826 	{
       
  1827 	if ( iCharacterSetIdentifierOfLoadedConversionData==0 )
       
  1828 	    {
       
  1829 	    OstTrace0( TRACE_FATAL, CCNVCHARACTERSETCONVERTER_CONVERTTOUNICODE, "Null CharacterSetIdentifier2 in CCnvCharacterSetConverter::ConvertToUnicode" );    
       
  1830 	    }
  1738 	__ASSERT_ALWAYS(iCharacterSetIdentifierOfLoadedConversionData!=0, Panic(EPanicNullCharacterSetIdentifier2));
  1831 	__ASSERT_ALWAYS(iCharacterSetIdentifierOfLoadedConversionData!=0, Panic(EPanicNullCharacterSetIdentifier2));
  1739 	aNumberOfUnconvertibleCharacters=0;
  1832 	aNumberOfUnconvertibleCharacters=0;
  1740 	aIndexOfFirstByteOfFirstUnconvertibleCharacter=-1;
  1833 	aIndexOfFirstByteOfFirstUnconvertibleCharacter=-1;
  1741 	if (aForeign.Length()==0)
  1834 	if (aForeign.Length()==0)
  1742 		{
  1835 		{
  1776 			break;
  1869 			break;
  1777 		case KCharacterSetIdentifierImapUtf7:
  1870 		case KCharacterSetIdentifierImapUtf7:
  1778 			returnValue=CnvUtfConverter::ConvertToUnicodeFromUtf7(aUnicode, aForeign, ETrue, aState);
  1871 			returnValue=CnvUtfConverter::ConvertToUnicodeFromUtf7(aUnicode, aForeign, ETrue, aState);
  1779 			break;
  1872 			break;
  1780 		default:
  1873 		default:
       
  1874 		    if ( iConversionData==NULL )
       
  1875 		        {
       
  1876 		        OstTrace0( TRACE_FATAL, DUP1_CCNVCHARACTERSETCONVERTER_CONVERTTOUNICODE, "No ConversionData2 in CCnvCharacterSetConverter::ConvertToUnicode" );
       
  1877 		        }
  1781 			__ASSERT_ALWAYS(iConversionData!=NULL, Panic(EPanicNoConversionData2));
  1878 			__ASSERT_ALWAYS(iConversionData!=NULL, Panic(EPanicNoConversionData2));
  1782 			returnValue=DoConvertToUnicode(*iConversionData, iDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
  1879 			returnValue=DoConvertToUnicode(*iConversionData, iDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
  1783 			break;
  1880 			break;
  1784 			}
  1881 			}
  1785 		}
  1882 		}
  1886  			implUid.iUid = charactersSet.Identifier();
  1983  			implUid.iUid = charactersSet.Identifier();
  1887 			TBool isInThisCharSet = (iCharsetCnvCache->GetConverterL(implUid))->IsInThisCharacterSetL(
  1984 			TBool isInThisCharSet = (iCharsetCnvCache->GetConverterL(implUid))->IsInThisCharacterSetL(
  1888 																plugInImplementsAutoDetect, 
  1985 																plugInImplementsAutoDetect, 
  1889 																aConfidenceLevel, 
  1986 																aConfidenceLevel, 
  1890 																aSample);
  1987 																aSample);
       
  1988 			OstTraceExt3( TRACE_DUMP, CCNVCHARACTERSETCONVERTER_AUTODETECTCHARSETL, "detect identifier 0x%x, return isInThisCharSet=%d, aConfidenceLevel=%d",  implUid.iUid, isInThisCharSet, aConfidenceLevel);
  1891 			if ((!plugInImplementsAutoDetect) || !isInThisCharSet)
  1989 			if ((!plugInImplementsAutoDetect) || !isInThisCharSet)
  1892 				{
  1990 				{
  1893 				continue;
  1991 				continue;
  1894 				}
  1992 				}
  1895 			}
  1993 			}
  1916 	TInt result=0;
  2014 	TInt result=0;
  1917 	TInt min = KMaxTInt;;
  2015 	TInt min = KMaxTInt;;
  1918 	const TInt numberOfCandidateCharacterSets=chid.Count();
  2016 	const TInt numberOfCandidateCharacterSets=chid.Count();
  1919 	if (numberOfCandidateCharacterSets ==0)
  2017 	if (numberOfCandidateCharacterSets ==0)
  1920  		{
  2018  		{
       
  2019         OstTrace0( TRACE_DUMP, DUP2_CCNVCHARACTERSETCONVERTER_AUTODETECTCHARSETL, "We donot find any candidate in first run, so add all plugin as candidate." );
  1921  		// all the charcterset returned 0, so take all and find then one with least unconvertible
  2020  		// all the charcterset returned 0, so take all and find then one with least unconvertible
  1922  		// characters
  2021  		// characters
  1923  		for (TInt i=aArrayOfCharacterSetsAvailable.Count()-1; i>=0; --i)
  2022  		for (TInt i=aArrayOfCharacterSetsAvailable.Count()-1; i>=0; --i)
  1924  			{
  2023  			{
  1925  			const CCnvCharacterSetConverter::SCharacterSet& charactersSettoAppend=aArrayOfCharacterSetsAvailable[i];
  2024  			const CCnvCharacterSetConverter::SCharacterSet& charactersSettoAppend=aArrayOfCharacterSetsAvailable[i];
  1937 			{
  2036 			{
  1938 			charconverter->PrepareToConvertToOrFromL(chid[i], aArrayOfCharacterSetsAvailable, dummyFileServerSession); 
  2037 			charconverter->PrepareToConvertToOrFromL(chid[i], aArrayOfCharacterSetsAvailable, dummyFileServerSession); 
  1939 			TInt state=KStateDefault;
  2038 			TInt state=KStateDefault;
  1940 			TInt unconvertibleChars;
  2039 			TInt unconvertibleChars;
  1941 			charconverter->ConvertToUnicode(*convertedToUnicode,aSample,state,unconvertibleChars);
  2040 			charconverter->ConvertToUnicode(*convertedToUnicode,aSample,state,unconvertibleChars);
       
  2041 			OstTraceExt2( TRACE_DUMP, DUP1_CCNVCHARACTERSETCONVERTER_AUTODETECTCHARSETL, "Plugin 0x%x has %d unconvertibleChars", chid[i], unconvertibleChars);
       
  2042 			
  1942 			if (unconvertibleChars < min)
  2043 			if (unconvertibleChars < min)
  1943 				{
  2044 				{
  1944 				min = unconvertibleChars;
  2045 				min = unconvertibleChars;
  1945 				result = i;
  2046 				result = i;
  1946 				}
  2047 				}
  1950 
  2051 
  1951 	aConfidenceLevel=previousConfidenceLevel;
  2052 	aConfidenceLevel=previousConfidenceLevel;
  1952 
  2053 
  1953 	//aConfidenceLevel=another;
  2054 	//aConfidenceLevel=another;
  1954 	aCharacterSetIdentifier = chid[result];
  2055 	aCharacterSetIdentifier = chid[result];
       
  2056 	OstTrace1( TRACE_DUMP, DUP3_CCNVCHARACTERSETCONVERTER_AUTODETECTCHARSETL, "Use 0x%x as the auto detected plugin", aCharacterSetIdentifier);
  1955 	
  2057 	
  1956 	if (aConfidenceLevel <= ELowestThreshold) 
  2058 	if (aConfidenceLevel <= ELowestThreshold) 
  1957 		{
  2059 		{
  1958 		// go through all the charset available again and start converting the sample test
  2060 		// go through all the charset available again and start converting the sample test
  1959 		// the one with the least 0xfffd is the winner !! 
  2061 		// the one with the least 0xfffd is the winner !! 
  2051 	}
  2153 	}
  2052 	
  2154 	
  2053 LOCAL_C TUint OutputCharacterCode(TUint aInputCharacterCode, 
  2155 LOCAL_C TUint OutputCharacterCode(TUint aInputCharacterCode, 
  2054 								  const SCnvConversionData::SOneDirectionData::SRange& aRange)
  2156 								  const SCnvConversionData::SOneDirectionData::SRange& aRange)
  2055 	{
  2157 	{
       
  2158 	if ( (aInputCharacterCode<aRange.iFirstInputCharacterCodeInRange) || (aInputCharacterCode>aRange.iLastInputCharacterCodeInRange) )
       
  2159 	    {
       
  2160 	    OstTrace0( TRACE_FATAL, _OUTPUTCHARACTERCODE, "Input Character Code Not In Range in ::OutputCharacterCode" );
       
  2161 	    }
  2056 	__ASSERT_DEBUG((aInputCharacterCode>=aRange.iFirstInputCharacterCodeInRange) && (aInputCharacterCode<=aRange.iLastInputCharacterCodeInRange), Panic(EPanicInputCharacterCodeNotInRange));
  2162 	__ASSERT_DEBUG((aInputCharacterCode>=aRange.iFirstInputCharacterCodeInRange) && (aInputCharacterCode<=aRange.iLastInputCharacterCodeInRange), Panic(EPanicInputCharacterCodeNotInRange));
  2057 	switch (aRange.iAlgorithm)
  2163 	switch (aRange.iAlgorithm)
  2058 		{
  2164 		{
  2059 	case SCnvConversionData::SOneDirectionData::SRange::EDirect:
  2165 	case SCnvConversionData::SOneDirectionData::SRange::EDirect:
  2060 		return aInputCharacterCode;
  2166 		return aInputCharacterCode;
  2061 	case SCnvConversionData::SOneDirectionData::SRange::EOffset:
  2167 	case SCnvConversionData::SOneDirectionData::SRange::EOffset:
  2062 #if defined(CONST_STATIC_UNIONS_ARE_POSSIBLE)
  2168 #if defined(CONST_STATIC_UNIONS_ARE_POSSIBLE)
       
  2169 	    if (aRange.iData.iOffset==0)
       
  2170 	        {
       
  2171 	        OstTrace0( TRACE_DUMP, DUP1__OUTPUTCHARACTERCODE, "EPanicZeroOffset1" );
       
  2172 	        }
  2063 		__ASSERT_DEBUG(aRange.iData.iOffset!=0, Panic(EPanicZeroOffset1));
  2173 		__ASSERT_DEBUG(aRange.iData.iOffset!=0, Panic(EPanicZeroOffset1));
  2064 		return aInputCharacterCode+aRange.iData.iOffset;
  2174 		return aInputCharacterCode+aRange.iData.iOffset;
  2065 #else
  2175 #else
       
  2176 		if (STATIC_CAST(TInt, aRange.iData.iWord1)==0)
       
  2177 		    {
       
  2178 		    OstTrace0( TRACE_DUMP, DUP2__OUTPUTCHARACTERCODE, "EPanicZeroOffset2" );
       
  2179 		    }
  2066 		__ASSERT_DEBUG(STATIC_CAST(TInt, aRange.iData.iWord1)!=0, Panic(EPanicZeroOffset2));
  2180 		__ASSERT_DEBUG(STATIC_CAST(TInt, aRange.iData.iWord1)!=0, Panic(EPanicZeroOffset2));
  2067 		return aInputCharacterCode+STATIC_CAST(TInt, aRange.iData.iWord1);
  2181 		return aInputCharacterCode+STATIC_CAST(TInt, aRange.iData.iWord1);
  2068 #endif
  2182 #endif
  2069 	case SCnvConversionData::SOneDirectionData::SRange::EIndexedTable16:
  2183 	case SCnvConversionData::SOneDirectionData::SRange::EIndexedTable16:
  2070 #if defined(CONST_STATIC_UNIONS_ARE_POSSIBLE)
  2184 #if defined(CONST_STATIC_UNIONS_ARE_POSSIBLE)
  2081 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable1616::SEntry* const entryArray=aRange.iData.iKeyedTable1616.iEntryArray;
  2195 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable1616::SEntry* const entryArray=aRange.iData.iKeyedTable1616.iEntryArray;
  2082 #else
  2196 #else
  2083 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2197 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2084 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable1616::SEntry* const entryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable1616::SEntry*, aRange.iData.iWord2);
  2198 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable1616::SEntry* const entryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable1616::SEntry*, aRange.iData.iWord2);
  2085 #endif
  2199 #endif
       
  2200 		if(rightIndex<=0)
       
  2201 		    {
       
  2202 		    OstTrace0( TRACE_DUMP, DUP3__OUTPUTCHARACTERCODE, "EPanicEmptyKeyedTable1616" );
       
  2203 		    }
  2086 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable1616));
  2204 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable1616));
  2087 		FOREVER
  2205 		FOREVER
  2088 			{
  2206 			{
       
  2207 			if (leftIndex>rightIndex)
       
  2208 			    {
       
  2209 			    OstTrace0( TRACE_DUMP, DUP4__OUTPUTCHARACTERCODE, "EPanicBadIndices1" );
       
  2210 			    }
  2089 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices1));
  2211 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices1));
  2090 			if (leftIndex==rightIndex)
  2212 			if (leftIndex==rightIndex)
  2091 				{
  2213 				{
  2092 				return KNoConversionAvailable;
  2214 				return KNoConversionAvailable;
  2093 				}
  2215 				}
  2115 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable16OfIndexedTables16::SKeyedEntry* const keyedEntryArray=aRange.iData.iKeyedTable16OfIndexedTables16.iKeyedEntryArray;
  2237 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable16OfIndexedTables16::SKeyedEntry* const keyedEntryArray=aRange.iData.iKeyedTable16OfIndexedTables16.iKeyedEntryArray;
  2116 #else
  2238 #else
  2117 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2239 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2118 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable16OfIndexedTables16::SKeyedEntry* const keyedEntryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable16OfIndexedTables16::SKeyedEntry*, aRange.iData.iWord2);
  2240 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable16OfIndexedTables16::SKeyedEntry* const keyedEntryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable16OfIndexedTables16::SKeyedEntry*, aRange.iData.iWord2);
  2119 #endif
  2241 #endif
       
  2242 		if (rightIndex<=0)
       
  2243 		    {
       
  2244 		    OstTrace0( TRACE_DUMP, DUP5__OUTPUTCHARACTERCODE, "EPanicEmptyKeyedTable16OfIndexedTables16" );
       
  2245 		    }
  2120 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable16OfIndexedTables16));
  2246 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable16OfIndexedTables16));
  2121 		FOREVER
  2247 		FOREVER
  2122 			{
  2248 			{
       
  2249 			if (leftIndex>rightIndex)
       
  2250 			    {
       
  2251 			    OstTrace0( TRACE_DUMP, DUP6__OUTPUTCHARACTERCODE, "EPanicBadIndices2" );
       
  2252 			    }
  2123 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices2));
  2253 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices2));
  2124 			if (leftIndex==rightIndex)
  2254 			if (leftIndex==rightIndex)
  2125 				{
  2255 				{
  2126 				return KNoConversionAvailable;
  2256 				return KNoConversionAvailable;
  2127 				}
  2257 				}
  2158 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable3232::SEntry* const entryArray=aRange.iData.iKeyedTable3232.iEntryArray;
  2288 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable3232::SEntry* const entryArray=aRange.iData.iKeyedTable3232.iEntryArray;
  2159 #else
  2289 #else
  2160 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2290 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2161 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable3232::SEntry* const entryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable3232::SEntry*, aRange.iData.iWord2);
  2291 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable3232::SEntry* const entryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable3232::SEntry*, aRange.iData.iWord2);
  2162 #endif
  2292 #endif
       
  2293 		if (rightIndex<=0)
       
  2294 		    {
       
  2295 		    OstTrace0( TRACE_DUMP, DUP7__OUTPUTCHARACTERCODE, "EPanicEmptyKeyedTable3232" );
       
  2296 		    }
  2163 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable3232));
  2297 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable3232));
  2164 		FOREVER
  2298 		FOREVER
  2165 			{
  2299 			{
       
  2300 			if (leftIndex>rightIndex)
       
  2301 			    {
       
  2302 			    OstTrace0( TRACE_DUMP, DUP8__OUTPUTCHARACTERCODE, "EPanicBadIndices1" );
       
  2303 			    }
  2166 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices1));
  2304 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices1));
  2167 			if (leftIndex==rightIndex)
  2305 			if (leftIndex==rightIndex)
  2168 				{
  2306 				{
  2169 				return KNoConversionAvailable;
  2307 				return KNoConversionAvailable;
  2170 				}
  2308 				}
  2192 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable32OfIndexedTables32::SKeyedEntry* const keyedEntryArray=aRange.iData.iKeyedTable32OfIndexedTables32.iKeyedEntryArray;
  2330 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable32OfIndexedTables32::SKeyedEntry* const keyedEntryArray=aRange.iData.iKeyedTable32OfIndexedTables32.iKeyedEntryArray;
  2193 #else
  2331 #else
  2194 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2332 		TInt rightIndex=STATIC_CAST(TInt, aRange.iData.iWord1);
  2195 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable32OfIndexedTables32::SKeyedEntry* const keyedEntryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable32OfIndexedTables32::SKeyedEntry*, aRange.iData.iWord2);
  2333 		const SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable32OfIndexedTables32::SKeyedEntry* const keyedEntryArray=REINTERPRET_CAST(SCnvConversionData::SOneDirectionData::SRange::UData::SKeyedTable32OfIndexedTables32::SKeyedEntry*, aRange.iData.iWord2);
  2196 #endif
  2334 #endif
       
  2335 		if (rightIndex<=0)
       
  2336 		    {
       
  2337 		    OstTrace0( TRACE_DUMP, DUP9__OUTPUTCHARACTERCODE, "EPanicEmptyKeyedTable32OfIndexedTables32" );
       
  2338 		    }
  2197 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable32OfIndexedTables32));
  2339 		__ASSERT_DEBUG(rightIndex>0, Panic(EPanicEmptyKeyedTable32OfIndexedTables32));
  2198 		FOREVER
  2340 		FOREVER
  2199 			{
  2341 			{
       
  2342 			if (leftIndex>rightIndex)
       
  2343 			    {
       
  2344 			    OstTrace0( TRACE_DUMP, DUP10__OUTPUTCHARACTERCODE, "EPanicBadIndices2" );
       
  2345 			    }
  2200 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices2));
  2346 			__ASSERT_DEBUG(leftIndex<=rightIndex, Panic(EPanicBadIndices2));
  2201 			if (leftIndex==rightIndex)
  2347 			if (leftIndex==rightIndex)
  2202 				{
  2348 				{
  2203 				return KNoConversionAvailable;
  2349 				return KNoConversionAvailable;
  2204 				}
  2350 				}
  2220 		}
  2366 		}
  2221 //new 32 bit algorithms end		
  2367 //new 32 bit algorithms end		
  2222 		
  2368 		
  2223 #if defined(_DEBUG)
  2369 #if defined(_DEBUG)
  2224 	default:
  2370 	default:
       
  2371 	    OstTrace0( TRACE_DUMP, DUP11__OUTPUTCHARACTERCODE, "EPanicBadAlgorithm1" );
  2225 		Panic(EPanicBadAlgorithm1);
  2372 		Panic(EPanicBadAlgorithm1);
  2226 #endif
  2373 #endif
  2227 		}
  2374 		}
  2228 	return 0; // dummy return to prevent compiler error
  2375 	return 0; // dummy return to prevent compiler error
  2229 	}
  2376 	}
  2233 			TInt& aSizeOfOutputForeignCharacterCodeInBytes, 
  2380 			TInt& aSizeOfOutputForeignCharacterCodeInBytes, 
  2234 			TUint aInputUnicodeCharacterCode, 
  2381 			TUint aInputUnicodeCharacterCode, 
  2235 			const SCnvConversionData::SOneDirectionData::SRange* aFirstUnicodeToForeignRange, 
  2382 			const SCnvConversionData::SOneDirectionData::SRange* aFirstUnicodeToForeignRange, 
  2236 			const SCnvConversionData::SOneDirectionData::SRange* aLastUnicodeToForeignRange)
  2383 			const SCnvConversionData::SOneDirectionData::SRange* aLastUnicodeToForeignRange)
  2237 	{
  2384 	{
       
  2385 	if (aFirstUnicodeToForeignRange==NULL)
       
  2386 	    {
       
  2387 	    OstTrace0( TRACE_DUMP, _CONVERTSTOFOREIGNCHARACTERSET, "EPanicNullPointer1" );
       
  2388 	    }
  2238 	__ASSERT_DEBUG(aFirstUnicodeToForeignRange!=NULL, Panic(EPanicNullPointer1));
  2389 	__ASSERT_DEBUG(aFirstUnicodeToForeignRange!=NULL, Panic(EPanicNullPointer1));
       
  2390 	if (aLastUnicodeToForeignRange==NULL)
       
  2391 	    {
       
  2392 	    OstTrace0( TRACE_DUMP, DUP1__CONVERTSTOFOREIGNCHARACTERSET, "EPanicNullPointer2" );
       
  2393 	    }
  2239 	__ASSERT_DEBUG(aLastUnicodeToForeignRange!=NULL, Panic(EPanicNullPointer2));
  2394 	__ASSERT_DEBUG(aLastUnicodeToForeignRange!=NULL, Panic(EPanicNullPointer2));
       
  2395 	if (aFirstUnicodeToForeignRange>aLastUnicodeToForeignRange)
       
  2396 	    {
       
  2397 	    OstTrace0( TRACE_DUMP, DUP2__CONVERTSTOFOREIGNCHARACTERSET, "EPanicCrossedPointers" );
       
  2398 	    }
  2240 	__ASSERT_DEBUG(aFirstUnicodeToForeignRange<=aLastUnicodeToForeignRange, Panic(EPanicCrossedPointers));
  2399 	__ASSERT_DEBUG(aFirstUnicodeToForeignRange<=aLastUnicodeToForeignRange, Panic(EPanicCrossedPointers));
  2241 	for (const SCnvConversionData::SOneDirectionData::SRange* currentUnicodeToForeignRange=aFirstUnicodeToForeignRange; ; ++currentUnicodeToForeignRange)
  2400 	for (const SCnvConversionData::SOneDirectionData::SRange* currentUnicodeToForeignRange=aFirstUnicodeToForeignRange; ; ++currentUnicodeToForeignRange)
  2242 		{
  2401 		{
  2243 		if ((aInputUnicodeCharacterCode>=currentUnicodeToForeignRange->iFirstInputCharacterCodeInRange) &&
  2402 		if ((aInputUnicodeCharacterCode>=currentUnicodeToForeignRange->iFirstInputCharacterCodeInRange) &&
  2244 			(aInputUnicodeCharacterCode<=currentUnicodeToForeignRange->iLastInputCharacterCodeInRange))
  2403 			(aInputUnicodeCharacterCode<=currentUnicodeToForeignRange->iLastInputCharacterCodeInRange))
  2247 				{
  2406 				{
  2248 				aSizeOfOutputForeignCharacterCodeInBytes=currentUnicodeToForeignRange->iSizeOfOutputCharacterCodeInBytesIfForeign;
  2407 				aSizeOfOutputForeignCharacterCodeInBytes=currentUnicodeToForeignRange->iSizeOfOutputCharacterCodeInBytesIfForeign;
  2249 				return ETrue;
  2408 				return ETrue;
  2250 				}
  2409 				}
  2251 			}
  2410 			}
       
  2411 		if (currentUnicodeToForeignRange>aLastUnicodeToForeignRange)
       
  2412 		    {
       
  2413 		    OstTrace0( TRACE_DUMP, DUP3__CONVERTSTOFOREIGNCHARACTERSET, "EPanicPointerPastUpperLimit21" );
       
  2414 		    }
  2252 		__ASSERT_DEBUG(currentUnicodeToForeignRange<=aLastUnicodeToForeignRange, Panic(EPanicPointerPastUpperLimit21));
  2415 		__ASSERT_DEBUG(currentUnicodeToForeignRange<=aLastUnicodeToForeignRange, Panic(EPanicPointerPastUpperLimit21));
  2253 		if (currentUnicodeToForeignRange>=aLastUnicodeToForeignRange)
  2416 		if (currentUnicodeToForeignRange>=aLastUnicodeToForeignRange)
  2254 			{
  2417 			{
  2255 			return EFalse;
  2418 			return EFalse;
  2256 			}
  2419 			}
  2279 for foreign characters is specified in aConversionData (i.e. not 
  2442 for foreign characters is specified in aConversionData (i.e. not 
  2280 SCnvConversionData::EUnspecified), then that value is used and the value of 
  2443 SCnvConversionData::EUnspecified), then that value is used and the value of 
  2281 aDefaultEndiannessOfForeignCharacters is ignored.
  2444 aDefaultEndiannessOfForeignCharacters is ignored.
  2282 @param aReplacementForUnconvertibleUnicodeCharacters The single character which 
  2445 @param aReplacementForUnconvertibleUnicodeCharacters The single character which 
  2283 is to be used to replace unconvertible characters.
  2446 is to be used to replace unconvertible characters.
  2284 @param aForeign On return, contains the converted text in a non-Unicode 
  2447 @param aForeign On return, contains the converted text in a non-Unicode 
  2285 character set.
  2448 character set.
  2286 @param aUnicode The source Unicode text to be converted.
  2449 @param aUnicode The source Unicode text to be converted.
  2287 @param aIndicesOfUnconvertibleCharacters On return holds the indices of each 
  2450 @param aIndicesOfUnconvertibleCharacters On return holds the indices of each 
  2288 Unicode character in the source text which could not be converted (because 
  2451 Unicode character in the source text which could not be converted (because 
  2289 the target character set does not have an equivalent character).
  2452 the target character set does not have an equivalent character).
  2329 @param aReplacementForUnconvertibleUnicodeCharacters The single character which 
  2492 @param aReplacementForUnconvertibleUnicodeCharacters The single character which 
  2330 is to be used to replace unconvertible characters. If aInputConversionFlags 
  2493 is to be used to replace unconvertible characters. If aInputConversionFlags 
  2331 is set to EInputConversionFlagStopAtFirstUnconvertibleCharacter, this 
  2494 is set to EInputConversionFlagStopAtFirstUnconvertibleCharacter, this 
  2332 replacement character is used to replace the first unconvertible character, 
  2495 replacement character is used to replace the first unconvertible character, 
  2333 then the conversion will stop.
  2496 then the conversion will stop.
  2334 @param aForeign On return, contains the converted text in a non-Unicode 
  2497 @param aForeign On return, contains the converted text in a non-Unicode 
  2335 character set. This may already contain some text. If it does, and if 
  2498 character set. This may already contain some text. If it does, and if 
  2336 aInputConversionFlags specifies EInputConversionFlagAppend, then the converted 
  2499 aInputConversionFlags specifies EInputConversionFlagAppend, then the converted 
  2337 text is appended to this descriptor.
  2500 text is appended to this descriptor.
  2338 @param aUnicode The source Unicode text to be converted.
  2501 @param aUnicode The source Unicode text to be converted.
  2339 @param aIndicesOfUnconvertibleCharacters On return holds the indices of each 
  2502 @param aIndicesOfUnconvertibleCharacters On return holds the indices of each 
  2384 		{
  2547 		{
  2385 		pointerToPreviousForeignByte+=aForeign.Length();
  2548 		pointerToPreviousForeignByte+=aForeign.Length();
  2386 		}
  2549 		}
  2387 	const TUint16* pointerToCurrentUnicodeCharacter=aUnicode.Ptr();
  2550 	const TUint16* pointerToCurrentUnicodeCharacter=aUnicode.Ptr();
  2388 	const TUint16* const pointerToLastUnicodeCharacter=pointerToCurrentUnicodeCharacter+(aUnicode.Length()-1);
  2551 	const TUint16* const pointerToLastUnicodeCharacter=pointerToCurrentUnicodeCharacter+(aUnicode.Length()-1);
       
  2552 	if (aConversionData.iUnicodeToForeignData.iNumberOfRanges<=0)
       
  2553 	    {
       
  2554 	    OstTrace0( TRACE_DUMP, CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicBadNumberOfRanges1" );
       
  2555 	    }
  2389 	__ASSERT_DEBUG(aConversionData.iUnicodeToForeignData.iNumberOfRanges>0, Panic(EPanicBadNumberOfRanges1));
  2556 	__ASSERT_DEBUG(aConversionData.iUnicodeToForeignData.iNumberOfRanges>0, Panic(EPanicBadNumberOfRanges1));
  2390 	const SCnvConversionData::SOneDirectionData::SRange* const firstRange=aConversionData.iUnicodeToForeignData.iRangeArray;
  2557 	const SCnvConversionData::SOneDirectionData::SRange* const firstRange=aConversionData.iUnicodeToForeignData.iRangeArray;
  2391 	const SCnvConversionData::SOneDirectionData::SRange* const lastRange=firstRange+(aConversionData.iUnicodeToForeignData.iNumberOfRanges-1);
  2558 	const SCnvConversionData::SOneDirectionData::SRange* const lastRange=firstRange+(aConversionData.iUnicodeToForeignData.iNumberOfRanges-1);
  2392 	const TEndianness endiannessToWriteForeignCharactersIn=EndiannessOfForeignCharacters(aConversionData, aDefaultEndiannessOfForeignCharacters);
  2559 	const TEndianness endiannessToWriteForeignCharactersIn=EndiannessOfForeignCharacters(aConversionData, aDefaultEndiannessOfForeignCharacters);
  2393 	const TEndianness endiannessOfReplacementForUnconvertibleUnicodeCharacters=EndiannessOfForeignCharacters(aConversionData, ELittleEndian); // this has a hard-coded default
  2560 	const TEndianness endiannessOfReplacementForUnconvertibleUnicodeCharacters=EndiannessOfForeignCharacters(aConversionData, ELittleEndian); // this has a hard-coded default
  2395 	const TBool downgradingPermitted=(currentCharacterSetConverter!=NULL); // downgrading is only permitted if we're not doing VFAT short-name generation
  2562 	const TBool downgradingPermitted=(currentCharacterSetConverter!=NULL); // downgrading is only permitted if we're not doing VFAT short-name generation
  2396 	const TDowngradeForExoticLineTerminatingCharacters downgradeForExoticLineTerminatingCharacters=(currentCharacterSetConverter!=NULL)? currentCharacterSetConverter->iDowngradeForExoticLineTerminatingCharacters: EDowngradeExoticLineTerminatingCharactersToCarriageReturnLineFeed;
  2563 	const TDowngradeForExoticLineTerminatingCharacters downgradeForExoticLineTerminatingCharacters=(currentCharacterSetConverter!=NULL)? currentCharacterSetConverter->iDowngradeForExoticLineTerminatingCharacters: EDowngradeExoticLineTerminatingCharactersToCarriageReturnLineFeed;
  2397 	TUint nextInputCharacterCode=KNoConversionAvailable;
  2564 	TUint nextInputCharacterCode=KNoConversionAvailable;
  2398 	FOREVER
  2565 	FOREVER
  2399 		{
  2566 		{
       
  2567 		if (pointerToPreviousForeignByte>pointerToLastForeignByte)
       
  2568 		    {
       
  2569 		    OstTrace0( TRACE_DUMP, DUP1_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit6" );
       
  2570 		    }
  2400 		__ASSERT_DEBUG(pointerToPreviousForeignByte<=pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit6));
  2571 		__ASSERT_DEBUG(pointerToPreviousForeignByte<=pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit6));
       
  2572 		if (pointerToCurrentUnicodeCharacter>pointerToLastUnicodeCharacter)
       
  2573 		    {
       
  2574 		    OstTrace0( TRACE_DUMP, DUP2_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit7" );
       
  2575 		    }
  2401 		__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit7));
  2576 		__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit7));
  2402 		TBool stop=EFalse;
  2577 		TBool stop=EFalse;
  2403 		TUint inputCharacterCode;
  2578 		TUint inputCharacterCode;
  2404 		if (nextInputCharacterCode==KNoConversionAvailable)
  2579 		if (nextInputCharacterCode==KNoConversionAvailable)
  2405 			{
  2580 			{
  2410 			inputCharacterCode=nextInputCharacterCode;
  2585 			inputCharacterCode=nextInputCharacterCode;
  2411 			nextInputCharacterCode=KNoConversionAvailable;
  2586 			nextInputCharacterCode=KNoConversionAvailable;
  2412 			}
  2587 			}
  2413 		if ((inputCharacterCode>=0xd800) && (inputCharacterCode<0xdc00))
  2588 		if ((inputCharacterCode>=0xd800) && (inputCharacterCode<0xdc00))
  2414 			{
  2589 			{
       
  2590 			if (pointerToCurrentUnicodeCharacter>pointerToLastUnicodeCharacter)
       
  2591 			    {
       
  2592 			    OstTrace0( TRACE_DUMP, DUP3_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit8" );
       
  2593 			    }
  2415 			__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit8));
  2594 			__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit8));
  2416 			if (pointerToCurrentUnicodeCharacter>=pointerToLastUnicodeCharacter)
  2595 			if (pointerToCurrentUnicodeCharacter>=pointerToLastUnicodeCharacter)
  2417 				{
  2596 				{
  2418 				aOutputConversionFlags|=EOutputConversionFlagInputIsTruncated;
  2597 				aOutputConversionFlags|=EOutputConversionFlagInputIsTruncated;
  2419 				goto end;
  2598 				goto end;
  2426 			inputCharacterCode&=~0xd800;
  2605 			inputCharacterCode&=~0xd800;
  2427 			inputCharacterCode<<=10;
  2606 			inputCharacterCode<<=10;
  2428 			secondHalfOfSurrogatePair&=~0xdc00;
  2607 			secondHalfOfSurrogatePair&=~0xdc00;
  2429 			inputCharacterCode|=secondHalfOfSurrogatePair;
  2608 			inputCharacterCode|=secondHalfOfSurrogatePair;
  2430 			inputCharacterCode+=0x00010000; // this must be added - it cannot be bitwise-"or"-ed
  2609 			inputCharacterCode+=0x00010000; // this must be added - it cannot be bitwise-"or"-ed
       
  2610 			if (!(inputCharacterCode&0xffff0000) || !(inputCharacterCode<0x00110000))
       
  2611 			    {
       
  2612 			    OstTrace0( TRACE_DUMP, DUP4_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicBadNon16BitCharacterCode1" );
       
  2613 			    }
  2431 			__ASSERT_DEBUG((inputCharacterCode&0xffff0000) && (inputCharacterCode<0x00110000), Panic(EPanicBadNon16BitCharacterCode1));
  2614 			__ASSERT_DEBUG((inputCharacterCode&0xffff0000) && (inputCharacterCode<0x00110000), Panic(EPanicBadNon16BitCharacterCode1));
  2432 			}
  2615 			}
  2433 convertInputCharacterCode:
  2616 convertInputCharacterCode:
  2434 		const SCnvConversionData::SOneDirectionData::SRange* currentRange=firstRange;
  2617 		const SCnvConversionData::SOneDirectionData::SRange* currentRange=firstRange;
  2435 		FOREVER
  2618 		FOREVER
  2439 				{
  2622 				{
  2440 				TUint outputCharacterCode=OutputCharacterCode(inputCharacterCode, *currentRange);
  2623 				TUint outputCharacterCode=OutputCharacterCode(inputCharacterCode, *currentRange);
  2441 				if (outputCharacterCode!=KNoConversionAvailable)
  2624 				if (outputCharacterCode!=KNoConversionAvailable)
  2442 					{
  2625 					{
  2443 					TInt temp=currentRange->iSizeOfOutputCharacterCodeInBytesIfForeign; // the meaning of temp changes during it's lifetime (hence the bland variable name)
  2626 					TInt temp=currentRange->iSizeOfOutputCharacterCodeInBytesIfForeign; // the meaning of temp changes during it's lifetime (hence the bland variable name)
       
  2627 					if ( (temp<=0) || ((temp>STATIC_CAST(TInt, sizeof(TUint)))) || !((temp==sizeof(TUint)) || (outputCharacterCode<STATIC_CAST(TUint, 1<<(temp*8)))) )
       
  2628 					    {
       
  2629 					    OstTrace0( TRACE_DUMP, DUP5_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicBadSizeOfForeignOutputCharacterCode" );
       
  2630 					    }
  2444 					__ASSERT_DEBUG((temp>0) && (temp<=STATIC_CAST(TInt, sizeof(TUint))) && ((temp==sizeof(TUint)) || (outputCharacterCode<STATIC_CAST(TUint, 1<<(temp*8)))), Panic(EPanicBadSizeOfForeignOutputCharacterCode)); // ?? this second half of this assert needs a corresponding "KErrCorrupt"-check when loading the file
  2631 					__ASSERT_DEBUG((temp>0) && (temp<=STATIC_CAST(TInt, sizeof(TUint))) && ((temp==sizeof(TUint)) || (outputCharacterCode<STATIC_CAST(TUint, 1<<(temp*8)))), Panic(EPanicBadSizeOfForeignOutputCharacterCode)); // ?? this second half of this assert needs a corresponding "KErrCorrupt"-check when loading the file
  2445 					if (pointerToLastForeignByte-pointerToPreviousForeignByte<temp)
  2632 					if (pointerToLastForeignByte-pointerToPreviousForeignByte<temp)
  2446 						{
  2633 						{
  2447 						goto end;
  2634 						goto end;
  2448 						}
  2635 						}
  2451 					switch (endiannessToWriteForeignCharactersIn)
  2638 					switch (endiannessToWriteForeignCharactersIn)
  2452 						{
  2639 						{
  2453 					case ELittleEndian:
  2640 					case ELittleEndian:
  2454 						FOREVER
  2641 						FOREVER
  2455 							{
  2642 							{
       
  2643 							if (pointerToPreviousForeignByte>=pointerToLastForeignByte)
       
  2644 							    {
       
  2645 							    OstTrace0( TRACE_DUMP, DUP6_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit9" );
       
  2646 							    }
  2456 							__ASSERT_DEBUG(pointerToPreviousForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit9));
  2647 							__ASSERT_DEBUG(pointerToPreviousForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit9));
  2457 							++pointerToPreviousForeignByte;
  2648 							++pointerToPreviousForeignByte;
  2458 							*pointerToPreviousForeignByte=STATIC_CAST(TUint8, outputCharacterCode);
  2649 							*pointerToPreviousForeignByte=STATIC_CAST(TUint8, outputCharacterCode);
       
  2650 							if (temp<0)
       
  2651 							    {
       
  2652 							    OstTrace0( TRACE_DUMP, DUP7_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicBadNumberOfRemainingForeignBytes1" );
       
  2653 							    }
  2459 							__ASSERT_DEBUG(temp>=0, Panic(EPanicBadNumberOfRemainingForeignBytes1));
  2654 							__ASSERT_DEBUG(temp>=0, Panic(EPanicBadNumberOfRemainingForeignBytes1));
  2460 							if (temp<=0)
  2655 							if (temp<=0)
  2461 								{
  2656 								{
  2462 								break;
  2657 								break;
  2463 								}
  2658 								}
  2466 							}
  2661 							}
  2467 						break;
  2662 						break;
  2468 					case EBigEndian:
  2663 					case EBigEndian:
  2469 						FOREVER
  2664 						FOREVER
  2470 							{
  2665 							{
       
  2666 							if (pointerToPreviousForeignByte>=pointerToLastForeignByte)
       
  2667 							    {
       
  2668 							    OstTrace0( TRACE_DUMP, DUP8_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit10" );
       
  2669 							    }
  2471 							__ASSERT_DEBUG(pointerToPreviousForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit10));
  2670 							__ASSERT_DEBUG(pointerToPreviousForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit10));
  2472 							++pointerToPreviousForeignByte;
  2671 							++pointerToPreviousForeignByte;
  2473 							*pointerToPreviousForeignByte=STATIC_CAST(TUint8, outputCharacterCode>>temp);
  2672 							*pointerToPreviousForeignByte=STATIC_CAST(TUint8, outputCharacterCode>>temp);
       
  2673 							if (temp<0)
       
  2674 							    {
       
  2675 							    OstTrace0( TRACE_DUMP, DUP9_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicBadNumberOfRemainingForeignBytes2" );
       
  2676 							    }
  2474 							__ASSERT_DEBUG(temp>=0, Panic(EPanicBadNumberOfRemainingForeignBytes2));
  2677 							__ASSERT_DEBUG(temp>=0, Panic(EPanicBadNumberOfRemainingForeignBytes2));
  2475 							if (temp<=0)
  2678 							if (temp<=0)
  2476 								{
  2679 								{
  2477 								break;
  2680 								break;
  2478 								}
  2681 								}
  2479 							temp-=8;
  2682 							temp-=8;
  2480 							}
  2683 							}
  2481 						break;
  2684 						break;
  2482 #if defined(_DEBUG)
  2685 #if defined(_DEBUG)
  2483 					default:
  2686 					default:
       
  2687 					    OstTrace0( TRACE_DUMP, DUP10_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicBadEndianness1" );
  2484 						Panic(EPanicBadEndianness1);
  2688 						Panic(EPanicBadEndianness1);
  2485 						break;
  2689 						break;
  2486 #endif
  2690 #endif
  2487 						}
  2691 						}
  2488 					break;
  2692 					break;
  2489 					}
  2693 					}
  2490 				}
  2694 				}
       
  2695 			if (currentRange>lastRange)
       
  2696 			    {
       
  2697 			    OstTrace0( TRACE_DUMP, DUP11_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit11" );
       
  2698 			    }
  2491 			__ASSERT_DEBUG(currentRange<=lastRange, Panic(EPanicPointerPastUpperLimit11));
  2699 			__ASSERT_DEBUG(currentRange<=lastRange, Panic(EPanicPointerPastUpperLimit11));
  2492 			if (currentRange>=lastRange)
  2700 			if (currentRange>=lastRange)
  2493 				{
  2701 				{
  2494 				if (downgradingPermitted)
  2702 				if (downgradingPermitted)
  2495 					{
  2703 					{
  2515 						case EDowngradeExoticLineTerminatingCharactersToJustLineFeed:
  2723 						case EDowngradeExoticLineTerminatingCharactersToJustLineFeed:
  2516 							inputCharacterCode=0x000a;
  2724 							inputCharacterCode=0x000a;
  2517 							goto convertInputCharacterCode;
  2725 							goto convertInputCharacterCode;
  2518 #if defined(_DEBUG)
  2726 #if defined(_DEBUG)
  2519 						default:
  2727 						default:
       
  2728 						    OstTrace0( TRACE_DUMP, DUP12_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicBadDowngradeForExoticLineTerminatingCharacters2" );
  2520 							Panic(EPanicBadDowngradeForExoticLineTerminatingCharacters2);
  2729 							Panic(EPanicBadDowngradeForExoticLineTerminatingCharacters2);
  2521 							break;
  2730 							break;
  2522 #endif
  2731 #endif
  2523 							}
  2732 							}
  2524 						}
  2733 						}
  2540 						lastByteToReadFrom=temp;
  2749 						lastByteToReadFrom=temp;
  2541 						increment=-1;
  2750 						increment=-1;
  2542 						}
  2751 						}
  2543 					FOREVER
  2752 					FOREVER
  2544 						{
  2753 						{
       
  2754 						if (pointerToPreviousForeignByte>=pointerToLastForeignByte)
       
  2755 						    {
       
  2756 						    OstTrace0( TRACE_DUMP, DUP13_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit12" );
       
  2757 						    }
  2545 						__ASSERT_DEBUG(pointerToPreviousForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit12));
  2758 						__ASSERT_DEBUG(pointerToPreviousForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit12));
  2546 						++pointerToPreviousForeignByte;
  2759 						++pointerToPreviousForeignByte;
  2547 						*pointerToPreviousForeignByte=*pointerToReadFrom;
  2760 						*pointerToPreviousForeignByte=*pointerToReadFrom;
  2548 						if (pointerToReadFrom==lastByteToReadFrom)
  2761 						if (pointerToReadFrom==lastByteToReadFrom)
  2549 							{
  2762 							{
  2561 				}
  2774 				}
  2562 			++currentRange;
  2775 			++currentRange;
  2563 			}
  2776 			}
  2564 		if (inputCharacterCode>=0x00010000)
  2777 		if (inputCharacterCode>=0x00010000)
  2565 			{
  2778 			{
       
  2779 			if (pointerToCurrentUnicodeCharacter>=pointerToLastUnicodeCharacter)
       
  2780 			    {
       
  2781 			    OstTrace0( TRACE_DUMP, DUP14_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit13" );
       
  2782 			    }
  2566 			__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit13));
  2783 			__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit13));
  2567 			if (nextInputCharacterCode==KNoConversionAvailable)
  2784 			if (nextInputCharacterCode==KNoConversionAvailable)
  2568 				{
  2785 				{
  2569 				++pointerToCurrentUnicodeCharacter;
  2786 				++pointerToCurrentUnicodeCharacter;
  2570 				}
  2787 				}
  2571 			}
  2788 			}
       
  2789 		if (pointerToCurrentUnicodeCharacter>pointerToLastUnicodeCharacter)
       
  2790 		    {
       
  2791 		    OstTrace0( TRACE_DUMP, DUP15_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastUpperLimit14" );
       
  2792 		    }
  2572 		__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit14));
  2793 		__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit14));
  2573 		if (nextInputCharacterCode==KNoConversionAvailable)
  2794 		if (nextInputCharacterCode==KNoConversionAvailable)
  2574 			{
  2795 			{
  2575 			if (pointerToCurrentUnicodeCharacter>=pointerToLastUnicodeCharacter)
  2796 			if (pointerToCurrentUnicodeCharacter>=pointerToLastUnicodeCharacter)
  2576 				{
  2797 				{
  2583 			{
  2804 			{
  2584 			goto end;
  2805 			goto end;
  2585 			}
  2806 			}
  2586 		}
  2807 		}
  2587 end:
  2808 end:
       
  2809     if (pointerToCurrentUnicodeCharacter<aUnicode.Ptr())
       
  2810         {
       
  2811         OstTrace0( TRACE_DUMP, DUP16_CCNVCHARACTERSETCONVERTER_DOCONVERTFROMUNICODE, "EPanicPointerPastLowerLimit1" );
       
  2812         }
  2588 	__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter>=aUnicode.Ptr(), Panic(EPanicPointerPastLowerLimit1));
  2813 	__ASSERT_DEBUG(pointerToCurrentUnicodeCharacter>=aUnicode.Ptr(), Panic(EPanicPointerPastLowerLimit1));
  2589 	if ((pointerToCurrentUnicodeCharacter<=aUnicode.Ptr()) && (aOutputConversionFlags&EOutputConversionFlagInputIsTruncated) && (~aInputConversionFlags&EInputConversionFlagAllowTruncatedInputNotEvenPartlyConsumable))
  2814 	if ((pointerToCurrentUnicodeCharacter<=aUnicode.Ptr()) && (aOutputConversionFlags&EOutputConversionFlagInputIsTruncated) && (~aInputConversionFlags&EInputConversionFlagAllowTruncatedInputNotEvenPartlyConsumable))
  2590 		{
  2815 		{
  2591 		return EErrorIllFormedInput;
  2816 		return EErrorIllFormedInput;
  2592 		}
  2817 		}
  2618 SCnvConversionData objects into this parameter).
  2843 SCnvConversionData objects into this parameter).
  2619 @param aDefaultEndiannessOfForeignCharacters The default endian-ness of the 
  2844 @param aDefaultEndiannessOfForeignCharacters The default endian-ness of the 
  2620 foreign characters. If an endian-ness for foreign characters is specified 
  2845 foreign characters. If an endian-ness for foreign characters is specified 
  2621 in aConversionData, then that is used instead and the value of 
  2846 in aConversionData, then that is used instead and the value of 
  2622 aDefaultEndiannessOfForeignCharacters is ignored.
  2847 aDefaultEndiannessOfForeignCharacters is ignored.
  2623 @param aUnicode On return, contains the text converted into Unicode.
  2848 @param aUnicode On return, contains the text converted into Unicode.
  2624 @param aForeign The non-Unicode source text to be converted.
  2849 @param aForeign The non-Unicode source text to be converted.
  2625 @param aNumberOfUnconvertibleCharacters On return, contains the number of 
  2850 @param aNumberOfUnconvertibleCharacters On return, contains the number of 
  2626 characters in aForeign which were not converted. Characters which cannot be 
  2851 characters in aForeign which were not converted. Characters which cannot be 
  2627 converted are output as Unicode replacement characters (0xFFFD).
  2852 converted are output as Unicode replacement characters (0xFFFD).
  2628 @param aIndexOfFirstByteOfFirstUnconvertibleCharacter On return, the index 
  2853 @param aIndexOfFirstByteOfFirstUnconvertibleCharacter On return, the index 
  2673 SCnvConversionData objects into this parameter).
  2898 SCnvConversionData objects into this parameter).
  2674 @param aDefaultEndiannessOfForeignCharacters The default endian-ness of the 
  2899 @param aDefaultEndiannessOfForeignCharacters The default endian-ness of the 
  2675 foreign characters. If an endian-ness for foreign characters is specified 
  2900 foreign characters. If an endian-ness for foreign characters is specified 
  2676 in aConversionData, then that is used instead and the value of 
  2901 in aConversionData, then that is used instead and the value of 
  2677 aDefaultEndiannessOfForeignCharacters is ignored.
  2902 aDefaultEndiannessOfForeignCharacters is ignored.
  2678 @param aUnicode On return, contains the text converted into Unicode.
  2903 @param aUnicode On return, contains the text converted into Unicode.
  2679 @param aForeign The non-Unicode source text to be converted.
  2904 @param aForeign The non-Unicode source text to be converted.
  2680 @param aNumberOfUnconvertibleCharacters On return, contains the number of 
  2905 @param aNumberOfUnconvertibleCharacters On return, contains the number of 
  2681 characters in aForeign which were not converted. Characters which cannot be 
  2906 characters in aForeign which were not converted. Characters which cannot be 
  2682 converted are output as Unicode replacement characters (0xFFFD).
  2907 converted are output as Unicode replacement characters (0xFFFD).
  2683 @param aIndexOfFirstByteOfFirstUnconvertibleCharacter On return, the index 
  2908 @param aIndexOfFirstByteOfFirstUnconvertibleCharacter On return, the index 
  2728 		{
  2953 		{
  2729 		pointerToPreviousUnicodeCharacter+=aUnicode.Length();
  2954 		pointerToPreviousUnicodeCharacter+=aUnicode.Length();
  2730 		}
  2955 		}
  2731 	const TUint8* pointerToCurrentForeignByte=aForeign.Ptr();
  2956 	const TUint8* pointerToCurrentForeignByte=aForeign.Ptr();
  2732 	const TUint8* const pointerToLastForeignByte=pointerToCurrentForeignByte+(aForeign.Length()-1);
  2957 	const TUint8* const pointerToLastForeignByte=pointerToCurrentForeignByte+(aForeign.Length()-1);
       
  2958 	if (aConversionData.iForeignVariableByteData.iNumberOfRanges<=0)
       
  2959 	    {
       
  2960 	    OstTrace0( TRACE_DUMP, CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicBadNumberOfRanges2" );
       
  2961 	    }
  2733 	__ASSERT_DEBUG(aConversionData.iForeignVariableByteData.iNumberOfRanges>0, Panic(EPanicBadNumberOfRanges2));
  2962 	__ASSERT_DEBUG(aConversionData.iForeignVariableByteData.iNumberOfRanges>0, Panic(EPanicBadNumberOfRanges2));
  2734 	const SCnvConversionData::SVariableByteData::SRange* const foreignVariableByteData_firstRange=aConversionData.iForeignVariableByteData.iRangeArray;
  2963 	const SCnvConversionData::SVariableByteData::SRange* const foreignVariableByteData_firstRange=aConversionData.iForeignVariableByteData.iRangeArray;
  2735 	const SCnvConversionData::SVariableByteData::SRange* const foreignVariableByteData_lastRange=foreignVariableByteData_firstRange+(aConversionData.iForeignVariableByteData.iNumberOfRanges-1);
  2964 	const SCnvConversionData::SVariableByteData::SRange* const foreignVariableByteData_lastRange=foreignVariableByteData_firstRange+(aConversionData.iForeignVariableByteData.iNumberOfRanges-1);
       
  2965 	if (aConversionData.iForeignToUnicodeData.iNumberOfRanges<=0)
       
  2966 	    {
       
  2967 	    OstTrace0( TRACE_DUMP, DUP1_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicBadNumberOfRanges3" );
       
  2968 	    }
  2736 	__ASSERT_DEBUG(aConversionData.iForeignToUnicodeData.iNumberOfRanges>0, Panic(EPanicBadNumberOfRanges3));
  2969 	__ASSERT_DEBUG(aConversionData.iForeignToUnicodeData.iNumberOfRanges>0, Panic(EPanicBadNumberOfRanges3));
  2737 	const SCnvConversionData::SOneDirectionData::SRange* const oneDirectionData_firstRange=aConversionData.iForeignToUnicodeData.iRangeArray;
  2970 	const SCnvConversionData::SOneDirectionData::SRange* const oneDirectionData_firstRange=aConversionData.iForeignToUnicodeData.iRangeArray;
  2738 	const SCnvConversionData::SOneDirectionData::SRange* const oneDirectionData_lastRange=oneDirectionData_firstRange+(aConversionData.iForeignToUnicodeData.iNumberOfRanges-1);
  2971 	const SCnvConversionData::SOneDirectionData::SRange* const oneDirectionData_lastRange=oneDirectionData_firstRange+(aConversionData.iForeignToUnicodeData.iNumberOfRanges-1);
  2739 	FOREVER
  2972 	FOREVER
  2740 		{
  2973 		{
       
  2974 		if (pointerToPreviousUnicodeCharacter>pointerToLastUnicodeCharacter)
       
  2975 		    {
       
  2976 		    OstTrace0( TRACE_DUMP, DUP2_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit15" );
       
  2977 		    }
  2741 		__ASSERT_DEBUG(pointerToPreviousUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit15));
  2978 		__ASSERT_DEBUG(pointerToPreviousUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit15));
       
  2979 		if (pointerToCurrentForeignByte>pointerToLastForeignByte)
       
  2980 		    {
       
  2981 		    OstTrace0( TRACE_DUMP, DUP3_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit16" );
       
  2982 		    }
  2742 		__ASSERT_DEBUG(pointerToCurrentForeignByte<=pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit16));
  2983 		__ASSERT_DEBUG(pointerToCurrentForeignByte<=pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit16));
  2743 		TBool stop=EFalse;
  2984 		TBool stop=EFalse;
  2744 		TUint inputCharacterCode=*pointerToCurrentForeignByte;
  2985 		TUint inputCharacterCode=*pointerToCurrentForeignByte;
  2745 		const SCnvConversionData::SVariableByteData::SRange* foreignVariableByteData_currentRange=foreignVariableByteData_firstRange;
  2986 		const SCnvConversionData::SVariableByteData::SRange* foreignVariableByteData_currentRange=foreignVariableByteData_firstRange;
  2746 		FOREVER
  2987 		FOREVER
  2747 			{
  2988 			{
       
  2989 			if (foreignVariableByteData_currentRange->iNumberOfSubsequentBytes>=sizeof(TUint))
       
  2990 			    {
       
  2991 			    OstTrace0( TRACE_DUMP, DUP4_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicBadNumberOfSubsequentBytes" );
       
  2992 			    }
  2748 			__ASSERT_DEBUG(foreignVariableByteData_currentRange->iNumberOfSubsequentBytes<sizeof(TUint), Panic(EPanicBadNumberOfSubsequentBytes));
  2993 			__ASSERT_DEBUG(foreignVariableByteData_currentRange->iNumberOfSubsequentBytes<sizeof(TUint), Panic(EPanicBadNumberOfSubsequentBytes));
  2749 			if ((inputCharacterCode>=foreignVariableByteData_currentRange->iFirstInitialByteValueInRange) && (inputCharacterCode<=foreignVariableByteData_currentRange->iLastInitialByteValueInRange))
  2994 			if ((inputCharacterCode>=foreignVariableByteData_currentRange->iFirstInitialByteValueInRange) && (inputCharacterCode<=foreignVariableByteData_currentRange->iLastInitialByteValueInRange))
  2750 				{
  2995 				{
  2751 				const TInt numberOfSubsequentBytes=foreignVariableByteData_currentRange->iNumberOfSubsequentBytes;
  2996 				const TInt numberOfSubsequentBytes=foreignVariableByteData_currentRange->iNumberOfSubsequentBytes;
       
  2997 				if (pointerToCurrentForeignByte>pointerToLastForeignByte)
       
  2998 				    {
       
  2999 				    OstTrace0( TRACE_DUMP, DUP5_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit17" );
       
  3000 				    }
  2752 				__ASSERT_DEBUG(pointerToCurrentForeignByte<=pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit17));
  3001 				__ASSERT_DEBUG(pointerToCurrentForeignByte<=pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit17));
  2753 				if (pointerToLastForeignByte-pointerToCurrentForeignByte<numberOfSubsequentBytes)
  3002 				if (pointerToLastForeignByte-pointerToCurrentForeignByte<numberOfSubsequentBytes)
  2754 					{
  3003 					{
  2755 					aOutputConversionFlags|=EOutputConversionFlagInputIsTruncated;
  3004 					aOutputConversionFlags|=EOutputConversionFlagInputIsTruncated;
  2756 					goto end;
  3005 					goto end;
  2759 					{
  3008 					{
  2760 				case ELittleEndian:
  3009 				case ELittleEndian:
  2761 					{
  3010 					{
  2762 					for (TInt i=1; i<=numberOfSubsequentBytes; ++i)
  3011 					for (TInt i=1; i<=numberOfSubsequentBytes; ++i)
  2763 						{
  3012 						{
       
  3013 						if (pointerToCurrentForeignByte>=pointerToLastForeignByte)
       
  3014 						    {
       
  3015 						    OstTrace0( TRACE_DUMP, DUP6_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit18" );
       
  3016 						    }
  2764 						__ASSERT_DEBUG(pointerToCurrentForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit18));
  3017 						__ASSERT_DEBUG(pointerToCurrentForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit18));
  2765 						++pointerToCurrentForeignByte;
  3018 						++pointerToCurrentForeignByte;
  2766 						TUint currentForeignByte=*pointerToCurrentForeignByte;
  3019 						TUint currentForeignByte=*pointerToCurrentForeignByte;
  2767 						currentForeignByte<<=(i*8);
  3020 						currentForeignByte<<=(i*8);
  2768 						inputCharacterCode|=currentForeignByte;
  3021 						inputCharacterCode|=currentForeignByte;
  2771 					break;
  3024 					break;
  2772 				case EBigEndian:
  3025 				case EBigEndian:
  2773 					{
  3026 					{
  2774 					for (TInt i=numberOfSubsequentBytes; i>0; --i)
  3027 					for (TInt i=numberOfSubsequentBytes; i>0; --i)
  2775 						{
  3028 						{
       
  3029 						if (pointerToCurrentForeignByte>=pointerToLastForeignByte)
       
  3030 						    {
       
  3031 						    OstTrace0( TRACE_DUMP, DUP7_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit19" );
       
  3032 						    }
  2776 						__ASSERT_DEBUG(pointerToCurrentForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit19));
  3033 						__ASSERT_DEBUG(pointerToCurrentForeignByte<pointerToLastForeignByte, Panic(EPanicPointerPastUpperLimit19));
  2777 						++pointerToCurrentForeignByte;
  3034 						++pointerToCurrentForeignByte;
  2778 						inputCharacterCode<<=8;
  3035 						inputCharacterCode<<=8;
  2779 						inputCharacterCode|=*pointerToCurrentForeignByte;
  3036 						inputCharacterCode|=*pointerToCurrentForeignByte;
  2780 						}
  3037 						}
  2781 					}
  3038 					}
  2782 					break;
  3039 					break;
  2783 #if defined(_DEBUG)
  3040 #if defined(_DEBUG)
  2784 				default:
  3041 				default:
       
  3042 				    OstTrace0( TRACE_DUMP, DUP8_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicBadEndianness2" );
  2785 					Panic(EPanicBadEndianness2);
  3043 					Panic(EPanicBadEndianness2);
  2786 					break;
  3044 					break;
  2787 #endif
  3045 #endif
  2788 					}
  3046 					}
  2789 				pointerToCurrentForeignByte-=numberOfSubsequentBytes; // resets pointerToCurrentForeignByte to its value before the loop above
  3047 				pointerToCurrentForeignByte-=numberOfSubsequentBytes; // resets pointerToCurrentForeignByte to its value before the loop above
  2790 				break;
  3048 				break;
  2791 				}
  3049 				}
       
  3050 			if (foreignVariableByteData_currentRange>foreignVariableByteData_lastRange)
       
  3051 			    {
       
  3052 			    OstTrace0( TRACE_DUMP, DUP9_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit20" );
       
  3053 			    }
  2792 			__ASSERT_DEBUG(foreignVariableByteData_currentRange<=foreignVariableByteData_lastRange, Panic(EPanicPointerPastUpperLimit20));
  3054 			__ASSERT_DEBUG(foreignVariableByteData_currentRange<=foreignVariableByteData_lastRange, Panic(EPanicPointerPastUpperLimit20));
  2793 			if (foreignVariableByteData_currentRange>=foreignVariableByteData_lastRange)
  3055 			if (foreignVariableByteData_currentRange>=foreignVariableByteData_lastRange)
  2794 				{
  3056 				{
  2795 				return EErrorIllFormedInput;
  3057 				return EErrorIllFormedInput;
  2796 				}
  3058 				}
  2807 				if (outputCharacterCode!=KNoConversionAvailable)
  3069 				if (outputCharacterCode!=KNoConversionAvailable)
  2808 					{
  3070 					{
  2809 					break;
  3071 					break;
  2810 					}
  3072 					}
  2811 				}
  3073 				}
       
  3074 			if (oneDirectionData_currentRange>oneDirectionData_lastRange)
       
  3075 			    {
       
  3076 			    OstTrace0( TRACE_DUMP, DUP10_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit21" );
       
  3077 			    }
  2812 			__ASSERT_DEBUG(oneDirectionData_currentRange<=oneDirectionData_lastRange, Panic(EPanicPointerPastUpperLimit21));
  3078 			__ASSERT_DEBUG(oneDirectionData_currentRange<=oneDirectionData_lastRange, Panic(EPanicPointerPastUpperLimit21));
  2813 			if (oneDirectionData_currentRange>=oneDirectionData_lastRange)
  3079 			if (oneDirectionData_currentRange>=oneDirectionData_lastRange)
  2814 				{
  3080 				{
  2815 				break;
  3081 				break;
  2816 				}
  3082 				}
  2817 			++oneDirectionData_currentRange;
  3083 			++oneDirectionData_currentRange;
  2818 			}
  3084 			}
       
  3085 		if (pointerToPreviousUnicodeCharacter>pointerToLastUnicodeCharacter)
       
  3086 		    {
       
  3087 		    OstTrace0( TRACE_DUMP, DUP11_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit22" );
       
  3088 		    }
  2819 		__ASSERT_DEBUG(pointerToPreviousUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit22));
  3089 		__ASSERT_DEBUG(pointerToPreviousUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit22));
  2820 		if (pointerToPreviousUnicodeCharacter==pointerToLastUnicodeCharacter)
  3090 		if (pointerToPreviousUnicodeCharacter==pointerToLastUnicodeCharacter)
  2821 			{
  3091 			{
  2822 			goto end;
  3092 			goto end;
  2823 			}
  3093 			}
  2824 		if (outputCharacterCode==KNoConversionAvailable)
  3094 		if (outputCharacterCode==KNoConversionAvailable)
  2825 			{
  3095 			{
  2826 			outputCharacterCode=0xfffd; // Unicode's "REPLACEMENT CHARACTER"
  3096 			outputCharacterCode=0xfffd; // Unicode's "REPLACEMENT CHARACTER"
       
  3097 			if (aNumberOfUnconvertibleCharacters<0)
       
  3098 			    {
       
  3099 			    OstTrace0( TRACE_FATAL, DUP13_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicBadNumberOfUnconvertibleCharacters" );
       
  3100 			    }
  2827 			__ASSERT_ALWAYS(aNumberOfUnconvertibleCharacters>=0, Panic(EPanicBadNumberOfUnconvertibleCharacters));
  3101 			__ASSERT_ALWAYS(aNumberOfUnconvertibleCharacters>=0, Panic(EPanicBadNumberOfUnconvertibleCharacters));
  2828 			if (aNumberOfUnconvertibleCharacters<=0)
  3102 			if (aNumberOfUnconvertibleCharacters<=0)
  2829 				{
  3103 				{
  2830 				aIndexOfFirstByteOfFirstUnconvertibleCharacter=pointerToCurrentForeignByte-aForeign.Ptr();
  3104 				aIndexOfFirstByteOfFirstUnconvertibleCharacter=pointerToCurrentForeignByte-aForeign.Ptr();
  2831 				}
  3105 				}
  2840 			++pointerToPreviousUnicodeCharacter;
  3114 			++pointerToPreviousUnicodeCharacter;
  2841 			*pointerToPreviousUnicodeCharacter=STATIC_CAST(TUint16, outputCharacterCode);
  3115 			*pointerToPreviousUnicodeCharacter=STATIC_CAST(TUint16, outputCharacterCode);
  2842 			}
  3116 			}
  2843 		else
  3117 		else
  2844 			{
  3118 			{
       
  3119 			if (outputCharacterCode>=0x00110000)
       
  3120 			    {
       
  3121 			    OstTrace0( TRACE_DUMP, DUP12_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicBadNon16BitCharacterCode2" );
       
  3122 				}
  2845 			__ASSERT_DEBUG(outputCharacterCode<0x00110000, Panic(EPanicBadNon16BitCharacterCode2));
  3123 			__ASSERT_DEBUG(outputCharacterCode<0x00110000, Panic(EPanicBadNon16BitCharacterCode2));
       
  3124 			if (pointerToPreviousUnicodeCharacter>pointerToLastUnicodeCharacter)
       
  3125 			    {
       
  3126 			    OstTrace0( TRACE_DUMP, DUP14_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit23" );
       
  3127 			    }
  2846 			__ASSERT_DEBUG(pointerToPreviousUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit23));
  3128 			__ASSERT_DEBUG(pointerToPreviousUnicodeCharacter<=pointerToLastUnicodeCharacter, Panic(EPanicPointerPastUpperLimit23));
  2847 			if (pointerToLastUnicodeCharacter-pointerToPreviousUnicodeCharacter<2)
  3129 			if (pointerToLastUnicodeCharacter-pointerToPreviousUnicodeCharacter<2)
  2848 				{
  3130 				{
  2849 				goto end;
  3131 				goto end;
  2850 				}
  3132 				}
  2852 			++pointerToPreviousUnicodeCharacter;
  3134 			++pointerToPreviousUnicodeCharacter;
  2853 			*pointerToPreviousUnicodeCharacter=STATIC_CAST(TUint16, (outputCharacterCode>>10)|0xd800);
  3135 			*pointerToPreviousUnicodeCharacter=STATIC_CAST(TUint16, (outputCharacterCode>>10)|0xd800);
  2854 			++pointerToPreviousUnicodeCharacter;
  3136 			++pointerToPreviousUnicodeCharacter;
  2855 			*pointerToPreviousUnicodeCharacter=STATIC_CAST(TUint16, (outputCharacterCode&0x000003ff)|0xdc00);
  3137 			*pointerToPreviousUnicodeCharacter=STATIC_CAST(TUint16, (outputCharacterCode&0x000003ff)|0xdc00);
  2856 			}
  3138 			}
       
  3139 		if (pointerToLastForeignByte-pointerToCurrentForeignByte<foreignVariableByteData_currentRange->iNumberOfSubsequentBytes)
       
  3140 		    {
       
  3141 		    OstTrace0( TRACE_DUMP, DUP15_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastUpperLimit24" );
       
  3142 		    }
  2857 		__ASSERT_DEBUG(pointerToLastForeignByte-pointerToCurrentForeignByte>=foreignVariableByteData_currentRange->iNumberOfSubsequentBytes, Panic(EPanicPointerPastUpperLimit24));
  3143 		__ASSERT_DEBUG(pointerToLastForeignByte-pointerToCurrentForeignByte>=foreignVariableByteData_currentRange->iNumberOfSubsequentBytes, Panic(EPanicPointerPastUpperLimit24));
  2858 		pointerToCurrentForeignByte+=foreignVariableByteData_currentRange->iNumberOfSubsequentBytes;
  3144 		pointerToCurrentForeignByte+=foreignVariableByteData_currentRange->iNumberOfSubsequentBytes;
  2859 		if (pointerToCurrentForeignByte==pointerToLastForeignByte)
  3145 		if (pointerToCurrentForeignByte==pointerToLastForeignByte)
  2860 			{
  3146 			{
  2861 			++pointerToCurrentForeignByte; // this increment is done regardless of the test just above, but it's not done before the test as it may make pointerToCurrentForeignByte greater than pointerToLastForeignByte, and if pointerToLastForeignByte just happens to be pointing at 0xffffffff, will pointerToCurrentForeignByte will be pointing at 0x00000000, thus the test (which would now be "if (pointerToCurrentForeignByte>pointerToLastForeignByte)") would fail
  3147 			++pointerToCurrentForeignByte; // this increment is done regardless of the test just above, but it's not done before the test as it may make pointerToCurrentForeignByte greater than pointerToLastForeignByte, and if pointerToLastForeignByte just happens to be pointing at 0xffffffff, will pointerToCurrentForeignByte will be pointing at 0x00000000, thus the test (which would now be "if (pointerToCurrentForeignByte>pointerToLastForeignByte)") would fail
  2866 			{
  3152 			{
  2867 			goto end;
  3153 			goto end;
  2868 			}
  3154 			}
  2869 		}
  3155 		}
  2870 end:
  3156 end:
       
  3157     if (pointerToCurrentForeignByte<aForeign.Ptr())
       
  3158         {
       
  3159         OstTrace0( TRACE_DUMP, DUP16_CCNVCHARACTERSETCONVERTER_DOCONVERTTOUNICODE, "EPanicPointerPastLowerLimit2" );
       
  3160         }
  2871 	__ASSERT_DEBUG(pointerToCurrentForeignByte>=aForeign.Ptr(), Panic(EPanicPointerPastLowerLimit2));
  3161 	__ASSERT_DEBUG(pointerToCurrentForeignByte>=aForeign.Ptr(), Panic(EPanicPointerPastLowerLimit2));
  2872 	if ((pointerToCurrentForeignByte<=aForeign.Ptr()) && (aOutputConversionFlags&EOutputConversionFlagInputIsTruncated) && (~aInputConversionFlags&EInputConversionFlagAllowTruncatedInputNotEvenPartlyConsumable))
  3162 	if ((pointerToCurrentForeignByte<=aForeign.Ptr()) && (aOutputConversionFlags&EOutputConversionFlagInputIsTruncated) && (~aInputConversionFlags&EInputConversionFlagAllowTruncatedInputNotEvenPartlyConsumable))
  2873 		{
  3163 		{
  2874 		return EErrorIllFormedInput;
  3164 		return EErrorIllFormedInput;
  2875 		}
  3165 		}
  2958 
  3248 
  2959 #if defined(_DEBUG)
  3249 #if defined(_DEBUG)
  2960 			{
  3250 			{
  2961 			for(TInt j = arrayOfCharacterSetsAvailable->Count() - 1; j >= 0; --j)
  3251 			for(TInt j = arrayOfCharacterSetsAvailable->Count() - 1; j >= 0; --j)
  2962 				{
  3252 				{
       
  3253 				if ((*arrayOfCharacterSetsAvailable)[j].Identifier() == characterSetIdentifier)
       
  3254 				    {
       
  3255 				    OstTrace0( TRACE_DUMP, DUP1_CCNVCHARACTERSETCONVERTER_DOCREATEARRAYOFCHARACTERSETSAVAILABLELC, "EPanicCharacterSetAlreadyAdded" );
       
  3256 				    }
  2963 				__ASSERT_DEBUG((*arrayOfCharacterSetsAvailable)[j].Identifier() != characterSetIdentifier, Panic(EPanicCharacterSetAlreadyAdded));
  3257 				__ASSERT_DEBUG((*arrayOfCharacterSetsAvailable)[j].Identifier() != characterSetIdentifier, Panic(EPanicCharacterSetAlreadyAdded));
  2964 				}
  3258 				}
  2965 			}
  3259 			}
  2966 #endif
  3260 #endif
  2967 
  3261 
  2977 				}
  3271 				}
  2978 
  3272 
  2979 			characterSet.iName = implInfo->DisplayName().AllocLC();
  3273 			characterSet.iName = implInfo->DisplayName().AllocLC();
  2980 
  3274 
  2981 			arrayOfCharacterSetsAvailable->AppendL(characterSet);
  3275 			arrayOfCharacterSetsAvailable->AppendL(characterSet);
       
  3276 			
       
  3277 			OstTraceDefExt1( OST_TRACE_CATEGORY_PRODUCTION | OST_TRACE_CATEGORY_RND, TRACE_INTERNALS, 
       
  3278 			            CCNVCHARACTERSETCONVERTER_DOCREATEARRAYOFCHARACTERSETSAVAILABLELC, 
       
  3279 			             "%S Appended to Character Set Array",  *(characterSet.iName) );
  2982 
  3280 
  2983 			CleanupStack::Pop(characterSet.iName); //characterSet.iName
  3281 			CleanupStack::Pop(characterSet.iName); //characterSet.iName
  2984 			}
  3282 			}
  2985 
  3283 
  2986 			if(aIdentifierOfOnlyCharacterSetOfInterest == characterSetIdentifier)
  3284 			if(aIdentifierOfOnlyCharacterSetOfInterest == characterSetIdentifier)
  3091 CCnvCharacterSetConverter::DoPrepareToConvertToOrFromL(
  3389 CCnvCharacterSetConverter::DoPrepareToConvertToOrFromL(
  3092 								TUint aCharacterSetIdentifier, 
  3390 								TUint aCharacterSetIdentifier, 
  3093 								const CArrayFix<SCharacterSet>* aArrayOfCharacterSetsAvailable, 
  3391 								const CArrayFix<SCharacterSet>* aArrayOfCharacterSetsAvailable, 
  3094 								RFs& aFileServerSession)
  3392 								RFs& aFileServerSession)
  3095 	{
  3393 	{
       
  3394     OstTraceExt2( TRACE_DUMP, DUP3_CCNVCHARACTERSETCONVERTER_DOPREPARETOCONVERTTOORFROML, "Prepare to convert aCharacterSetIdentifier(0x%x) in aArrayOfCharacterSetsAvailable(0x%x)", aCharacterSetIdentifier, (unsigned int)aArrayOfCharacterSetsAvailable);
       
  3395     
  3096 	//AutoDetectCharacterSetL relies on the fact that this function does not use 
  3396 	//AutoDetectCharacterSetL relies on the fact that this function does not use 
  3097 	//aFileServerSession if aArrayOfCharacterSetsAvailable is *not* NULL and 
  3397 	//aFileServerSession if aArrayOfCharacterSetsAvailable is *not* NULL and 
  3098 	//if aCharacterSetIdentifier is *not* a data file
  3398 	//if aCharacterSetIdentifier is *not* a data file
  3099 	// aFileServerSession is no longer used load Plugin libraries. ECom framework used instead
  3399 	// aFileServerSession is no longer used load Plugin libraries. ECom framework used instead
  3100 	
  3400 	if (aCharacterSetIdentifier==0)
       
  3401 	    {
       
  3402 	    OstTrace0( TRACE_FATAL, CCNVCHARACTERSETCONVERTER_DOPREPARETOCONVERTTOORFROML, "EPanicNullCharacterSetIdentifier3" );
       
  3403 	    }
  3101 	__ASSERT_ALWAYS(aCharacterSetIdentifier!=0, Panic(EPanicNullCharacterSetIdentifier3));
  3404 	__ASSERT_ALWAYS(aCharacterSetIdentifier!=0, Panic(EPanicNullCharacterSetIdentifier3));
  3102 	if (iCharacterSetIdentifierOfLoadedConversionData!=aCharacterSetIdentifier)
  3405 	if (iCharacterSetIdentifierOfLoadedConversionData!=aCharacterSetIdentifier)
  3103 		{
  3406 		{
  3104 
  3407 
  3105 		TUint newStoredFlags=0;
  3408 		TUint newStoredFlags=0;
  3165 					return ENotAvailable;
  3468 					return ENotAvailable;
  3166 					}
  3469 					}
  3167 				const SCharacterSet& characterSet=(*aArrayOfCharacterSetsAvailable)[i];
  3470 				const SCharacterSet& characterSet=(*aArrayOfCharacterSetsAvailable)[i];
  3168 				if (characterSet.Identifier()==aCharacterSetIdentifier)
  3471 				if (characterSet.Identifier()==aCharacterSetIdentifier)
  3169 					{
  3472 					{
       
  3473 					if (!characterSet.NameIsFileName())
       
  3474 					    {
       
  3475 					    OstTrace0( TRACE_DUMP, DUP1_CCNVCHARACTERSETCONVERTER_DOPREPARETOCONVERTTOORFROML, "EPanicNameIsNotFileName" );
       
  3476 					    }
  3170 					__ASSERT_DEBUG(characterSet.NameIsFileName(), Panic(EPanicNameIsNotFileName));
  3477 					__ASSERT_DEBUG(characterSet.NameIsFileName(), Panic(EPanicNameIsNotFileName));
  3171 					if (characterSet.FileIsConversionPlugInLibrary())
  3478 					if (characterSet.FileIsConversionPlugInLibrary())
  3172 						{
  3479 						{
  3173 						newStoredFlags|=EStoredFlagConversionPlugInLibraryIsLoaded;
  3480 						newStoredFlags|=EStoredFlagConversionPlugInLibraryIsLoaded;
  3174 						
  3481 						
  3178 						}
  3485 						}
  3179 					else
  3486 					else
  3180 						{
  3487 						{
  3181 						//You are here?! This should never happen! Source code here was related to
  3488 						//You are here?! This should never happen! Source code here was related to
  3182 						//old type character set converter data!
  3489 						//old type character set converter data!
       
  3490 						OstTrace0( TRACE_FATAL, DUP2_CCNVCHARACTERSETCONVERTER_DOPREPARETOCONVERTTOORFROML, "EPanicCharacterSetNotPresent" );
  3183  						__ASSERT_ALWAYS(EFalse, Panic(EPanicCharacterSetNotPresent));
  3491  						__ASSERT_ALWAYS(EFalse, Panic(EPanicCharacterSetNotPresent));
  3184 						}
  3492 						}
  3185 					break;
  3493 					break;
  3186 					}
  3494 					}
  3187 				}
  3495 				}
  3201 
  3509 
  3202 LOCAL_C void DeleteOneDirectionData(
  3510 LOCAL_C void DeleteOneDirectionData(
  3203 								TInt aNumberOfRanges, 
  3511 								TInt aNumberOfRanges, 
  3204 								const SCnvConversionData::SOneDirectionData::SRange* aRange)
  3512 								const SCnvConversionData::SOneDirectionData::SRange* aRange)
  3205 	{
  3513 	{
       
  3514 	if ( !((aRange!=NULL) || (aNumberOfRanges==0)) )
       
  3515 	    {
       
  3516 	    OstTrace0( TRACE_DUMP, _DELETEONEDIRECTIONDATA, "EPanicBadNumberOfRanges4" );
       
  3517 	    }
  3206 	__ASSERT_DEBUG((aRange!=NULL) || (aNumberOfRanges==0), Panic(EPanicBadNumberOfRanges4));
  3518 	__ASSERT_DEBUG((aRange!=NULL) || (aNumberOfRanges==0), Panic(EPanicBadNumberOfRanges4));
  3207 	if (aRange!=NULL)
  3519 	if (aRange!=NULL)
  3208 		{
  3520 		{
       
  3521 		if (aNumberOfRanges<=0)
       
  3522 		    {
       
  3523 		    OstTrace0( TRACE_DUMP, DUP1__DELETEONEDIRECTIONDATA, "EPanicBadNumberOfRanges5" );
       
  3524 		    }
  3209 		__ASSERT_DEBUG(aNumberOfRanges>0, Panic(EPanicBadNumberOfRanges5));
  3525 		__ASSERT_DEBUG(aNumberOfRanges>0, Panic(EPanicBadNumberOfRanges5));
  3210 		SCnvConversionData::SOneDirectionData::SRange* currentRange=CONST_CAST(SCnvConversionData::SOneDirectionData::SRange*, aRange);
  3526 		SCnvConversionData::SOneDirectionData::SRange* currentRange=CONST_CAST(SCnvConversionData::SOneDirectionData::SRange*, aRange);
  3211 		const SCnvConversionData::SOneDirectionData::SRange* const lastRange=currentRange+(aNumberOfRanges-1);
  3527 		const SCnvConversionData::SOneDirectionData::SRange* const lastRange=currentRange+(aNumberOfRanges-1);
  3212 		FOREVER
  3528 		FOREVER
  3213 			{
  3529 			{
  3232 				break;
  3548 				break;
  3233 			case SCnvConversionData::SOneDirectionData::SRange::EKeyedTable16OfIndexedTables16:
  3549 			case SCnvConversionData::SOneDirectionData::SRange::EKeyedTable16OfIndexedTables16:
  3234 				// fall through
  3550 				// fall through
  3235 #if defined(_DEBUG)
  3551 #if defined(_DEBUG)
  3236 			default:
  3552 			default:
       
  3553 			    OstTrace0( TRACE_FATAL, DUP2__DELETEONEDIRECTIONDATA, "EPanicBadAlgorithm2" );
  3237 				Panic(EPanicBadAlgorithm2);
  3554 				Panic(EPanicBadAlgorithm2);
  3238 #endif
  3555 #endif
  3239 				break;
  3556 				break;
  3240 				}
  3557 				}
       
  3558 			if (currentRange>lastRange)
       
  3559 			    {
       
  3560 			    OstTrace0( TRACE_DUMP, DUP3__DELETEONEDIRECTIONDATA, "EPanicPointerPastUpperLimit25" );
       
  3561 			    }
  3241 			__ASSERT_DEBUG(currentRange<=lastRange, Panic(EPanicPointerPastUpperLimit25));
  3562 			__ASSERT_DEBUG(currentRange<=lastRange, Panic(EPanicPointerPastUpperLimit25));
  3242 			if (currentRange==lastRange)
  3563 			if (currentRange==lastRange)
  3243 				{
  3564 				{
  3244 				break;
  3565 				break;
  3245 				}
  3566 				}
  3278 		return ELittleEndian;
  3599 		return ELittleEndian;
  3279 	case SCnvConversionData::EFixedBigEndian:
  3600 	case SCnvConversionData::EFixedBigEndian:
  3280 		return EBigEndian;
  3601 		return EBigEndian;
  3281 		}
  3602 		}
  3282 #if defined(_DEBUG)
  3603 #if defined(_DEBUG)
       
  3604 	OstTrace0( TRACE_DUMP, CCNVCHARACTERSETCONVERTER_ENDIANNESSOFFOREIGNCHARACTERS, "EPanicBadEndianness3" );
  3283 	Panic(EPanicBadEndianness3);
  3605 	Panic(EPanicBadEndianness3);
  3284 #endif
  3606 #endif
  3285 	return ELittleEndian; // dummy return to prevent compiler error
  3607 	return ELittleEndian; // dummy return to prevent compiler error
  3286 	}
  3608 	}
  3287 
  3609 
  3297 @return EAppendFailed if the append failed, or
  3619 @return EAppendFailed if the append failed, or
  3298 EAppendSuccessful if it succeeded. */
  3620 EAppendSuccessful if it succeeded. */
  3299 EXPORT_C CCnvCharacterSetConverter::TArrayOfAscendingIndices::TAppendResult 
  3621 EXPORT_C CCnvCharacterSetConverter::TArrayOfAscendingIndices::TAppendResult 
  3300 CCnvCharacterSetConverter::TArrayOfAscendingIndices::AppendIndex(TInt aIndex)
  3622 CCnvCharacterSetConverter::TArrayOfAscendingIndices::AppendIndex(TInt aIndex)
  3301  	{
  3623  	{
       
  3624  	if ( aIndex<0 )
       
  3625  	    {
       
  3626  	    OstTrace1( TRACE_DUMP, DUP2_TARRAYOFASCENDINGINDICES_APPENDINDEX, "Bad index in TArrayOfAscendingIndices::AppendIndex;aIndex=%d", aIndex );    
       
  3627  	    }
  3302 	__ASSERT_DEBUG(aIndex>=0, Panic(EPanicBadIndex));
  3628 	__ASSERT_DEBUG(aIndex>=0, Panic(EPanicBadIndex));
  3303 	const TInt lengthOfArrayOfIndices=iArrayOfIndices.Length();
  3629 	const TInt lengthOfArrayOfIndices=iArrayOfIndices.Length();
  3304 	if ((aIndex>STATIC_CAST(TInt, KMaxTUint16)) || (lengthOfArrayOfIndices==iArrayOfIndices.MaxLength()))
  3630 	if ((aIndex>STATIC_CAST(TInt, KMaxTUint16)) || (lengthOfArrayOfIndices==iArrayOfIndices.MaxLength()))
  3305 		{
  3631 		{
  3306 		return EAppendFailed;
  3632 		return EAppendFailed;
  3307 		}
  3633 		}
       
  3634 	if ( (lengthOfArrayOfIndices!=0) && (iArrayOfIndices[lengthOfArrayOfIndices-1]>=aIndex))
       
  3635 	    {
       
  3636 	    OstTrace1( TRACE_DUMP, DUP1_TARRAYOFASCENDINGINDICES_APPENDINDEX, "Duplicate Index Or Not Ascending in TArrayOfAscendingIndices::AppendIndex;aIndex=%d", aIndex );
       
  3637 	    }
  3308 	__ASSERT_DEBUG((lengthOfArrayOfIndices==0) || (iArrayOfIndices[lengthOfArrayOfIndices-1]<aIndex), Panic(EPanicDuplicateIndexOrNotAscending));
  3638 	__ASSERT_DEBUG((lengthOfArrayOfIndices==0) || (iArrayOfIndices[lengthOfArrayOfIndices-1]<aIndex), Panic(EPanicDuplicateIndexOrNotAscending));
  3309 	iArrayOfIndices.Append(aIndex);
  3639 	iArrayOfIndices.Append(aIndex);
  3310 	return EAppendSuccessful;
  3640 	return EAppendSuccessful;
  3311 	}
  3641 	}
  3312 	
  3642 	
  3328 @panic User::Invariant() if the new max cache size is less than 4.
  3658 @panic User::Invariant() if the new max cache size is less than 4.
  3329 @see CCnvCharacterSetConverter::AutoDetectCharSetL
  3659 @see CCnvCharacterSetConverter::AutoDetectCharSetL
  3330 */
  3660 */
  3331 EXPORT_C void CCnvCharacterSetConverter::SetMaxCacheSize(TInt aSize)
  3661 EXPORT_C void CCnvCharacterSetConverter::SetMaxCacheSize(TInt aSize)
  3332     {
  3662     {
       
  3663     if ( aSize < CCharsetCnvCache::KMinCacheSize )
       
  3664         {
       
  3665         OstTrace1( TRACE_FATAL, CCNVCHARACTERSETCONVERTER_SETMAXCACHESIZE, "Parameter aSize < KMinCacheSize in CCnvCharacterSetConverter::SetMaxCacheSize;aSize=%d", aSize );
       
  3666         }
  3333     __ASSERT_ALWAYS(aSize >= CCharsetCnvCache::KMinCacheSize, User::Invariant());
  3667     __ASSERT_ALWAYS(aSize >= CCharsetCnvCache::KMinCacheSize, User::Invariant());
  3334     iCharsetCnvCache->SetMaxSize(aSize);
  3668     iCharsetCnvCache->SetMaxSize(aSize);
  3335     }
  3669     }
  3336 
  3670