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