void CRichText::OverrideFormatForParsersIfApplicable(TPtrC& aText, TCharFormatX& aFormat, TInt aStartPos) const { if (aFormat.iParserTag && iParserData->iActiveParserList && iParserData->iEditObserver) { // Replace format TInt start = -1; TInt length = 0; TInt curPos = iParserData->iLastKnownCursor; if (curPos > DocumentLength()) curPos = DocumentLength(); // This shouldn't be neccesary but it makes it more // bulletproof if the calls from outside are made in // the wrong order if (curPos != -1) { TCharFormatX format; TCharFormatXMask varies; MParser* parser; GetExtendedCharFormat(format, varies, curPos, 1); // If char at curpos has a tag then cursor is over that tag, get extents of tag if (CParserList::ReformatOnRollover(format.iParserTag)) DoCursorOverTag(curPos, parser, start, length); else if (curPos) { GetExtendedCharFormat(format, varies, curPos - 1, 1); // Try the char "before" curpos if (CParserList::ReformatOnRollover(format.iParserTag)) DoCursorOverTag(curPos - 1, parser, start, length); } } MParser* parser = iParserData->iActiveParserList->ParserWithThisTag(aFormat.iParserTag); if (length && (aStartPos >= start) && (aStartPos < start + length)) { if (start + length < aStartPos + aText.Length()) aText.Set(aText.Left(start + length - aStartPos)); if (parser != NULL) { // Only accept the rollover format if the parser agrees // with the framework match of a tag if (parser->ConfirmCursorOverTag(*this, start, length, curPos)) parser->GetRolloverFormat(aFormat.iCharFormat); else // Reset format to recognised format if parser disagrees // with the framework match as the tag is still in view // and must be formatted as in the else clause below. parser->GetRecogniseFormat(aFormat.iCharFormat); } } else { if (length && (start > aStartPos)) aText.Set(aText.Left(start - aStartPos)); if (parser != NULL) parser->GetRecogniseFormat(aFormat.iCharFormat); } } }
void CAppConfig::GetConfigL(const TDesC &aKey, const TConfig &aConfig) { RDbTable table; TDbSeekKey seekKey(aKey); User::LeaveIfError(table.Open(iDb, KConfigTable, table.EReadOnly)); CleanupClosePushL(table); User::LeaveIfError(table.SetIndex(KConfigIndex)); CDbColSet* colSet = table.ColSetL(); CleanupStack::PushL(colSet); TInt valueColNo = colSet->ColNo(KConfigValueCol); if (table.SeekL(seekKey)) { table.GetL(); TPtrC value = table.ColDes(valueColNo); switch (aConfig.iType) { case EConfigBool: *aConfig.iValue.iBool = value.Compare(KBoolTrue) == 0 ? ETrue : EFalse; break; case EConfigInt: { TLex lex(value); TInt lvalue; if (lex.Val(lvalue) == KErrNone) { *aConfig.iValue.iInt = lvalue; } break; } case EConfigText: if (aConfig.iValue.iText->MaxLength() > value.Length()) { aConfig.iValue.iText->Copy(value.Left(aConfig.iValue.iText->MaxLength())); } else { aConfig.iValue.iText->Copy(value); } break; case EConfigText8: if (aConfig.iValue.iText8->MaxLength() > value.Length()) { aConfig.iValue.iText8->Copy(value.Left(aConfig.iValue.iText8->MaxLength())); } else { aConfig.iValue.iText8->Copy(value); } break; } } CleanupStack::PopAndDestroy(colSet); CleanupStack::PopAndDestroy(&table); }
TPtrC CEikListBoxTextEditor::EditableItemText(TRect* aRect) { _AKNTRACE_FUNC_ENTER; TPtrC itemtext = ItemText(); if (iItemPos==0) // not yet set (and even if set, cannot be zero) { iItemPos = itemtext.Locate('\n'); // loacte partly editable item start if (iItemPos != KErrNotFound) { iItemPos++; // jump over mark character iItemLen = itemtext.Mid( iItemPos ).Locate('\n'); // locate string end if ( iItemLen == KErrNotFound ) Panic( ETUiklbedPanicEndMarkMissing ); if ( iItemLen==0 ) Panic( ETUiklbedPanicEmptyField ); TPtrC head = itemtext.Left( iItemPos ); TPtrC body = itemtext.Mid( iItemPos, iItemLen ); if ( aRect ) // adjust the rect if it is given { aRect->iTl.iX += iFont->TextWidthInPixels( head ); aRect->iBr.iX = aRect->iTl.iX + iFont->TextWidthInPixels( body ) + 4; } _AKNTRACE_FUNC_EXIT; return body; } iItemPos = 0; // partly editable text not found } _AKNTRACE_FUNC_EXIT; return itemtext; }
TPtrC TLineBuffer::ReadLine() { // Class nvariant: iRemainder == iTail.Length() ASSERT(iRemainder == iTail.Length()); TInt end = iTail.Locate('\n'); if (end < 0) { // Buffer ends without ending '\n', treat as line end = iTail.Length(); iRemainder = 0; } else { // 0 <= end < iTail.Length() => iTail.Length() > iRemainder >= 0 // (remainder is always decreased at least by 1, skipping '\n', // and will never become negative, because end < remainder) iRemainder -= end + 1; // Ignore CR before LF, if present if (end > 0 && iTail[end-1] == '\r') --end; } const TPtrC line(iTail.Left(end)); iTail.Set(iTail.Right(iRemainder)); return line; }
EXPORT_C void TInuLogger::WriteComment(const TDesC& aComment) // // Writes aComment to test log file, logging file and test harness { TPtrC line; line.Set(aComment); while (line.Length() > KMaxLogLineLength) { iLogger.Write(line.Left(KMaxLogLineLength)); line.Set(line.Right(line.Length() - KMaxLogLineLength)); } iLogger.Write(line.Left(line.Length())); }
S60MediaRecognizer::MediaType S60MediaRecognizer::identifyMediaType(const QString& fileName) { S60MediaRecognizer::MediaType result = Video; // default to videoplayer bool recognizerOpened = false; TInt err = m_recognizer.Connect(); if (err == KErrNone) { recognizerOpened = true; } err = m_fileServer.Connect(); if (err == KErrNone) { recognizerOpened = true; } // This is needed for sharing file handles for the recognizer err = m_fileServer.ShareProtected(); if (err == KErrNone) { recognizerOpened = true; } if (recognizerOpened) { m_file.Close(); err = m_file.Open(m_fileServer, QString2TPtrC(QDir::toNativeSeparators(fileName)), EFileRead | EFileShareReadersOnly); if (err == KErrNone) { TDataRecognitionResult recognizerResult; err = m_recognizer.RecognizeData(m_file, recognizerResult); if (err == KErrNone) { const TPtrC mimeType = recognizerResult.iDataType.Des(); if (mimeType.Left(KMimeTypePrefixLength).Compare(KMimeTypePrefixAudio) == 0) { result = Audio; } else if (mimeType.Left(KMimeTypePrefixLength).Compare(KMimeTypePrefixVideo) == 0) { result = Video; } } } } return result; }
EXPORT_C TBool CEikListBoxTextEditor::UpdateModelL() // virtual - needs to be rewritten if editing other than single column text list { _AKNTRACE_FUNC_ENTER; if (!Editor()) { _AKNTRACE_FUNC_EXIT; return EFalse; // quit if editing is not currently on } const MDesCArray* matchableTextArray=ListBoxModel()->MatchableTextArray(); CDesCArray* textArray=(CDesCArray*)matchableTextArray; TPtrC itemtext = ItemText(); if ( iItemPos ) // partly editable item? { HBufC* itemBuffer= HBufC::New(itemtext.Length()); CleanupStack::PushL( itemBuffer ); TPtr itemPointer = itemBuffer->Des(); itemPointer.Append( itemtext.Left( iItemPos ) ); HBufC* ptr=iEditor->GetTextInHBufL(); TPtrC newText; if (ptr) { newText.Set(ptr->Des()); } TInt addSpaces = iItemLen - newText.Length(); for (TInt index=0; ((addSpaces>0) && (index<addSpaces)); index++) itemPointer.Append(_L(" ")); itemPointer.Append( newText ); itemPointer.Append( itemtext.Right( itemtext.Length()-iItemPos-iItemLen ) ); delete ptr; textArray->InsertL( ItemIndex(), *itemBuffer ); CleanupStack::PopAndDestroy(); // itemBuffer textArray->Delete( ItemIndex()+1 ); } else // replace the whole list item { HBufC* newText = iEditor->GetTextInHBufL(); if (!newText) return ETrue; // if user tries to insert an empty text... CleanupStack::PushL(newText); textArray->InsertL(ItemIndex(),*newText); CleanupStack::PopAndDestroy(); // newText textArray->Delete( ItemIndex() + 1 ); } _AKNTRACE_FUNC_EXIT; return ETrue; }
/** Function to write a comment string to test log file, logging file and test harness. @param aComment The descriptor containing the comment string */ EXPORT_C void THttpLogger::WriteComment(const TDesC& aComment) // // Writes aComment to test log file, logging file and test harness { if(iLogger) { // If connection to flogger was made if(iLogger->Handle() != 0) { TPtrC line; line.Set(aComment); while (line.Length() > KMaxLogLineLength) { iLogger->Write(line.Left(KMaxLogLineLength)); line.Set(line.Right(line.Length() - KMaxLogLineLength)); } iLogger->Write(line.Left(line.Length())); } } }
void CScriptFile::FoundNewItemL(const TDesC& aText, TLex& arInput, TInt& arCurrentItemStart, CScriptSection& aSection, CScriptSectionItem*& arCurrentItem) { TPtrC token = arInput.MarkedToken(); ParseAndSetItemValueL(aText, arInput, arCurrentItemStart, arCurrentItem); arInput.SkipSpaceAndMark(); arCurrentItemStart = arInput.Offset(); TPtrC itemEnd(KScriptItemEnd); const TInt length = token.Length() - itemEnd.Length(); arCurrentItem = &aSection.ReplaceItemL(token.Left(length), KNullDesC); }
/* ------------------------------------------------------------------------------- Class: CStifSectionParser Method: SubstractLine Description: Substracts line from selected text Parameters: TPtrC& aText: in: text. Return Values: TPtrC: Substracted line. Errors/Exceptions: None Status: Proposal ------------------------------------------------------------------------------- */ TPtrC CStifSectionParser::SubstractLine( const TPtrC& aText ) { TLex lex( aText ); while( !lex.Eos() ) { if ( lex.Get() == 0x0A ) // "\n" character. Unix style { break; } } return aText.Left( lex.Offset() ); }
/** Copy a maximum of KTextFieldMinimalLength characters from aSrc to aDest. @param aSrc Source text buffer. @param aDest Destination text buffer. @return ETrue if copy was successfull, EFalse otherwise. */ TBool TCntPersistenceUtility::CopyMinFieldText(TPtrC aSrc,TDes& aDest) { TBool ret(EFalse); if(aSrc.Length() > 0) { TInt length = aSrc.Length(); if (length>KTextFieldMinimalLength) { length=KTextFieldMinimalLength; } aDest.Copy(aSrc.Left(length)); ret = ETrue; } return ret; }
// --------------------------------------------------------- // CWtaiHandler::GetWtaiLibraryFunctionL() // --------------------------------------------------------- // TPtrC CWtaiHandler::GetWtaiLibraryFunctionL() { CLOG_ENTERFN( "CWtaiHandler::GetWtaiLibraryFunction()" ); // wtai://<library>/<function> (; <parameter>)* TPtrC path = RemoveSchemeFromUrlL( KWtai ); // <library>/<function> (; <parameter>)* TInt colonPos = VerifyWtaiSchemeL( path ); TPtrC library_function = path.Left( colonPos ); CLOG_LEAVEFN( "CWtaiHandler::GetWtaiLibraryFunction()" ); return library_function; // <library>/<function> }
TInt CSwisExpressionEnvironment::ExtractNextToken(TPtrC& aTokenString, TPtrC& aParseString) { TInt separatorPosition = aParseString.LocateF(','); // Check that a separator was located within the parse string if(separatorPosition == KErrNotFound || separatorPosition > aParseString.Length()-1) { return KErrNotFound; } // Set the extracted token string and remove the token from the parse string aTokenString.Set(aParseString.Left(separatorPosition)); aParseString.Set(aParseString.Mid(separatorPosition+1)); return KErrNone; }
LOCAL_C void DistinguishElement(const TPtrC& aElement, RArray<TRange>& aSelectiveCaseRange) { TInt colonOccurance = aElement.FindC(KTEFColon); //we are expecting only a range or a test case ID over here... if( colonOccurance!=KErrNotFound ) { //then this is a range of testcases, split it at the colon TRange newRange(aElement.Left(colonOccurance),aElement.Mid(colonOccurance+1)); aSelectiveCaseRange.Append(newRange); } else { TRange newRange(aElement,aElement); aSelectiveCaseRange.Append(newRange); } }
/** * Reads the value present from the test steps ini file within the mentioned section name and key name * Copies the value to the TUint reference passed in. * If the value is prefixed with 0x the value is read as a hexadecimal value * If the value is suffixed with b the value is read as a binary value * If the value is prefixed with a 0 the value is read as an octal value * If it does not match the above it is read in as an integer * @param aSectName - Section within the test steps ini file * @param aKeyName - Name of a key within a section * @return aResult - The integer value of the Hex input * @return TBool - ETrue for found, EFalse for not found */ TBool CDataWrapperBase::GetUintFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint& aResult) { TPtrC result; TBool ret=EFalse; TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result)); if ( err != KErrNone ) { ret=EFalse; } if ( ret ) { TLex lex(result); if( result.FindC(KPrefixHex)==KErrNone ) { lex=result.Mid(KPrefixHex().Length()); ret=(lex.Val(aResult, EHex)==KErrNone); } else { TInt binarySuffixPosition=result.Length()-KSuffixBinary().Length(); if ( result.FindC(KSuffixBinary)==binarySuffixPosition ) { lex=result.Left(binarySuffixPosition); ret=(lex.Val(aResult, EBinary)==KErrNone); } else { if( result.FindC(KPrefixOctal)==KErrNone ) { ret=(lex.Val(aResult, EOctal)==KErrNone); } else { TInt intResult; ret=(lex.Val(intResult)==KErrNone); if ( ret ) { aResult=(TUint)intResult; } } } } } return ret; }
// --------------------------------------------------------------------------- // If aDevExt contains a valid friendly name, the friendly name will be displayed; // Otherwise, if the given name from the parameter of a notifier request is valid, // the given name will be displayed; // Otherwise, If aDevExt contains a valid device name, the name will be displayed; // Otherwise, the a name will be created by this function. // --------------------------------------------------------------------------- // void TBTNotifUtil::GetDeviceUiNameL( TDes& aNameBuf, const CBtDevExtension* aDevExt, const TDesC& aNameInParam, const TBTDevAddr& aAddr) { CBtDevExtension* tempDev( NULL ); TPtrC namePtr; if ( aDevExt && aDevExt->Device().IsValidFriendlyName() && aDevExt->Device().FriendlyName().Length() != 0 ) { // We always use the friendly name regardless of // the device-name of the device is available or not. namePtr.Set( aDevExt->Device().FriendlyName() ); } else { // this will take care of name formating. Either the // name from iNameInParam or the address will be // the alias: tempDev = CBtDevExtension::NewLC( aAddr, aNameInParam ); namePtr.Set( tempDev->Alias() ); } // Make sure no overflow: if ( aNameBuf.MaxLength() < namePtr.Length() ) { aNameBuf.Copy( namePtr.Left( aNameBuf.MaxLength() ) ); } else { aNameBuf.Copy( namePtr ); } if ( tempDev ) { CleanupStack::PopAndDestroy( tempDev ); } }
HBufC* CSwiEngine::FindInJadLC(HBufC* aJad, const TDesC& aProp) { TInt lineIndex = aJad->Find(aProp); TPtrC tmpPtr = aJad->Right(aJad->Length()-lineIndex-aProp.Length()); TInt crlfIndex = tmpPtr.Find(KCRLF); if(crlfIndex == -1) { // maybe bad jad crlfIndex = tmpPtr.Find(KLF); } TPtrC tmpPtr2 = tmpPtr; if(crlfIndex != -1) { // maybe this is the last line and there is no newline at the eol tmpPtr2.Set(tmpPtr.Left(crlfIndex)); } HBufC* ret = tmpPtr2.AllocLC(); TPtr ptr= ret->Des(); ptr.Trim(); return ret; }
EXPORT_C TInt TextUtils::ColumnText(TPtrC& aColumnText,TInt aColumn,const TDesC* aSourceText,TChar aColumnSeparator) /** Gets a portion of text from a descriptor, corresponding to a requested column. @param aColumnText On return, set to the portion of aSourceText that corresponds to the column aColumn. @param aColumn The column to extract. The first column is numbered zero. @param aSourceText The source text string that contains one or more column separators. @param aColumnSeparator The character used in aSourceText to separate the columns. By default, a tab character. @return KErrNotFound if the column number is invalid, otherwise KErrNone. */ { aColumnText.Set(TPtrC()); TInt end=0; TInt column=0; TPtrC text; if (aSourceText) text.Set(*aSourceText); while (text.Length()) { end=text.Locate(aColumnSeparator); if (end==KErrNotFound) end=text.Length(); if (column==aColumn) { aColumnText.Set(text.Left(end)); return(KErrNone); } else if (++column>aColumn) break; if (end<text.Length()) ++end; text.Set(text.Mid(end)); } return(KErrNotFound); }
// -------------------------------------------------------------------------- // CImageCapture::GetNextFileNameLC // Get the file name // -------------------------------------------------------------------------- HBufC* CImageCapture::GetNextFileNameLC(const TDesC& aName) const { const TInt KNumberLength = 4; // this is to indicate the file numbering, // e.g. 0001, 0002, etc. const TInt KMaxIndex = 10000; const TInt KTimeRecordSize = 512; TPtrC filePathPtr; _LIT(KExtensionpng, ".png"); _LIT(KSlash,"\\"); // Gets the file extension. TPtrC fileExtension; fileExtension.Set(KExtensionpng); filePathPtr.Set(iSettings.iLogPath); TInt result = filePathPtr.LocateReverse('\\'); TPtrC string; if(result!=KErrNotFound) string.Set(filePathPtr.Left(result+1)); TBuf8<KTimeRecordSize> fileName; fileName.Copy(string); if(iXmlFileName.Length()>0) { TInt pos=iXmlFileName.LocateReverse('.'); TPtrC8 ptr; if(pos!=KErrNotFound) { ptr.Set(iXmlFileName.Left(pos)); fileName.Append(ptr); } fileName.Append(KSlash); } fileName.Append(aName); HBufC* newFileName = HBufC::NewLC(fileName.Length()+ KNumberLength + fileExtension.Length() + 1); TPtr newFileNamePtr(newFileName->Des()); newFileNamePtr.Copy(fileName); // Checks whether aNamexxxx.png already exists on the phone or not. // This is to prevent over-riding of any existing images with the same name TBool IsFileExist = ETrue; TInt index = 1; HBufC* buffer = HBufC::NewL(newFileNamePtr.MaxLength()); TPtr bufferPtr(buffer->Des()); while ((index < KMaxIndex) && (IsFileExist)) { bufferPtr.Copy(newFileNamePtr); bufferPtr.AppendNumFixedWidth(index, EDecimal, KNumberLength); bufferPtr.Append(fileExtension); if (BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), *buffer)) { index++; } else { IsFileExist = EFalse; } } delete buffer; // If the index exceeds KMaxIndex, then we don't need to format the file name. if (index >= KMaxIndex) { newFileNamePtr.AppendNum(index); } else { newFileNamePtr.AppendNumFixedWidth(index, EDecimal, KNumberLength); } newFileNamePtr.Append(fileExtension); // If the index greated then KMaxIndex, then rollback to 1 if (index >= KMaxIndex) { index = 1; } return newFileName; }
void CSubViewTest::SubAndLocalViewCompareTestL() const { test.Printf(_L("Testing subview is accurate compared to the local view.")); const TInt KSubViewCount = iSubView->CountL(); const TInt KLocalViewCount = iNamedLocalView->CountL(); const TInt KFirstFieldIdx(0); TInt subViewIdx(0); TBool foundFirstInSubView(EFalse); TBool foundLastInSubView(EFalse); TInt subCntItemId(iSubView->AtL(subViewIdx)); TInt localCntItemId(-1); // initialise with a value that can't be a real Id for(TInt localViewIdx = 0; localViewIdx < KLocalViewCount && !foundLastInSubView; ++localViewIdx) { localCntItemId = iNamedLocalView->AtL(localViewIdx); // already found the first item in the sub view within // the underlying local view. if (foundFirstInSubView) { ++subViewIdx; subCntItemId = iSubView->AtL(subViewIdx); // check that the contact ids in the sub view and local view match if (subCntItemId != localCntItemId) { test.Printf(_L("Mismatch of contacts between subview and local view")); test(EFalse); } // if we've found the last sub view item, do boundary checking to // ensure we have the right things from the local view in the sub view. if (subViewIdx == KSubViewCount - 1) { foundLastInSubView = ETrue; // Haven't checked localViewIdx < KLocalViewCount but it's not // likely that the last contact in the sub view will legitimately // be the same as the last one in the local view. const TPtrC nextLocalName = iNamedLocalView->ContactAtL(localViewIdx + 1).Field(KFirstFieldIdx); const TPtrC subName = iSubView->ContactAtL(subViewIdx).Field(KFirstFieldIdx); // check that the first character of the last contact in the subview // is within the proper range and that the next contact in the // local view is outside the range. test.Printf(_L("Found last contact from subview in local view. Testing for errors.")); test(subName.Left(1).CompareF(KHighChar) <= 0 || nextLocalName.Left(1).CompareF(KHighChar) > 0); test.Printf(_L("-- check okay.")); } } // we've found the first contact item from the sub view in the local // view. check else if (localCntItemId == subCntItemId && !foundFirstInSubView) { foundFirstInSubView = ETrue; // Haven't checked localViewIdx != 0 but it is not likely that the // first contact in the local view will legitimately be the same as // the first one in the sub view. const TPtrC prevLocalName = iNamedLocalView->ContactAtL(localViewIdx - 1).Field(KFirstFieldIdx); const TPtrC subName = iSubView->ContactAtL(subViewIdx).Field(KFirstFieldIdx); // check that the first character of the first contact in the subview // is within the proper range and that the previous contact in the // local view is outside the range. test.Printf(_L("Found first contact from subview in local view. Testing for errors.")); test(subName.Left(1).CompareF(KLowChar) >= 0 && prevLocalName.Left(1).CompareF(KLowChar) < 0); test.Printf(_L("-- check okay.")); // check that we can find an expected contact item in the subview // and cannot find something that should not be there. test.Printf(_L("Testing FindL() functionality.")); test(iSubView->FindL(subCntItemId) == subViewIdx && iSubView->FindL(iNamedLocalView->AtL(localViewIdx - 1)) == KErrNotFound); test.Printf(_L("-- check okay.")); // check the AllFieldsLC functionality test.Printf(_L("Testing AllFieldsLC() functionality.")); _LIT(KDelimiter, ";"); HBufC* allFields = iSubView->AllFieldsLC(subViewIdx, KDelimiter()); TPtrC allFieldsPtr = allFields->Des(); TBufC<16> field0 = iSubView->ContactAtL(subViewIdx).Field(0); TBufC<16> field1 = iSubView->ContactAtL(subViewIdx).Field(1); TBufC<16> field2 = iSubView->ContactAtL(subViewIdx).Field(2); TBufC<16> field3 = iSubView->ContactAtL(subViewIdx).Field(3); TBuf<48> fieldsBuf; _LIT(KFormat, "%S;%S;%S;%S"); fieldsBuf.AppendFormat(KFormat(), &field0, &field1, &field2, &field3); test(fieldsBuf.Compare(allFieldsPtr) == 0); // they should be the same test.Printf(_L("-- check okay.")); CleanupStack::PopAndDestroy(allFields); } } }
void ParseCommandLine () { TBuf<64> c; User::CommandLine(c); c.LowerCase(); if (c != KNullDesC) { TLex lex(c); TPtrC token; while (token.Set(lex.NextToken()), token != KNullDesC) { if (token.Mid(0) == _L("quiet")) { gQuiet = ETrue; continue; } if (token.Mid(0) == _L("verbose")) { gQuiet = EFalse; continue; } if (token.Left(5) == _L("chunk")) { TInt equalPos; equalPos = token.Locate('='); if (equalPos > 0 && (equalPos+1) < token.Length()) { TLex lexNum(token.Mid(equalPos+1)); lexNum.Val(gChunkSize,EDecimal); } continue; } if (token.Left(3) == _L("low")) { TInt equalPos; equalPos = token.Locate('='); if (equalPos > 0 && (equalPos+1) < token.Length()) { TLex lexNum(token.Mid(equalPos+1)); lexNum.Val(gMin,EDecimal); } continue; } if (token.Left(5) == _L("high")) { TInt equalPos; equalPos = token.Locate('='); if (equalPos > 0 && (equalPos+1) < token.Length()) { TLex lexNum(token.Mid(equalPos+1)); lexNum.Val(gMax,EDecimal); } continue; } if (token.Left(6) == _L("period")) { TInt equalPos; equalPos = token.Locate('='); if (equalPos > 0 && (equalPos+1) < token.Length()) { TLex lexNum(token.Mid(equalPos+1)); lexNum.Val(gPeriod,EDecimal); } continue; } if (token.Left(3) == _L("mem")) { TInt equalPos; equalPos = token.Locate('='); if (equalPos > 0 && (equalPos+1) < token.Length()) { TLex lexNum(token.Mid(equalPos+1)); lexNum.Val(gMemScheme,EDecimal); } continue; } } } }
/** * Wraps the text and sets it into the labels. */ void CAknTextControl::ParseTextL(const CFont* aFont, CArrayFixFlat<TInt>* aLineWidths,const TWrapMethod& aWrapMethod) { if ( aWrapMethod == ENoAllocation && iWrappedArray ) { // We preallocate text required in construction of alert win, so we just replace the texts in labels. TPtrC remainder = Text(); TChar endlchar('\n'); TInt linebreak = remainder.LocateReverse(endlchar); TBuf<17 + KAknBidiExtraSpacePerLine> temp; //KEikAlertMaxMsgLength not declared in this scope if ( linebreak == KErrNotFound ) { AknBidiTextUtils::ConvertToVisualAndClip(remainder, temp, *aFont, KMaxTInt, KMaxTInt ); Line(0)->SetTextL(temp); // won't leave as there is enough space in buffer iLines[0]->iModified = ETrue; Line(1)->SetTextL(KNullDesC); iLines[1]->iModified = ETrue; } else { AknBidiTextUtils::ConvertToVisualAndClip( remainder.Left(linebreak), temp, *aFont, KMaxTInt, KMaxTInt ); Line(0)->SetTextL(temp); iLines[0]->iModified = ETrue; if ( remainder.Length()-1 == linebreak) // Line break is the last character { Line(1)->SetTextL(KNullDesC); } else { AknBidiTextUtils::ConvertToVisualAndClip( remainder.Right(remainder.Length()-linebreak-1), temp, *aFont, KMaxTInt, KMaxTInt ); Line(1)->SetTextL(temp); // we don't want new line to label, thus -1 } iLines[1]->iModified = ETrue; } return; } if (iTextIsAlreadyInLabel || !iWrappedArray) return; TInt maxLines = aLineWidths->Count(); // user handles all text processing if ( aWrapMethod == ENoProcessing ) { iWrappedArray->Reset(); TPtrC remainder = Text(); while ( remainder.Length() && iWrappedArray->Count() < maxLines ) { const TText* textArray = remainder.Ptr(); TInt textLength = remainder.Length(); TInt i = 0; for ( ; i < textLength ; i++ ) { TText t = textArray[i]; if ( t == KLineFeed || t == KLineSeparator || t == KParagraphSeparator || t == KCarriageReturn ) { break; } } iWrappedArray->AppendL( remainder.Left( i ) ); // After a CR, skip also possible matching LF if ( i < textLength - 1 && textArray[i] == KCarriageReturn && textArray[i + 1] == KLineFeed ) { i++; } i++; if ( i >= textLength ) { break; } remainder.Set( remainder.Right( textLength - i ) ); } } else { TPtr text = Text(); HBufC* visualBuffer = HBufC::NewLC( text.Length() + maxLines * KAknBidiExtraSpacePerLine ); *visualBuffer = text; TPtr ptr = visualBuffer->Des(); AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr); if (aWrapMethod == EWord) { AknBidiTextUtils::ConvertToVisualAndWrapToArrayL( ptr, *aLineWidths, *aFont, *iWrappedArray, ETrue ); } else if (aWrapMethod == ELine) { AknBidiTextUtils::ConvertToVisualAndChopToArrayL( ptr, *aLineWidths, *aFont, *iWrappedArray ); } else { __ASSERT_DEBUG(0,Panic(EAknPanicNotSupported)); } } TInt numLines = iWrappedArray->Count(); UpdateLabelsL(numLines,aFont,aLineWidths); SetWrappedTextIntoLabelsL(*iWrappedArray, numLines, aFont); if ( aWrapMethod != ENoProcessing ) { CleanupStack::PopAndDestroy(); // visualBuffer } }
/** Implementation of the insertion algorithm @param aNodeToStart the node whose children to start with @param aPath the path of the new node to be inserted @param aDirPos the position of the new node to be inserted @param aNodeInserted in return, the node that has been successfully inserted */ void CLeafDirTree::DoInsertL(CLeafDirTreeNode* aNodeToStart, const TDesC& aPath, const TLeafDirData& aLeafDirData, CLeafDirTreeNode*& aNodeInserted) { CLeafDirTreeNode* currentParent = aNodeToStart; TInt foundPos = 0; RPointerArray<CLeafDirTreeNode> currentLevel = aNodeToStart->Children(); TInt currentPos = currentLevel.Count() - 1; TPtrC currentPath; currentPath.Set(aPath); while (currentLevel.Count() > 0 && currentPos >= 0) { CLeafDirTreeNode* currentNode = currentLevel[currentPos]; TPtrC currentNodePath; currentNodePath.Set(currentNode->Path()); // If current node is contained by aPath. // E.g.: current node = "1\2\3\", currentPath = "1\2\3\5\" // In this case, we need to go to next level, // discard logged position (currentPos) in this level as we don't need to come back. foundPos = currentPath.FindF(currentNodePath); if (foundPos == 0 && currentNodePath.Length() < currentPath.Length()) { currentParent = currentNode; currentLevel = currentNode->Children(); currentPos = currentLevel.Count() - 1; currentPath.Set(currentPath.Mid(currentNodePath.Length())); continue; } // If current node's path contains aPath // E.g.: current node = "1\2\3\4\", currentPath = "1\2\3\" // We need to split current node to two nodes and return. foundPos = currentNodePath.FindF(currentPath); if (foundPos == 0 && currentNodePath.Length() > currentPath.Length()) { CLeafDirTreeNode* newNode = CLeafDirTreeNode::NewL(this, currentPath, aLeafDirData, CLeafDirTreeNode::ELeafIntermediary); currentParent->MakeItChildL(newNode); TPtrC restPath; restPath.Set(currentNodePath.Mid(currentPath.Length())); currentNode->SetPathL(restPath); currentParent->RemoveChild(currentNode); newNode->MakeItChildL(currentNode); AddOntoLruL(newNode); aNodeInserted = newNode; return; } // If current node's path equals aPath, // change the node type if it is necessary if (foundPos == 0 && currentNodePath.Length() == currentPath.Length()) { // Check node type, if already cached, update Lru list and return. if (currentNode->IsLeaf() || currentNode->IsLeafIntermediary()) { currentNode->SetLeafDirData(aLeafDirData); aNodeInserted = currentNode; MakeMostRecentlyUsed(currentNode); return; } // If it has not been cached yet, i.e., it is a 'pure intermediary' node, // cache the node and put it onto Lru list else if(currentNode->IsPureIntermediary()) { currentNode->SetLeafDirData(aLeafDirData); currentNode->SetType(CLeafDirTreeNode::ELeafIntermediary); AddOntoLruL(currentNode); aNodeInserted = currentNode; return; } } // If none of above is the case (i.e. haven't found exact match or paths // are not contained by each other), we need to find the first common part // between each child and aPath to share path data. foundPos = FindLongestCommonPath(currentNodePath, currentPath); // If a common part of path is found, we need to create a pure intermediary node to share // the common part of path data, and create a new leaf node for the target path. if (foundPos > 0) { TPtrC commonPath; commonPath.Set(currentNodePath.Left(foundPos + 1)); currentNodePath.Set(currentNodePath.Mid(foundPos + 1)); TPtrC newLeafPath; newLeafPath.Set(currentPath.Mid(foundPos + 1)); // Add new pureintermediary node, set it as child of current parent TLeafDirData dummyPos(0); CLeafDirTreeNode* newPureIntermediaryNode = CLeafDirTreeNode::NewL(this, commonPath, dummyPos, CLeafDirTreeNode::EPureIntermediary); currentParent->MakeItChildL(newPureIntermediaryNode); // Remove current child from aNodeToStart, do not need to change // node type of aNodeToStart currentParent->RemoveChild(currentNode); // Modify current pathData, make it child of new node newPureIntermediaryNode->MakeItChildL(currentNode); currentNode->SetPathL(currentNodePath); // Add new leaf node as a child of the new pure intermediary node CLeafDirTreeNode* newLeafNode = CLeafDirTreeNode::NewL(this, newLeafPath, aLeafDirData, CLeafDirTreeNode::ELeaf); newPureIntermediaryNode->MakeItChildL(newLeafNode); aNodeInserted = newLeafNode; AddOntoLruL(newLeafNode); return; } // Otherwise, move on within this level. currentPos--; } // No match case found, add a new node straight on at current level CLeafDirTreeNode* newNode = CLeafDirTreeNode::NewL(this, currentPath, aLeafDirData, CLeafDirTreeNode::ELeaf); if (currentParent->IsLeaf()) // might be the root node { currentParent->SetType(CLeafDirTreeNode::ELeafIntermediary); } currentParent->MakeItChildL(newNode); aNodeInserted = newNode; AddOntoLruL(newNode); }
/** @SYMTestCaseID SYSLIB-SQL-CT-1628 @SYMTestCaseDesc GetFirstSqlStmt() test Tests the GetFirstSqlStmt() behaviour with a set of various SQL statements. @SYMTestPriority High @SYMTestActions GetFirstSqlStmt() test @SYMTestExpectedResults Test must not fail @SYMREQ REQ5792 REQ5793 */ void TestGetFirstSqlStmt() { TPtrC res; TBuf<1> b2; b2.Append(TChar(0)); TPtr p2(PTR_ARG(b2)); res.Set(GetFirstSqlStmt(p2)); //Expected result: res = "\x0", p2 is NULL TEST(res == b2); TEST(!p2.Ptr()); TBuf<2> b3; b3.Append(TChar(' ')); b3.Append(TChar(0)); TPtr p3(PTR_ARG(b3)); res.Set(GetFirstSqlStmt(p3)); //Expected result: res = " \x0", p3 is NULL TEST(res == b3); TEST(!p3.Ptr()); TBuf<7> b4(_L(";; ; ")); b4.Append(TChar(0)); TPtr p4(PTR_ARG(b4)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = "\x0", p4 = "; ; \x0" TEST(res.Length() == 1 && (TInt)res[0] == 0); TInt accLen = res.Length(); TEST(p4 == b4.Right(b4.Length() - accLen)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = "\x0", p4 = " ; \x0" TEST(res.Length() == 1 && (TInt)res[0] == 0); accLen += res.Length(); TEST(p4 == b4.Right(b4.Length() - accLen)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = " \x0", p4 = " \x0" TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == 0); accLen += res.Length(); TEST(p4 == b4.Right(b4.Length() - accLen)); res.Set(GetFirstSqlStmt(p4)); //Expected result: res = " \x0", p4 is NULL TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == (TInt)TChar(' ') && (TInt)res[2] == 0); TEST(!p4.Ptr()); TBuf<20> b5(_L("SELECT * FROM A")); b5.Append(TChar(0)); TPtr p5(PTR_ARG(b5)); res.Set(GetFirstSqlStmt(p5)); //Expected result: res = "SELECT * FROM A\x0", p5 is NULL TEST(res == b5); TEST(!p5.Ptr()); TBuf<20> b6(_L("SELECT * FROM A;")); b6.Append(TChar(0)); TPtr p6(PTR_ARG(b6)); res.Set(GetFirstSqlStmt(p6)); //Expected result: res = "SELECT * FROM A\x0", p6 = "\x0" TEST(res == b6.Left(b6.Length() - 1)); TEST(p6.Length() == 1 && p6[0] == 0); TBuf<40> b7(_L("/** Comment */ SELECT * FROM A;")); b7.Append(TChar(0)); TPtr p7(PTR_ARG(b7)); res.Set(GetFirstSqlStmt(p7)); //Expected result: res = "/** Comment */ SELECT * FROM A\x0", p7 = "\x0" TEST(res == b7.Left(b7.Length() - 1)); TEST(p7.Length() == 1 && p7[0] == 0); TBuf<40> b8(_L(" SELECT * FROM --Comment \r\n A;")); b8.Append(TChar(0)); TPtr p8(PTR_ARG(b8)); res.Set(GetFirstSqlStmt(p8)); //Expected result: res = " SELECT * FROM --Comment \r\n A\x0", p8 = "\x0" TEST(res == b8.Left(b8.Length() - 1)); TEST(p8.Length() == 1 && p8[0] == 0); TBuf<40> b9(_L("SELECT * FROM A; SELECT * FROM B")); b9.Append(TChar(0)); TPtr p9(PTR_ARG(b9)); res.Set(GetFirstSqlStmt(p9)); //Expected result: res = "SELECT * FROM A\x0", p9 = " SELECT * FROM B\x0" TEST(res.Left(res.Length() - 1) == b9.Left(res.Length() - 1) && (TInt)res[res.Length() - 1] == 0); accLen = res.Length(); TEST(p9 == b9.Right(b9.Length() - accLen)); res.Set(GetFirstSqlStmt(p9)); //Expected result: res = " SELECT * FROM B\x0", p9 is NULL TEST(res == b9.Right(b9.Length() - accLen)); TEST(!p9.Ptr()); //Defect INC113060 TBuf<255> b10(_L("UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473")); TPtr p10(PTR_ARG(b10)); res.Set(GetFirstSqlStmt(p10)); //Expected results: res= original string TEST(res.Compare(b10)==0); TEST(!p10.Ptr()); TBuf<255> firstStmt(_L("SELECT * FROM PlayList"));firstStmt.Append(TChar(0)); TBuf<255> b11(_L("SELECT * FROM PlayList;UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473")); TPtr p11(PTR_ARG(b11)); res.Set(GetFirstSqlStmt(p11)); TEST(res.Compare(firstStmt)==0); TEST(p11.Compare(b10)==0); }
CConsoleCommand& CCommandLineParser::ParseL() { const TInt numArgs = iCmdLineArgs->Count(); // There must be at least two arguments: the name of the program and the name of a command if (numArgs <= 1) { User::Leave(KErrArgument); } // Extract the name of the command TPtrC arg0 = iCmdLineArgs->Arg(1); if (arg0.Left(KTxtOptionPrefix.iTypeLength) != KTxtOptionPrefix) { User::Leave(KErrArgument); } TPtrC cmdName = arg0.Mid(KTxtOptionPrefix.iTypeLength); // Look for the command in iCommands CConsoleCommand* cmd = NULL; for (TInt i=0; i<iCommands.Count(); ++i) { if (cmdName == iCommands[i]->Name()) { cmd = iCommands[i]; } } if (cmd == NULL) { User::Leave(KErrArgument); } // Iterate over the command's options and build pairs of optName and optValues TPtrC optName; RArray<TPtrC> optValues; CleanupClosePushL(optValues); for (TInt i=2; i<numArgs; ++i) { TPtrC arg = iCmdLineArgs->Arg(i); // Option name if (arg.Left(KTxtOptionPrefix.iTypeLength) == KTxtOptionPrefix) { // Process the previous option if (optName.Length()) { cmd->OptionHandlerL(optName, optValues); } // Set new option optName.Set(arg.Mid(KTxtOptionPrefix.iTypeLength)); if (optName.Length() == 0) { User::Leave(KErrArgument); } optValues.Reset(); } else { // Store the option's value optValues.AppendL(arg); } } // Process the last option if (optName.Length() || optValues.Count()) { cmd->OptionHandlerL(optName, optValues); } CleanupStack::PopAndDestroy(&optValues); // Return the current command return *cmd; }
// --------------------------------------------------------------------------- // CTestStartupListUpdater::RemoveL() // --------------------------------------------------------------------------- // TInt CTestStartupListUpdater::RemoveL( CStifItemParser& aItem ) { _LIT( KTestName, "Remove" ); Print( 0, KTestStartFormat, &KTestName ); TInt testResult = KErrNone; RSoftwareComponentRegistry registry; User::LeaveIfError( registry.Connect() ); CleanupClosePushL( registry ); // Get installed application TComponentIds and TUids RArray<TUid> uidList; CleanupClosePushL( uidList ); RArray<TComponentId> componentIdList; CleanupClosePushL( componentIdList ); registry.GetComponentIdsL( componentIdList ); for( TInt i = 0; i < componentIdList.Count(); ++i ) { TComponentId compId = componentIdList[ i ]; CComponentEntry *compEntry = CComponentEntry::NewLC(); if( registry.GetComponentL( compId, *compEntry ) ) { if( compEntry->IsRemovable() && compEntry->SoftwareType() == KSoftwareTypeNative ) { _LIT(KCompUid, "CompUid"); CPropertyEntry *property = registry.GetComponentPropertyL( compId, KCompUid ); CleanupStack::PushL( property ); CIntPropertyEntry* intProperty = dynamic_cast<CIntPropertyEntry*>( property ); uidList.AppendL( TUid::Uid( intProperty->IntValue() ) ); CleanupStack::PopAndDestroy( property ); } else { uidList.AppendL( KNullUid ); } } CleanupStack::PopAndDestroy( compEntry ); } if( uidList.Count() != componentIdList.Count() ) { _LIT( KFailedToGetIds, "Failed to get IDs" ); Print( 0, KTestStartFormat, &KFailedToGetIds ); testResult = KErrGeneral; } // Uninstall TUid apps listed in parameters TPtrC param; while( aItem.GetNextString ( param ) == KErrNone && testResult == KErrNone ) { const TUint KMaxLimit = 0xFFFFFFFF; TLex lex( param ); TUint32 intVal = 0; _LIT( KHexPrefix, "0x" ); if( param.Left( KHexPrefix().Length() ) == KHexPrefix ) { lex.Inc( KHexPrefix().Length() ); testResult = lex.BoundedVal( intVal, EHex, KMaxLimit ); } else { testResult = lex.BoundedVal( intVal, EDecimal, KMaxLimit ); } if( testResult == KErrNone ) { TUid uid( TUid::Uid( intVal ) ); if( uid != KNullUid ) { TInt index = uidList.Find( uid ); if( index >= 0 && index < componentIdList.Count() ) { TComponentId componentId = componentIdList[ index ]; RSoftwareInstall installer; User::LeaveIfError( installer.Connect() ); CleanupClosePushL( installer ); TRequestStatus status; installer.Uninstall( componentId, status ); User::WaitForRequest( status ); testResult = status.Int(); CleanupStack::PopAndDestroy( &installer ); } else { testResult = KErrNotFound; } } else { testResult = KErrUnknown; } } Print( 1, KTestParamFormatArg, &KTestName, ¶m, testResult ); } CleanupStack::PopAndDestroy( 3, ®istry ); // componentIdList, uidList, registry Print( 0, KTestDoneFormat, &KTestName ); return testResult; }