コード例 #1
0
/**
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0536
@SYMTestCaseDesc        Splitting and converting from Unicode to EucJpPacked test
@SYMTestPriority        Medium
@SYMTestActions         Tests for conversion after splitting, from Unicode to EucJpPacked and back to Unicode
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
void CT_EUCJP_PACKED_2::TestSplittingConvertingFromUnicodeToEucJpPacked(CCnvCharacterSetConverter& aCharacterSetConverter, TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit, TInt aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfEucJpPacked, const TDesC8& aExpectedEucJpPacked, const TDesC16& aOriginalUnicode)
	{
	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0536 "));
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
	test(aMaximumLengthUpperLimit<=KBufferLength);
	TUint8 eucJpPackedBuffer[KBufferLength];
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
		{
		TPtr8 generatedFirstPartOfEucJpPacked(eucJpPackedBuffer, i);
		test(aCharacterSetConverter.ConvertFromUnicode(generatedFirstPartOfEucJpPacked, aOriginalUnicode)==aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit);
		test(generatedFirstPartOfEucJpPacked==aExpectedEucJpPacked.Left(aExpectedLengthOfFirstPartOfEucJpPacked));
		TBuf8<KBufferLength> generatedSecondPartOfEucJpPacked;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfEucJpPacked, aOriginalUnicode.Right(aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit))==0);
		test(generatedSecondPartOfEucJpPacked==aExpectedEucJpPacked.Mid(aExpectedLengthOfFirstPartOfEucJpPacked));
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		TBuf16<KBufferLength> generatedUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedFirstPartOfEucJpPacked, state)==0);
		test(state==CCnvCharacterSetConverter::KStateDefault);
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, generatedSecondPartOfEucJpPacked, state)==0);
		test(state==CCnvCharacterSetConverter::KStateDefault);
		generatedUnicode.Append(generatedSecondPartOfUnicode);
		test(generatedUnicode==aOriginalUnicode);
		}
	}
コード例 #2
0
void CT_ISO2022JP1_2::TestSplittingConvertingFromUnicodeToIso2022Jp(
                CCnvCharacterSetConverter& aCharacterSetConverter,
                TInt aMaximumLengthLowerLimit,
                TInt aMaximumLengthUpperLimit,
                TInt aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit,
                const TDesC8& aExpectedFirstPartOfIso2022Jp,
                const TDesC8& aExpectedSecondPartOfIso2022Jp,
                const TDesC16& aOriginalUnicode)
	{
	INFO_PRINTF1(_L(" TestTruncatedConversionFromUnicodeToIso2022Jp "));
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
	test(aMaximumLengthUpperLimit<=KBufferLength);
	TUint8 iso2022JpBuffer[KBufferLength];
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
		{
		TPtr8 generatedFirstPartOfIso2022Jp(iso2022JpBuffer, i);
		test(aCharacterSetConverter.ConvertFromUnicode(generatedFirstPartOfIso2022Jp, aOriginalUnicode)==aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit);
		test(generatedFirstPartOfIso2022Jp==aExpectedFirstPartOfIso2022Jp);
		TBuf8<KBufferLength> generatedSecondPartOfIso2022Jp;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfIso2022Jp, aOriginalUnicode.Right(aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit))==0);
		test(generatedSecondPartOfIso2022Jp==aExpectedSecondPartOfIso2022Jp);
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		TBuf16<KBufferLength> generatedUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedFirstPartOfIso2022Jp, state)==0);
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, generatedSecondPartOfIso2022Jp, state)==0);
		generatedUnicode.Append(generatedSecondPartOfUnicode);
		test(generatedUnicode==aOriginalUnicode);
		}
	}
コード例 #3
0
ファイル: rhodesAppView.cpp プロジェクト: 3runo5ouza/rhodes
void CRhodesAppView::InitOptions()
	{
		char* slash = "";
		char* options_page = callGetOptionsPage();
		if (!options_page) {
		options_page = "";
		} else if ( (*options_page!='/')&&(*options_page!='\\') ) {
			slash = "/";
		}
		int len = strlen(get_home_url())+strlen(slash)+strlen(options_page);
		char* sp = (char*) malloc(len+1);
		sprintf(sp,"%s%s%s",get_home_url(),slash,options_page);

		RFs session;
		User::LeaveIfError(session.Connect());
		
		CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewL();
	  	converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, session);
	  
	  	TPtrC8 ptr((const unsigned char*)sp);

	  	int state = CCnvCharacterSetConverter::KStateDefault;
	  	converter->ConvertToUnicode(iOptionsPage, ptr, state);
		
	  	session.Close();
	  	
		free(sp);
	}
コード例 #4
0
ファイル: os_symbian.cpp プロジェクト: evlinsky/FBReader
void ConvertToUnicode(RFs session, TDes16& aUnicode, const char *str)
{
  CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewL();
  converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, session);
  
  TPtrC8 ptr((const unsigned char*)str);

  int state = CCnvCharacterSetConverter::KStateDefault;
  converter->ConvertToUnicode(aUnicode, ptr, state);
}
コード例 #5
0
HBufC8* CRecogStep::ConvertDes16toHBufC8LC(TDesC& source)
	{
	HBufC8 *buf = HBufC8::NewL(source.Length());
	CleanupStack::PushL(buf);
	TPtr8 ptr=buf->Des();

	CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewLC();
	converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierAscii, iTheFs);
	converter->ConvertFromUnicode(ptr, source);
	CleanupStack::PopAndDestroy(converter);
	return buf;
	}
コード例 #6
0
/**
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0537
@SYMTestCaseDesc        Tests for truncated conversion from EucJpPacked to Unicode
@SYMTestPriority        Medium
@SYMTestActions         Tests for truncated conversion from EucJpPacked to Unicode and back to EucJpPacked
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
void CT_EUCJP_PACKED_2::TestTruncatedConversionToUnicodeFromEucJpPacked(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalEucJpPacked)
	{
	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0537 "));
	for (TInt i=aOriginalEucJpPacked.Length(); i>=3; --i) // 3 is the length of GBK's longest multi-byte characters
		{
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		TBuf16<KBufferLength> generatedUnicode;
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalEucJpPacked.Left(i), state);
		test(returnValue>=0);
		TBuf16<KBufferLength> generatedsecondPartOfUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedsecondPartOfUnicode, aOriginalEucJpPacked.Mid(i-returnValue), state)==0);
		generatedUnicode.Append(generatedsecondPartOfUnicode);
		test(generatedUnicode==aExpectedUnicode);
		}
	}
コード例 #7
0
void CT_ISO2022JP1_2::TestConversionFromUnicodeToIso(
                CCnvCharacterSetConverter& aCharacterSetConverter,
                const TDesC16& aOriginalUnicode)
 	{
	INFO_PRINTF1(_L(" TestConversionFromUnicodeToIso "));
 	TBuf8<KNotEnoughBufferLength> generatedIso2022Jp;
	generatedIso2022Jp.FillZ(KNotEnoughBufferLength);
 	const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedIso2022Jp, aOriginalUnicode);
 	test(returnValue>=0);
 	TInt state=CCnvCharacterSetConverter::KStateDefault;
 	TBuf16<KBufferLength> generatedUnicode;
	TInt testresult;
	testresult=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedIso2022Jp, state);
 	test(testresult==0);
 //	test(generatedUnicode==aOriginalUnicode);
 	}
コード例 #8
0
void CLocaLogicImpl::ConstructL()
{
	CALLSTACKITEM_N(_CL("CLocaLogicImpl"), _CL("ConstructL"));

	iDevStats=CDevStats::NewL(AppContext(), iDb);
	iMessageStats=CMessageStats::NewL(AppContext(), iDb);
	iRemote=CLocaRemoteEvents::NewL(AppContext(), this);
	iAcceptedMessages=CAcceptedMsgs::NewL(iDb);

	iBBSubSession=BBSession()->CreateSubSessionL(this);
	iBBSubSession->AddNotificationL(KLocaScriptTuple, ETrue);

	iEvent.iData.SetValue(&iMsgStatus);
	iEvent.iData.SetOwnsValue(EFalse);
	iEvent.iPriority()=CBBSensorEvent::VALUE;

	GetSettingsL();

	Settings().NotifyOnChange(SETTING_LOCA_BLUEJACK_MAX_MESSAGES, this);
	Settings().NotifyOnChange(SETTING_LOCA_BLUEJACK_MAX_RETRIES, this);
	Settings().NotifyOnChange(SETTING_PUBLISH_AUTHOR, this);

	iInterpreter = CSPyInterpreter::NewInterpreterL();
	iCC=CCnvCharacterSetConverter::NewL();
	iCC->PrepareToConvertToOrFromL(KCharacterSetIdentifierIso88591, Fs());
	iFunctions=new (ELeave) CDesC8ArraySeg(4);
	iErrorFunctions=new (ELeave) CDesC8ArraySeg(4);
}
コード例 #9
0
void CLocaLogicImpl::DeletedL(const TTupleName& aName, const TDesC& aSubName)
{
	if (aName==KLocaScriptTuple) {
		if (aSubName.Length()>0 && aSubName[0]!='_') {
			TInterpreterAutoLock interpr;
			// borrowed
			PyObject* main_module = PyImport_AddModule("__main__");
			if (! main_module ) return;
			// borrowed
			PyObject* global_dict = PyModule_GetDict(main_module);
			if (! global_dict ) return;

			auto_ptr<HBufC8> subname8(HBufC8::NewL(aSubName.Length()+10));
			TPtr8 p=subname8->Des();
			TInt err=KErrNone;
			TInt unconverted=0, unconverted_pos=0;
			err=iCC->ConvertFromUnicode(p, aSubName, unconverted, unconverted_pos);
			if (err!=KErrNone || unconverted!=0) return;
			subname8->Des().Append('\0');

			PyDict_DelItemString(global_dict, (char*)subname8->Ptr());
			TInt pos;
			DeleteFromArrayL(iFunctions, *subname8);
			DeleteFromArrayL(iErrorFunctions, *subname8);
		}
	}
}
コード例 #10
0
/**
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0535
@SYMTestCaseDesc        Tests for truncated conversion from Unicode to EucJpPacked
@SYMTestPriority        Medium
@SYMTestActions         Tests for truncated conversion from Unicode to EucJpPacked and back to Unicode
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
void CT_EUCJP_PACKED_2::TestTruncatedConversionFromUnicodeToEucJpPacked(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode)
	{
	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0535 "));
	for (TInt i=aOriginalUnicode.Length(); i>=0; --i)
		{
		TBuf8<KBufferLength> generatedEucJpPacked;
		const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedEucJpPacked, aOriginalUnicode.Left(i));
		test(returnValue>=0);
		TBuf8<KBufferLength> generatedsecondPartOfEucJpPacked;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedsecondPartOfEucJpPacked, aOriginalUnicode.Mid(i-returnValue))==0);
		generatedEucJpPacked.Append(generatedsecondPartOfEucJpPacked);
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		TBuf16<KBufferLength> generatedUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedEucJpPacked, state)==0);
		test(generatedUnicode==aOriginalUnicode);
		}
	}
コード例 #11
0
void CT_ISO2022JP1_2::TestTruncatedConversionToUnicodeFromIso2022Jp(
                CCnvCharacterSetConverter& aCharacterSetConverter,
                const TDesC16& aExpectedUnicode,
                const TDesC8& aOriginalIso2022Jp)
	{
	INFO_PRINTF1(_L(" TestTruncatedConversionToUnicodeFromIso2022Jp "));
	for (TInt i=aOriginalIso2022Jp.Length(); i>=3; --i) // 3 is the length of ISO-2022-JP's longest escape sequence
		{
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		TBuf16<KBufferLength> generatedUnicode;
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalIso2022Jp.Left(i), state);
		test(returnValue>=0);
		TBuf16<KBufferLength> generatedsecondPartOfUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedsecondPartOfUnicode, aOriginalIso2022Jp.Mid(i-returnValue), state)==0);
		generatedUnicode.Append(generatedsecondPartOfUnicode);
		test(generatedUnicode==aExpectedUnicode);
		}
	}
コード例 #12
0
ファイル: formats.cpp プロジェクト: fgroen/ayfly
TFileName ay_sys_getstr(const unsigned char *str, unsigned long length)
{
    CCnvCharacterSetConverter *aCharacterSetConverter = CCnvCharacterSetConverter::NewL();
    RFs aFileServerSession;
    TUint aForeignCharacterSet = KCharacterSetIdentifierAscii;
    // check to see if the character set is supported - if not then leave
    if (aCharacterSetConverter->PrepareToConvertToOrFromL(aForeignCharacterSet,
                    aFileServerSession) != CCnvCharacterSetConverter::EAvailable)
    User::Leave(KErrNotSupported);
    // Create a small output buffer 
    TBuf16<20> outputBuffer;
    TFileName endBuffer;
    // Create a buffer for the unconverted text - initialised with the input descriptor
    TPtrC8 remainderOfForeignText(str, length);
    // Create a "state" variable and initialise it with CCnvCharacterSetConverter::KStateDefault
    // After initialisation the state variable must not be tampered with.
    // Simply pass into each subsequent call of ConvertToUnicode()
    TInt state=CCnvCharacterSetConverter::KStateDefault;
    for(;;) // conversion loop

    {
        // Start conversion. When the output buffer is full, return the number
        // of characters that were not converted
        const TInt returnValue=aCharacterSetConverter->ConvertToUnicode(outputBuffer, remainderOfForeignText, state);
        // check to see that the descriptor isn�t corrupt - leave if it is
        if (returnValue==CCnvCharacterSetConverter::EErrorIllFormedInput)
        User::Leave(KErrCorrupt);
        else if (returnValue<0) // future-proof against "TError" expanding
        User::Leave(KErrGeneral);

        // Do something here to store the contents of the output buffer.
        // Finish conversion if there are no unconverted 
        // characters in the remainder buffer
        endBuffer += outputBuffer;
        if (returnValue==0)
        break;
        
        // Remove converted source text from the remainder buffer.
        // The remainder buffer is then fed back into loop
        remainderOfForeignText.Set(remainderOfForeignText.Right(returnValue));
    }
    delete aCharacterSetConverter;
    return endBuffer;
}
コード例 #13
0
void CT_ISO2022JP1_2::TestTruncatedConversionFromUnicodeToIso2022Jp(
                CCnvCharacterSetConverter& aCharacterSetConverter,
                const TDesC16& aOriginalUnicode)
	{
	INFO_PRINTF1(_L(" TestTruncatedConversionFromUnicodeToIso2022Jp "));
	for (TInt i=aOriginalUnicode.Length(); i>=0; --i)
		{
		TBuf8<KBufferLength> generatedIso2022Jp;
		const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedIso2022Jp, aOriginalUnicode.Left(i));
		test(returnValue>=0);
		TBuf8<KBufferLength> generatedsecondPartOfIso2022Jp;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedsecondPartOfIso2022Jp, aOriginalUnicode.Mid(i-returnValue))==0);
		generatedIso2022Jp.Append(generatedsecondPartOfIso2022Jp);
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		TBuf16<KBufferLength> generatedUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedIso2022Jp, state)==0);
		test(generatedUnicode==aOriginalUnicode);
		}
	}
コード例 #14
0
//
//将中文字符转换成Unicode	
HBufC16* CCommonUtils::ConvertToUnicodeFromGBK(const TText8* aStr)
{	
	CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();

	if( converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGbk,CEikonEnv::Static()->FsSession()) != CCnvCharacterSetConverter::EAvailable)
	{
		delete converter;
		return NULL;
	}

	//TText8  *str = (TText8*)"诺基亚7650C";
	TInt state= CCnvCharacterSetConverter::KStateDefault;

	TPtrC8 source( aStr );
	HBufC* ret = HBufC::NewLC( source.Length() );
	TPtr16 ptr = ret->Des();
	converter->ConvertToUnicode(ptr, source, state);
	CleanupStack::Pop(ret);

	return ret;
}
コード例 #15
0
// -----------------------------------------------------------------------------
// CSTSPinConverter::ConvertToUTF8L
//
// -----------------------------------------------------------------------------
void CSTSPinConverter::ConvertToUTF8L(const TDesC& aPinValue,
                                      TPtr8& aConvertedPIN, TBool aUpperCase)
{

    // RFs for CCnvCharacterSetConverter
    RFs fsSession;
    User::LeaveIfError(fsSession.Connect());
    CleanupClosePushL(fsSession);

    CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();

    // transform pin to UTF8
    if (converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8,
            fsSession) != CCnvCharacterSetConverter::EAvailable)
    {
        User::Leave(KErrNotSupported);
    }

    TInt error = converter->ConvertFromUnicode(aConvertedPIN, aPinValue);

    // check to see that the descriptor isn’t corrupt - leave if it is
    if (error == CCnvCharacterSetConverter::EErrorIllFormedInput)
    {
        User::Leave(KErrCorrupt);
    }
    if (error < 0)
    {
        User::Leave(KErrGeneral);
    }

    //convert to uppercase
    if (aUpperCase)
    {
        aConvertedPIN.UpperCase();
    }

    CleanupStack::PopAndDestroy(converter);
    CleanupStack::PopAndDestroy(&fsSession);

}
コード例 #16
0
// ============================================================================
// CWidgetBackupRegistryXml::FromUnicodeL
// Utility to bundle transcoding to unicode steps.
//
// @since 5.0
// @param aEncoding input buffer encoding
// @param aUnicodeSizeMultiplier how many bytes of input make one unicode char
// @param aInBuf input data in encoding
// @param aOutBuf malloc'ed output buf, caller takes ownership
// @param aFileSession CCnvCharacterSetConverter requires it
// ============================================================================
//
void CWidgetBackupRegistryXml::FromUnicodeL( TInt aEncoding,
                                     TInt aUnicodeSizeMultiplier,
                                     TPtrC16 aInBuf, HBufC8** aOutBuf,
                                     RFs& aFileSession )
    {
    *aOutBuf = NULL;

    // outbuf sizing and alloction
    HBufC8* outBuf = HBufC8::NewLC(aUnicodeSizeMultiplier * (aInBuf.Length() + 1));
    TPtr8 outPtr = outBuf->Des();

    // convert from unicode
    CCnvCharacterSetConverter* charConv = CCnvCharacterSetConverter::NewLC();
    charConv->PrepareToConvertToOrFromL( aEncoding, aFileSession );
    User::LeaveIfError(
        charConv->ConvertFromUnicode( outPtr, aInBuf));
    outPtr.ZeroTerminate();
    CleanupStack::PopAndDestroy( charConv );

    CleanupStack::Pop( outBuf ); 
    *aOutBuf = outBuf;
    }
コード例 #17
0
// ============================================================================
// CWidgetUIConfigHandler::ToUnicodeL
// Utility to bundle transcoding to unicode steps.
//
// @since 3.1
// @param aEncoding input buffer encoding
// @param aUnicodeSizeMultiplier how many bytes of input make one unicode char
// @param aInBuf input data in encoding
// @param aOutBuf malloc'ed output buf, caller takes ownership
// @param aFileSession CCnvCharacterSetConverter requires it
// ============================================================================
//
void CWidgetUIConfigHandler::ToUnicodeL( TInt aEncoding,
                                         TInt aUnicodeSizeMultiplier,
                                         TPtrC8 aInBuf, HBufC16** aOutBuf,
                                         RFs& aFileSession )
    {
    *aOutBuf = NULL;

    // outbuf sizing and alloction
    HBufC16* outBuf = HBufC16::NewLC(aUnicodeSizeMultiplier * aInBuf.Length());
    TPtr16 outPtr = outBuf->Des();

    // convert to unicode
    CCnvCharacterSetConverter* charConv = CCnvCharacterSetConverter::NewLC();
    charConv->PrepareToConvertToOrFromL( aEncoding, aFileSession );
    TInt state = CCnvCharacterSetConverter::KStateDefault;
    TInt rep = 0; // number of unconvertible characters
    TInt rIndx = 0; // index of first unconvertible character
    User::LeaveIfError(
        charConv->ConvertToUnicode( outPtr, aInBuf, state, rep, rIndx ) );
    CleanupStack::PopAndDestroy( charConv );

    CleanupStack::Pop(); // outBuf
    *aOutBuf = outBuf;
    }
コード例 #18
0
void CLocaLogicImpl::ConvertFromPythonString(TDes& aBuf, PyObject* aString)
{
	aBuf.Zero();
	if (PyString_Check(aString)) {
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		TInt len=PyString_Size(aString);
		if (len > aBuf.MaxLength()) len=aBuf.MaxLength();
		iCC->ConvertToUnicode(aBuf, TPtrC8((TUint8*)PyString_AsString(aString), 
			len), state);
	} else if (PyUnicode_Check(aString)) {
		TInt len=PyUnicode_GetSize(aString)/2;
		if (len > aBuf.MaxLength()) len=aBuf.MaxLength();
		aBuf=TPtrC((TUint16*)PyUnicode_AsUnicode(aString), len);
	}
}
コード例 #19
0
void CLocaLogicImpl::ConvertFromPythonString(auto_ptr<HBufC8>& aBuf, PyObject* aString)
{
	if (PyString_Check(aString)) {
		TInt len=PyString_Size(aString);
		if (! aBuf.get() || aBuf->Des().MaxLength() < len) {
			aBuf.reset(HBufC8::NewL(len*2));
		}
		aBuf->Des()=TPtrC8((TUint8*)PyString_AsString(aString), len);
	} else if (PyUnicode_Check(aString)) {
		TInt len=PyUnicode_GetSize(aString);
		if (! aBuf.get() || aBuf->Des().MaxLength() < len) {
			aBuf.reset(HBufC8::NewL(len*2));
		}
		TPtr8 p=aBuf->Des();
		iCC->ConvertFromUnicode(p, TPtrC((TUint16*)PyUnicode_AsUnicode(aString), len));
	}
	PyErr_Clear();
}
コード例 #20
0
void CT_ISO2022JP1_2::TestIsIllFormedIso2022Jp(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC8& aIso2022Jp)
	{
	INFO_PRINTF1(_L(" TestIsIllFormedIso2022Jp "));
	TBuf16<50> generatedUnicode;
	TInt state=CCnvCharacterSetConverter::KStateDefault;
	TPtrC8 remainderOfIso2022Jp(aIso2022Jp);
	TInt lastReturnValue=KMaxTInt;
	FOREVER
		{
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, remainderOfIso2022Jp, state);
		if (returnValue==CCnvCharacterSetConverter::EErrorIllFormedInput)
			{
			break;
			}
		test(returnValue>0);
		test(returnValue<lastReturnValue);
		lastReturnValue=returnValue;
		remainderOfIso2022Jp.Set(remainderOfIso2022Jp.Right(returnValue));
		}
	}
コード例 #21
0
/**
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0539
@SYMTestCaseDesc        Conversion of bad EucJpPacked format to Unicode test
@SYMTestPriority        Medium
@SYMTestActions         Tests to convert Ill formed EucJpPacked input to Unicode.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
void CT_EUCJP_PACKED_2::TestIsIllFormedEucJpPacked(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC8& aEucJpPacked)
	{
	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0539 "));
	TBuf16<50> generatedUnicode;
	TInt state=CCnvCharacterSetConverter::KStateDefault;
	TPtrC8 remainderOfEucJpPacked(aEucJpPacked);
	TInt lastReturnValue=KMaxTInt;
	FOREVER
		{
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, remainderOfEucJpPacked, state);
		if (returnValue==CCnvCharacterSetConverter::EErrorIllFormedInput)
			{
			break;
			}
		test(returnValue>0);
		test(returnValue<lastReturnValue);
		lastReturnValue=returnValue;
		remainderOfEucJpPacked.Set(remainderOfEucJpPacked.Right(returnValue));
		}
	}
コード例 #22
0
ファイル: ENP.CPP プロジェクト: cdaffara/symbiandump-mw2
//
// Calculate a hash value for each server entry
// 
TBool CEmailNotificationParser::CalcHashValueL(CCnvCharacterSetConverter& aCharConv, const TDesC8& aUserName, const TDesC& aServerName, const TDesC8& aPortNum)
	{
	TInt total = 0;
	TInt loop = 0;
	TInt unConvertChar;
	TInt posOfUnconv;

	delete iServerName;
	iServerName = NULL;
	iServerName = HBufC8::NewL(aServerName.Length());

	TPtr8 svr = iServerName->Des();
	aCharConv.ConvertFromUnicode( svr, aServerName, unConvertChar,posOfUnconv);

	// Fix for DEF044588: the Smart Messaging Specification (Revision 3.0.0) states (page 3-17) that
	// the value of the first character of S is multiplied by one, second character by two etc.
	for(loop = 0; loop < aUserName.Length(); loop++)
		{
		total += ( (loop+1) * (TUint)aUserName[loop]);
		}

	TInt pos = aUserName.Length();

	for(loop = 0; loop < svr.Length(); loop++)
		{
		total += ( (pos + (loop+1) )* (TUint)svr[loop]);
		}

	pos += aServerName.Length();

	for(loop = 0; loop < aPortNum.Length(); loop++)
		{
		total += ( (pos + (loop+1) )* (TUint)aPortNum[loop]);
		}

	TReal hashVal;
	User::LeaveIfError(Math::Mod(hashVal, total, KServerIdModVal));
	return ((TInt)hashVal == iServerId);
	}
コード例 #23
0
void CT_ISO2022JP1_2::TestSplittingConvertingToUnicodeFromIso2022Jp(
                CCnvCharacterSetConverter& aCharacterSetConverter,
                TInt aMaximumLengthLowerLimit,
                TInt aMaximumLengthUpperLimit,
                TInt aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit,
                TInt aExpectedLengthOfFirstPartOfUnicode,
                const TDesC16& aExpectedUnicode,
                const TDesC8& aOriginalIso2022Jp)
	{
	INFO_PRINTF1(_L(" TestSplittingConvertingToUnicodeFromIso2022Jp "));
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
	test(aMaximumLengthUpperLimit<=KBufferLength);
	TUint16 unicodeBuffer[KBufferLength];
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
		{
		TPtr16 generatedFirstPartOfUnicode(unicodeBuffer, i);
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedFirstPartOfUnicode, aOriginalIso2022Jp, state);
		test(generatedFirstPartOfUnicode==aExpectedUnicode.Left(aExpectedLengthOfFirstPartOfUnicode));
		test(returnValue==aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit);
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, aOriginalIso2022Jp.Right(aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit), state)==0);
		test(generatedSecondPartOfUnicode==aExpectedUnicode.Mid(aExpectedLengthOfFirstPartOfUnicode));
		TBuf8<KBufferLength> generatedIso2022Jp;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedIso2022Jp, generatedFirstPartOfUnicode)==0);
		TBuf8<KBufferLength> generatedSecondPartOfIso2022Jp;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfIso2022Jp, generatedSecondPartOfUnicode)==0);
		generatedIso2022Jp.Append(generatedSecondPartOfIso2022Jp);
		TBuf16<KBufferLength> regeneratedUnicode;
		state=CCnvCharacterSetConverter::KStateDefault;
		test(aCharacterSetConverter.ConvertToUnicode(regeneratedUnicode, generatedIso2022Jp, state)==0);
//		test(regeneratedUnicode==aExpectedUnicode);
		state=CCnvCharacterSetConverter::KStateDefault;
		test(aCharacterSetConverter.ConvertToUnicode(regeneratedUnicode, aOriginalIso2022Jp, state)==0);
		test(regeneratedUnicode==aExpectedUnicode);
		}
	}
コード例 #24
0
LOCAL_C TBool TestGetBodyTextL()
	{
	__UHEAP_MARK;
	// Retrieve the store from the current context... 
	CMsvStore* store = pContext->EditStoreL();
	CleanupStack::PushL(store);
	
	// Populate CMsvBodyText from the data in the store...
	CMsvBodyText* obj = CMsvBodyText::NewLC();
	obj->RestoreL(*store);
	
	// Create a rich text object...
	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
	CleanupStack::PushL(paraLayer);
	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
	CleanupStack::PushL(charLayer);
	CRichText* richText = CRichText::NewL(paraLayer, charLayer);
	CleanupStack::PushL(richText);
	
	// Create an array of available character sets...
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* charSets;
	CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewL();
	CleanupStack::PushL(converter);
	charSets = converter->CreateArrayOfCharacterSetsAvailableLC(gFs);
	
	// For each available character set, call GetBodyTextL...
	TInt i;
	for (i = 0; i < charSets->Count(); i++)
		{
		// Over-ride the stored character set.
		obj->SetCharacterSet((*charSets)[i].Identifier());
		// Convert the 8 bit data to the specified character set.
		obj->GetBodyTextL(gFs, *store, *richText);
		test(richText->HasChanged());
		richText->Reset();
		}
	
	// Instead of decoding 10 bytes of data, increase the amount of data to 4000 bytes.
	obj->SetCharacterSet(0);
	obj->SetDefaultCharacterSet((*charSets)[0].Identifier());
	const TInt KTextBufferSize=4000;
	CBufBase *buffer=CBufFlat::NewL(KTextBufferSize);
	CleanupStack::PushL(buffer);
	while(buffer->Size()<KTextBufferSize)
		{
		buffer->InsertL(buffer->Size(),K10BytesData);
		}

	obj->StoreL(*store, *buffer);
	CleanupStack::PopAndDestroy(buffer);
	store->CommitL();
	obj->RestoreL(*store);
	obj->GetBodyTextL(gFs, *store, *richText);
	test(richText->HasChanged());
	
	// Clean up and release resources...
	CleanupStack::PopAndDestroy(charSets);
	CleanupStack::PopAndDestroy(converter);
	CleanupStack::PopAndDestroy(richText);
	CleanupStack::PopAndDestroy(charLayer);
	CleanupStack::PopAndDestroy(paraLayer);
	CleanupStack::PopAndDestroy(obj);
	CleanupStack::PopAndDestroy(store);
	__UHEAP_MARKEND;
		
	return ETrue;
	}
コード例 #25
0
void CLocaLogicImpl::NewScriptL(const TDesC& aSubName, const MBBData* aData)
{
	TInterpreterAutoLock interp;

	const CBBString* code=bb_cast<CBBString>(aData);	
	if (!code) {
		Reporting().UserErrorLog(_L("Could not read Python script named "),
			aSubName, _L(" (wrong bb type)"));
		return;
	}
	auto_ptr<HBufC8> code8(HBufC8::NewL(code->Value().Length()+10));
	auto_ptr<HBufC8> subname8(HBufC8::NewL(aSubName.Length()+10));
	{
		TInt err=KErrNone;
		TInt unconverted=0, unconverted_pos=0;
		{
			TPtr8 p=code8->Des();
			err=iCC->ConvertFromUnicode(p, code->Value(), unconverted, unconverted_pos);
		}
		if (err==KErrNone && unconverted==0) {
			TPtr8 p=subname8->Des();
			err=iCC->ConvertFromUnicode(p, aSubName, unconverted, unconverted_pos);
		}
		if (err!=KErrNone || unconverted>0) {
			TBuf<30> rest;
			if (err!=KErrNone) {
				rest=_L("to Latin1, err: ");
				rest.AppendNum(err);
			} else {
				rest=_L("to Latin1, at position ");
				rest.AppendNum(unconverted_pos);
			}
			Reporting().UserErrorLog(_L("Could not convert Python script named"),
				aSubName, rest);
			return;
		}
	}

	if ( code8.get() && code8->Length()>1 && (*code8)[code8->Length()-1] != '\n' ) {
		code8->Des().Append('\n');
	}
	code8->Des().Append('\0');
	TInt res=PyRun_SimpleString( (char*)code8->Ptr() );
	if (res < 0) {
		msg=_L("Cannot compile code in script ");
		msg.Append(aSubName);
		ReportPythonError(msg);
		return;
	}
	if (aSubName.Length()>0 && aSubName[0]!='_') {
		// borrowed
		PyObject* main_module = PyImport_AddModule("__main__");
		if (! main_module ) User::Leave(KErrNoMemory);
		// borrowed
		PyObject* global_dict = PyModule_GetDict(main_module);
		if (! global_dict ) User::Leave(KErrNoMemory);
		// borrowed
		subname8->Des().Append('\0');
		PyObject* func=PyDict_GetItemString(global_dict, (const char*)subname8->Ptr());
		if (func==0) {
			Reporting().UserErrorLog(_L("Running Python script "),
				aSubName, _L(" didn't create a function with that name"));
		} else {
			AddToArrayL(iFunctions, *subname8);
			DeleteFromArrayL(iErrorFunctions, *subname8);
		}
	}
}
コード例 #26
0
void CLocaLogicImpl::GetMessageL(const CBBBtDeviceList* devices,
	const TTime& aAtTime,
	TInt& doSendToIndex, 
	TInt& aMessageCode, TDes& aWithName,
	TDes& aWithTitle, auto_ptr<HBufC8>& aBody) 
{
	CALLSTACKITEM_N(_CL("CLocaLogicImpl"), _CL("GetMessage"));
	TInterpreterAutoLock interpr;

	doSendToIndex=-1;

	TInt count=-1;
	const TBBBtDeviceInfo* dev=0;

	TInt max_seen_priority=-1;

	for (dev=devices->First(); dev; dev=devices->Next()) count++;
	
	python_ptr<PyObject> dict_general(PyDict_New());
	if (! dict_general ) User::Leave(KErrNoMemory);
	AddToPyDict(dict_general, "nodename", iNodeName);
	AddToPyDict(dict_general, "time", aAtTime);
	AddToPyDict(dict_general, "bt_count", count);

	// borrowed
	PyObject* main_module = PyImport_AddModule("__main__");
	if (! main_module ) User::Leave(KErrNoMemory);
	// borrowed
	PyObject* global_dict = PyModule_GetDict(main_module);
	if (! global_dict ) User::Leave(KErrNoMemory);
	// borrowed

	TInt index=0;
	dev=devices->First(); // first is the node itself
	for (dev=devices->Next(); dev; dev=devices->Next()) {
		index++;
		TBuf<15> mac;
		dev->iMAC.IntoStringL(mac);
		AddToPyDict(dict_general, "mac", mac);
		AddToPyDict(dict_general, "majorclass", dev->iMajorClass());
		AddToPyDict(dict_general, "minorclass", dev->iMinorClass());

		TBool found=EFalse;
		python_ptr<PyObject> dict_devstats(PyDict_New());
		{
			TBuf<50> node;
			TDevStats s;
			for(found=iDevStats->FirstStats(*dev, node, s); found; 
					found=iDevStats->NextStats(*dev, node, s)) {
				python_ptr<PyObject> dict_dev(
					DevStatToPyDict(s));
				auto_ptr<HBufC8> node8(HBufC8::NewL(node.Length()+2));
				TPtr8 p=node8->Des();
				iCC->ConvertFromUnicode(p, node);
				node8->Des().ZeroTerminate();
				AddToPyDict(dict_devstats, (char*)node8->Ptr(), dict_dev);
			}
		}
		python_ptr<PyObject> dict_msgstats(0);
		{
			TMessageStats s;
			iMessageStats->GetStatsL(*dev, s);
			dict_msgstats.reset(MessageStatToPyDict(s));
		}
		for (int i=0; i<iFunctions->Count(); i++) {
			TScriptError err=RunScript(main_module,
				global_dict, iFunctions->MdcaPoint(i), max_seen_priority,
				dict_general.get(), dict_devstats.get(), 
				dict_msgstats.get(),
				aMessageCode, aWithName,
				aWithTitle, aBody, iErrorMsgBuf, dev->iMAC()
				);
			if (err>EHighestPriority) {
#if !defined(__WINS__) && !defined(CONTEXTLOCA)
				if (IsInArray(iErrorFunctions, iFunctions->MdcaPoint(i))) {
					PyErr_Clear();
					continue;
				}
#endif
				AddToArrayL(iErrorFunctions, iFunctions->MdcaPoint(i));

				TBuf<50> name;
				TInt state=CCnvCharacterSetConverter::KStateDefault;
				iCC->ConvertToUnicode(name, iFunctions->MdcaPoint(i), state);
				name.SetLength(name.Length()-1);
				if (err==EPythonError) {
					AppendCheckingSpaceL(iErrorMsgBuf, _L(" in script "));
					AppendCheckingSpaceL(iErrorMsgBuf, name);
					ReportPythonError(iErrorMsgBuf);
				} else {
					Reporting().UserErrorLog( iErrorMsgBuf,
						_L(" in script "), name);
				}
			} else if (err==EHighestPriority) {
				doSendToIndex=index;
			}
		}
	}
	/*
	// phone or PDA
	if (aDevice.iMajorClass()==0x02 || (
		aDevice.iMajorClass()==0x01 && 
		aDevice.iMinorClass()>0x03 )) {
	} else {
		return;
	}
	*/

}
コード例 #27
0
ファイル: ENP.CPP プロジェクト: cdaffara/symbiandump-mw2
//
// Get all email services
//
void CEmailNotificationParser::GetEmailServicesL()
	{

	CCnvCharacterSetConverter* charconv = CCnvCharacterSetConverter::NewL();
	CleanupStack::PushL(charconv);
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet> *charsetsAvailable = charconv->CreateArrayOfCharacterSetsAvailableL(iFs);
	CleanupStack::PushL(charsetsAvailable);

	charconv->PrepareToConvertToOrFromL(KUidCharsetISO88591,*charsetsAvailable,iFs);
	
	const TMsvId current = iEntry.Entry().Id();
	iEntry.SetEntryL(KMsvRootIndexEntryId);
	// Get all POP3 and Imap services
	CMsvEntrySelection* rootChildren = iEntry.ChildrenL();
	CleanupStack::PushL(rootChildren);

	TMsvEntry entry;

	CEmailAccounts* accounts = CEmailAccounts::NewLC();

	const TInt count = rootChildren->Count(); 
	TInt j =0;
	while(j < count && iFoundServer ==EFalse)
		{
		// set context to service entry
		iEntry.SetEntryL((*rootChildren)[j]);
		entry = iEntry.Entry(); 
		if (entry.iType == KUidMsvServiceEntry && (entry.iMtm == KUidMsgTypePOP3 || entry.iMtm == KUidMsgTypeIMAP4))
			{
			TBuf8<8> port;

			if(entry.iMtm == KUidMsgTypePOP3)
				{
				// calculate hash value
				CImPop3Settings* settings = new(ELeave)CImPop3Settings;
				CleanupStack::PushL(settings);
 
 				TPopAccount id;
				accounts->GetPopAccountL(entry.Id(), id);
				accounts->LoadPopSettingsL(id, *settings);

				port.Num((TUint)KPOP3DefaultPortNumber);
				iFoundServer = CalcHashValueL( *charconv, settings->LoginName(), settings->ServerAddress(), port);
				}
			else // entry.iMtm == KUidMsgTypeIMAP4
				{
				CImImap4Settings* settings = new(ELeave)CImImap4Settings;
				CleanupStack::PushL(settings);
				
 				TImapAccount id;
				accounts->GetImapAccountL(entry.Id(), id);
				accounts->LoadImapSettingsL(id, *settings);

				port.Num((TUint)KIMAPDefaultPortNumber);
				iFoundServer = CalcHashValueL( *charconv, settings->LoginName(), settings->ServerAddress(), port);
				}
			CleanupStack::PopAndDestroy(); // settings
			}
		j++;
		}

	if(	iFoundServer )
		iServiceMsvId = entry.Id();

	CleanupStack::PopAndDestroy(4, charconv); // charconv, charsetsAvailable, rootChildren, accounts
	
	iEntry.SetEntryL(current);
	}