EXPORT_C HBufC* CScriptFile::ReplaceLC(const TDesC& aOld, const TDesC& aNew, const TDesC& aOldString) { HBufC* rString = aOldString.AllocLC(); TInt oldLen = aOld.Length(); TInt newLen = aNew.Length(); if (!oldLen) return rString; for (TInt pos = 0; pos < rString->Length(); pos += newLen) { TPtrC ptrC = rString->Mid(pos); TInt find = ptrC.Find(aOld); if (find == KErrNotFound) return rString; pos += find; if (newLen > oldLen) { rString = rString->ReAllocL(rString->Length() + newLen - oldLen); CleanupStack::Pop(); CleanupStack::PushL(rString); } TPtr ptr(rString->Des()); ptr.Replace(pos, oldLen, aNew); } return rString; }
void CZipFileDecompressor::DecompressNextMemberL(CZipFileMember& aMember) { __ASSERT_ALWAYS(!iUncompressedFile.SubSessionHandle(), User::Invariant()); __ASSERT_ALWAYS(!iUncompressedData, User::Invariant()); //Ignore entries that has zero uncompressed size. //(This includes e.g. directories) if (aMember.UncompressedSize() > 0) { const TChar KDirectorySeparator('\\'); TUint32 uncompressedSize = aMember.UncompressedSize(); HBufC8* uncompressedData = HBufC8::NewLC(uncompressedSize); RZipFileMemberReaderStream* readerStream; User::LeaveIfError(iZipFile->GetInputStreamL(&aMember, readerStream)); CleanupStack::PushL(readerStream); TPtr8 uncompressedDataPtr = uncompressedData->Des(); User::LeaveIfError(readerStream->Read(uncompressedDataPtr, uncompressedDataPtr.MaxLength())); CleanupStack::PopAndDestroy(readerStream); HBufC* fileName = aMember.Name()->AllocLC(); TPtr fileNamePtr= fileName->Des(); TInt lastDirectorySeparator = fileName->LocateReverse(KDirectorySeparator); if (lastDirectorySeparator >= 0) { fileNamePtr = fileName->Mid(lastDirectorySeparator+1); } TParsePtr fileNameParser(fileNamePtr); User::LeaveIfError(iUncompressedFile.Replace(iFileServer, fileNameParser.NameAndExt(), EFileWrite)); CleanupStack::PopAndDestroy(fileName); CleanupStack::Pop(uncompressedData); iUncompressedData = uncompressedData; iUncompressedFile.Write(*iUncompressedData, iStatus); SetActive(); } else { iStatus = KRequestPending; SetActive(); TRequestStatus* ownStatus = &iStatus; User::RequestComplete(ownStatus, KErrNone); } }
// ----------------------------------------------------------------------------- // CWidgetUiObserver::TranslateURLToFilenameL // Translate the file name from a URL to a valid file name in the system. // ----------------------------------------------------------------------------- // TBool CWidgetUiObserver::TranslateURLToFilenameL( const TDesC& aFileName, const TDesC& aLanguageDir ) { // This function accepts URLs in the following format: // file://filename.xxx // file:///filename.xxx // file://c:/filename.xxx // file:///c:/filename.xxx // c:/dir/file.txt (the browser engine can send these too!) TInt count( 0 ); TInt index( 0 ); TBool drvLetter = EFalse; TUint16 c; HBufC* decodedUrl = EscapeUtils::EscapeDecodeL(aFileName); CleanupStack::PushL( decodedUrl ); // Throw away the intial file:// part, if present TPtrC urlPtr( aFileName ); if (urlPtr.FindF( KFileScheme) == 0 ) { urlPtr.Set( decodedUrl->Mid( KFileScheme().Length() ) ); } // Make sure there are enough characters in the filename before // trying to check them count = urlPtr.Length() + aLanguageDir.Length() + KLprojExt().Length() + KPathChar().Length(); if ( urlPtr.Length() > 0 ) //do nothing for trivial input { // Skip the first '/' if there is one if ( urlPtr[0] == '/' ) { urlPtr.Set( urlPtr.Mid( 1 ) ); } // Is there a drive letter? if ( urlPtr.Length() > 1 ) { // Can check for drive letter if ( urlPtr[1 + index] == ':' ) { drvLetter = ETrue; } } if ( drvLetter == EFalse ) { // Plan for a c:\ type drive prefix to what we already tallied above count += KDefaultDrivePath().Length(); } delete iFileName; iFileName = NULL; iFileName = HBufC::NewL( count ); if ( !drvLetter ) { iFileName->Des().Append( KDefaultDrivePath ); } TBool fragment( EFalse ); // Convert relative path containing /./ and /../ to absolute path for ( ; index < urlPtr.Length() && !fragment; index ++ ) { switch ( urlPtr[index] ) { case '#': // Check if there is a fragment '#' { fragment = ETrue; continue; // Just stop there } case '/': { iFileName->Des().Append( KPathChar ); break; } case '.': { if ( index > 1 && urlPtr[index - 1] == '/' ) { if ( index < count - 1 && urlPtr[ index + 1 ] == '/' ) { index ++; // Skip ./ break; } if ( index > 2 && index < count - 3 && urlPtr[ index + 1 ] == '.' && urlPtr[ index + 2 ] == '/' ) { TInt i = index - 2; for ( ; i > 0 && urlPtr[i] != '/'; i-- ) {} // Skip /../ iFileName->Des().SetLength( iFileName->Des().Length() - (index - i) ); index += 2; break; } } } // No break //lint -fallthrough default: { c = urlPtr[ index ]; iFileName->Des().Append( &c, 1 ); break; } } // end of switch } if ( aLanguageDir.Length() ) { TChar backSlash = '\\'; TInt pos = iFileName->Des().LocateReverse( backSlash ); if ( pos != KErrNotFound ) { TPtr p = iFileName->Des(); p.Insert(pos, KLprojExt ); p.Insert(pos, aLanguageDir ); p.Insert(pos, KPathChar ); } } } //Do nothing for any trivial input CleanupStack::PopAndDestroy(1, decodedUrl); // decodedUrl return ETrue; }
void CHandleOutSearch::HandleChildElement(TiXmlNode* aElement) { TInt index=iPointArray.Count()-1; TInt itemIndex=iPointArray[index]->GetItemCount()-1; if(itemIndex<0) { iPointArray[index]->CreatNewItem(); itemIndex=0; } if(aElement->NoChildren()) { if(iFlag) { HBufC* buf = CnvUtfConverter::ConvertToUnicodeFromUtf8L(TPtrC8((const TUint8*)aElement->Value())); CleanupStack::PushL(buf); if(buf->Compare(_L("br"))==0) { if(!iPointArray[index]->GetItem(itemIndex).IsNull()) iPointArray[index]->CreatNewItem(); } if(buf->Compare(_L("br"))!=0&&buf->Compare(_L("img"))!=0&&buf->Compare(_L("input"))!=0&&buf->Compare(_L("|"))!=0) { if(buf->Left(2).Compare(_L("--"))==0) { TInt f=0; for(TInt i=0;i<buf->Length();i++) { if(buf->Mid(i,1).Compare(_L("-"))!=0) { f=1; break; } } if(f==0) { iFlag=EFalse; } } if(iFlag) iPointArray[index]->GetItem(itemIndex).SetName(*buf); else { if(!iPointArray[index]->GetItem(itemIndex).IsNull()) iPointArray[index]->CreatNewItem(); } } iMainEngine.WriteLog16(*buf); CleanupStack::PopAndDestroy(1); } } else { HBufC8* tag=TPtrC8((const TUint8*)aElement->Value()).Alloc(); CleanupStack::PushL(tag); TInt value=CheckTag(*tag); CleanupStack::PopAndDestroy(1); if(value>0) { switch(value) { case 1: //P±êÇ© { TiXmlNode* element=aElement->FirstChild(); while(element!=0) { HandleChildElement(element); element=element->NextSibling(); } } break; case 2: //Á¬½Ó±êÇ© { HBufC8* bufUrl = TPtrC8((const TUint8*)aElement->ToElement()->Attribute("href")).Alloc(); CleanupStack::PushL(bufUrl); TInt urlFlag=CheckUrl(*bufUrl); if(urlFlag>0) { iPointArray[index]->GetItem(itemIndex).SetUrl(*bufUrl); } CleanupStack::PopAndDestroy(1); if(urlFlag==1||urlFlag==2) { HBufC* buf = CnvUtfConverter::ConvertToUnicodeFromUtf8L(TPtrC8((const TUint8*)aElement->FirstChild()->Value())); CleanupStack::PushL(buf); iPointArray[index]->GetItem(itemIndex).SetName(*buf); iMainEngine.WriteLog16(*buf); CleanupStack::PopAndDestroy(1); iPointArray[index]->GetItem(itemIndex).SetIsLink(ETrue); iPointArray[index]->CreatNewItem(); } else { HBufC* buf = CnvUtfConverter::ConvertToUnicodeFromUtf8L(TPtrC8((const TUint8*)aElement->FirstChild()->Value())); CleanupStack::PushL(buf); HBufC8* bufUrl = TPtrC8((const TUint8*)aElement->ToElement()->Attribute("href")).Alloc(); CleanupStack::PushL(bufUrl); if(CheckUrl(*bufUrl)==3) { if(buf->Compare(iMainEngine.GetDesById(ETurkeyTextRes_DownPage))==0||buf->Compare(iMainEngine.GetDesById(ETurkeyTextRes_HXML_DPage))==0) { iPointArray[index]->SetNextPageUrl(*bufUrl); } else if(buf->Compare(iMainEngine.GetDesById(ETurkeyTextRes_UpPage))==0||buf->Compare(iMainEngine.GetDesById(ETurkeyTextRes_HXML_UPage))==0) { iPointArray[index]->SetPrePageUrl(*bufUrl); } } iMainEngine.WriteLog16(*buf); CleanupStack::PopAndDestroy(2); } } break; case 4://»»ÐбêÇ© if(!iPointArray[index]->GetItem(itemIndex).IsNull()&&iFlag) iPointArray[index]->CreatNewItem(); break; case 3://×ÖÌå±êÇ© { if(iFlag) { HBufC* buf = CnvUtfConverter::ConvertToUnicodeFromUtf8L(TPtrC8((const TUint8*)aElement->FirstChild()->Value())); CleanupStack::PushL(buf); iPointArray[index]->GetItem(itemIndex).SetName(*buf); iMainEngine.WriteLog16(*buf); CleanupStack::PopAndDestroy(1); } } break; } } } }
// ----------------------------------------------------------------------------- // CSisxUIAppInfo::PrepareIteratorL // Prepares the iterator to be shown in details dialog. // (other items were commented in a header). // ----------------------------------------------------------------------------- // void CSisxUIAppInfo::PrepareIteratorL( const Swi::CAppInfo& /*aInfo*/ ) { FreeIterator(); iKeys = new( ELeave )CDesCArrayFlat( 6 ); iValues = new( ELeave )CDesCArrayFlat( 6 ); // Name SetFieldL( R_SWCOMMON_DETAIL_NAME, Name() ); // Version HBufC* stringBuf = CommonUI::CUIUtils::ConstructVersionStringLC( Version().iMajor, Version().iMinor, Version().iBuild ); TPtr ptr = stringBuf->Des(); AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); HBufC* tmpBuf = HBufC::NewLC( KLRE().Length() + stringBuf->Length() + KPDF().Length() ); TInt position = stringBuf->Find( KLeftParenthes() ); if ( position >= 0 ) { tmpBuf->Des() = stringBuf->Mid( 0, position ); tmpBuf->Des() += KLRE(); tmpBuf->Des() += stringBuf->Mid( position, stringBuf->Length() - position ); tmpBuf->Des() += KPDF(); } else { tmpBuf->Des() = *stringBuf; } SetFieldL( R_SWCOMMON_DETAIL_VERSION, *tmpBuf ); CleanupStack::PopAndDestroy( tmpBuf ); CleanupStack::PopAndDestroy( stringBuf ); // Supplier if ( IsTrusted() ) { SetFieldL( R_SWCOMMON_DETAIL_SUPPLIER, Vendor() ); } else { tmpBuf = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_UNKNOWN_SUPPLIER ); SetFieldL( R_SWCOMMON_DETAIL_SUPPLIER, *tmpBuf ); CleanupStack::PopAndDestroy( tmpBuf ); } // size tmpBuf = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_UNKNOWN_SIZE ); SetFieldL( R_SWCOMMON_DETAIL_APPSIZE, *tmpBuf ); CleanupStack::PopAndDestroy( tmpBuf ); // Technology tmpBuf = HBufC::NewLC( KLRE().Length() + KSymbian().Length() + KPDF().Length() ); tmpBuf->Des() = KLRE(); tmpBuf->Des() += KSymbian(); tmpBuf->Des() += KPDF(); SetFieldL( R_SWCOMMON_DETAIL_TECHNOLOGY, *tmpBuf ); CleanupStack::PopAndDestroy( tmpBuf ); // Type tmpBuf = StringLoader::LoadLC( R_SWCOMMON_DETAIL_VALUE_APPLICATION ); SetFieldL( R_SWCOMMON_DETAIL_TYPE, *tmpBuf ); CleanupStack::PopAndDestroy( tmpBuf ); }
void CCmdIniEdit::DoRunL() { TBool interactive = ETrue; if (iForce) { iReader = CIniReader::NewL(iIniFile); } else { iReader = CIniFile::NewL(iIniFile, iDescriptionFile); } TBool updated = EFalse; if (iSet) { TInt eqPos = iSet->Find(KEquals); TPtrC value(KNullDesC); TPtrC id(KNullDesC); if (eqPos == KErrNotFound) { id.Set(*iSet); Stdin().SetReadModeL(RIoReadHandle::ELine); iBuf.CreateL(0x100); Stdin().ReadL(iBuf); value.Set(iBuf); } else { id.Set(iSet->Left(eqPos)); value.Set(iSet->Mid(eqPos+1)); } iReader->SetValueL(Trim(id), value); updated = ETrue; interactive = EFalse; } if (iRemove) { iReader->RemoveValueL(*iRemove); updated = ETrue; interactive = EFalse; } if (iGet) { const TDesC* value = iReader->GetValue(*iGet); if (!value) LeaveIfErr(KErrNotFound, _L("id '%S' not found in %S"), iGet, &iIniFile); Write(*value); interactive = EFalse; } else if (iDump) { RPointerArray<CValue> values; CleanupClosePushL(values); iReader->GetValuesL(values); for (TInt i=0; i<values.Count(); ++i) { if (iForce) { Printf(_L("%S: %S\n"), &values[i]->Id(), &values[i]->Value()); } else { CSetting* setting = (CSetting*)values[i]; Printf(_L("%S: %S\n"), &setting->Name(), &setting->Value()); } } CleanupStack::PopAndDestroy(&values); interactive = EFalse; } if (interactive) { // TODO enter interactive mode LeaveIfErr(KErrNotSupported, _L("Interactive mode not implemented yet.")); } if (updated) { WriteIniFileL(iIniFile, *iReader); } }
// ----------------------------------------------------------------------------- // CAknKeyRotatorImpl::GetKeyRotatorCompensationL // Parses wsini.ini to read key rotator compensation value. // ----------------------------------------------------------------------------- // TInt CAknKeyRotatorImpl::GetKeyRotatorCompensationL() { TInt result = 0; HBufC* wsiniText = GetWsiniLC(); // Now look for keyword const TInt pos = wsiniText->Find( KAknKeyRotatorKey ); if ( pos != KErrNotFound ) { // Keyword was found. Check that it is the beginning of line. // Three cases: // 1. Keyword could be at the beginning of the file. // 2. Keyword could be at the beginning of the file // after byte ordering marker. // 3. Previous character can be end of line marker. const TInt previousPos = pos - 1; if ( previousPos < 0 || ( !previousPos && IsByteOrderingMarker( (*wsiniText)[ previousPos ] ) ) || IsEndOfLine( (*wsiniText)[ previousPos ] ) ) { TLex text( wsiniText->Mid( pos + KAknKeyRotatorKey().Length() ) ); // First, there must be at least a space after keyword. TBool fail = !( SkipSpaces( text ) & EAknWasSpace ); // Case 1: Disabled TBool wasDisabled = EFalse; if ( !fail ) { wasDisabled = !text.Remainder().Left( KAknKeyRotatorDisabled().Length() ). CompareF( KAknKeyRotatorDisabled ); if ( wasDisabled ) { // wasDisabled == True, KAknKeyRotatorDisabled was prefix // of text. So skip over it text.Inc( KAknKeyRotatorDisabled().Length() ); } } // Case 2: Then follows a sequence of digits, optionally preceded by '-'. if ( !wasDisabled && !fail ) { // Check optional - TBool negate = EFalse; if ( !text.Eos() && text.Peek() == '-' ) { negate = ETrue; text.Inc(); } // Get digit sequence and convert to integer value. TPtrC token = GetDigits( text ); fail = !token.Length() || ( TLex( token ).Val( result ) != KErrNone ); // Handle negation if ( !fail && negate ) { result = -result; } } // That sequence of digits is followed by sequence of spaces until // end of line or end of file. fail = fail || ( SkipSpaces( text ) & EAknWasCharacter ); if ( !wasDisabled ) { // Finally, that sequence of digits must represent // one valid decimal value of the following: // -270, -180, -90, 0, 90, 180, 270. fail = fail || !CheckCompensationValue( result ); } // If any of above checks failed, use default value 0. if ( fail ) { result = 0; } else { if ( wasDisabled ) { result = KMaxTInt; } } } } CleanupStack::PopAndDestroy( wsiniText ); return result; }