Пример #1
0
EXPORT_C TInt TEFparser::GetIniFileInfo(TDesC& aBuf, 
											  TPtrC& aIniFileName, 
											  TPtrC& aIniSectionName)
	{
	TInt pos =0;
	TInt startPos = 0, endPos = 0;
	
	
	TPtrC temp = aBuf.Mid(pos);
	
	endPos = temp.Find(KIniExtension);
	endPos += 4;
	
	if (endPos != KErrNotFound)
		{
		TInt len = endPos - startPos;
		TPtrC iniFileName = temp.Mid(startPos, len);
		aIniFileName.Set(iniFileName);
		
		TPtrC iniSectionName = temp.Mid(iniFileName.Length());
		aIniSectionName.Set(Trim(iniSectionName));
		
		return KErrNone;
		}
	else
		{
		return KErrNotFound;
		}
	
	}
Пример #2
0
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;
	}
Пример #3
0
inline TBool IsAdaptiveFindMatchClassic( const TDesC& aItemString, const TDesC& aSearchText )
    {
    TPtrC itemptr = aItemString;
    TPtrC searchptr = aSearchText;

    TBool match = EFalse;
    
    for(;;) 
        {
        // Loop invariant: itemptr is next character from ' ' or '-'
        // Loop invariant: seachptr is at beginning of searched item
    
        TInt val = MyFindC(itemptr,searchptr);
        if (val == 0)
            {
            match = ETrue;
            break;
            }
        if (val != KErrNotFound && IsFindWordSeparator(itemptr[val-1]))
            {
            match = ETrue;
            break;
            }

        // find the word separator characters from list item
        TInt spacepos = itemptr.LocateF(TChar(' '));
        TInt minuspos = itemptr.LocateF(TChar('-'));
        TInt tabpos = itemptr.LocateF(TChar('\t'));
        if (spacepos != KErrNotFound)
            {
            itemptr.Set(itemptr.Mid(spacepos+1));
            }
        else if (minuspos != KErrNotFound)
            {
            itemptr.Set(itemptr.Mid(minuspos+1));
            }
        else if (tabpos != KErrNotFound)
            {
            itemptr.Set(itemptr.Mid(tabpos+1));
            }
        else
            {
            match = EFalse;
            break;
            }
        if (itemptr.Length() == 0)
            {
            match = EFalse;
            break;
            }

        }
    return match;
    }	
Пример #4
0
/**
 * Reads the value present from the test steps ini file within the mentioned section name and key name
 * Copies the value to the TInt reference passed in. The value can optionally be prefixed with 0x
 * @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::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
	{
	TPtrC	result;
	TBool	ret=EFalse;
	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
	if ( err != KErrNone )
		{
		ret=EFalse;
		}
	if ( ret )
		{
		TLex	lex;
		if( result.FindC(KPrefixHex)==KErrNone )
			{
			lex=result.Mid(KPrefixHex().Length());
			}
		else
			{
			lex=result;
			}
		ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
		}

	return ret;
	}
Пример #5
0
EXPORT_C TPtrC TEFparser::GetRunTestStep(TPtrC& aBuf, 
									const TDesC& aTag,
									TInt& aPos,
									TInt& aError)
	{
	TInt endPos = 0;
	TInt startPos = 0;
	TInt tempPos = 0;
	
	TPtrC data = aBuf.Mid(aPos);
	
	tempPos = data.Find(aTag);
	
	if (tempPos != KErrNotFound)
		{
		tempPos += aTag.Length();
//			
		TPtrC temprunStepData = data.Mid(tempPos);		
//		
		endPos = temprunStepData.Find(KNewline);
		if (endPos == KErrNotFound)
			{
			endPos = temprunStepData.Find(KReturn);
			}
		if (endPos == KErrNotFound)
			{
			endPos = temprunStepData.Length();
			}
//		
		TInt len = 0;
		len = (endPos - startPos) + 1;
		TPtrC runStepData = temprunStepData.Mid(startPos,len);
		aPos += tempPos + runStepData.Length();
		aError = KErrNone;
		return Trim(runStepData);
		}
	else
		{
		aError = KErrNotFound;
		return TPtrC();
		}

	}
void CTestRControlChannel::ExtractServiceDescriptionL (const TDesC& aConfigSection, CUPnPServiceRegisterParamSet& aServiceRegisterParamSet)
	{
	RFs fs;
	RFile file;
	RBuf8 buf;

	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);

	TPtrC descriptionPath;
	_LIT(KDescriptionPath, "Description_Path");
	GetStringFromConfig(aConfigSection, KDescriptionPath, descriptionPath);

	TInt err = file.Open(fs, descriptionPath, EFileShareReadersOnly);
	
	// For Hardware system path is c:, so descriptionPath value present in '.ini' is referring 'c:'
	if ( err == KErrPathNotFound )
		{				
		RBuf fileName;
		TDriveName aSystemDrive;
		TDriveUnit driveunit(RFs::GetSystemDrive());
		aSystemDrive.Zero();
		aSystemDrive=driveunit.Name();				
		fileName.CreateL ( descriptionPath.Length () );
		fileName.Zero();
		fileName.Append(aSystemDrive);
		fileName.Append ( descriptionPath.Mid ( aSystemDrive.Length () ) );				
		
		err = file.Open(fs, fileName, EFileShareReadersOnly);
		}
	if (err != KErrNone)
		{
		User::LeaveIfError(err);
		}

	CleanupClosePushL(file);
	TInt fileSize = 0;
	file.Size(fileSize);

	buf.Create(fileSize);

	err = file.Read(buf, fileSize);
	aServiceRegisterParamSet.SetServiceDescriptionL ( buf );

	CleanupStack::PopAndDestroy(2 );
	buf.Close();
	_LIT(KInfoLogFile, "CRControlChannelObserver::ExtractServiceDescriptionL End.... \n");
	INFO_PRINTF1(KInfoLogFile);
	}
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;
	}
Пример #8
0
/**
 * 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;
	}
Пример #9
0
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);	
		}
}
Пример #10
0
TInt CIniData::StepToNextBlock()
/**
Locates the next available block of data within a section

@return ETrue if successful or EFalse
*/
	{
	if (BlockState != E_UNKNOWN)
		{
		// get unscanned portion of the section
		TPtrC temp = section.Mid(scanStart);

		// find the start of the next block
		if (BlockState == E_SET)
			{
			blockStart = temp.FindF(TPtrC(BEGIN_SET));
			blockEnd = temp.FindF(TPtrC(END_SET));
			}
		else if (BlockState == E_TEMPLATE)
			{
			blockStart = temp.FindF(TPtrC(BEGIN_TEMPLATE));
			blockEnd = temp.FindF(TPtrC(END_TEMPLATE));
			}
		else if (BlockState == E_ADD)
			{
			blockStart = temp.FindF(TPtrC(BEGIN_ADD));
			blockEnd = temp.FindF(TPtrC(END_ADD));
			}

		if (blockStart != KErrNotFound && blockEnd != KErrNotFound)
			{
			// set the start point for the next block search
			scanStart += blockEnd;
			scanStart++;

			// set the actual block to work with
			blockEnd -= blockStart;
			TPtrC tempBlock = temp.Mid(blockStart,blockEnd);
			block.Set((unsigned short *)tempBlock.Ptr(), tempBlock.Length(), tempBlock.Size());
			return ETrue;
			}
		}

	return EFalse;
	}
Пример #11
0
/**
Search for a node by directory path, start from children of aNodeToStart but do not include aNodeToStart.

@param	aPath			the path as the key to search in the tree
@param	aNodeToStart	the node whose children to start with 
@param	aNodeFound		in return, the node found 
@param	aDirPos			the location of the directory
@return	KErrNone 		if a node found
		KErrNotFound 	if no node is found
*/
TInt CLeafDirTree::DoSearch(const TDesC& aPath, CLeafDirTreeNode* aNodeToStart, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aLeafDirData)
	{
	RPointerArray<CLeafDirTreeNode> currentLevel = aNodeToStart->Children();
	TInt currentPos = currentLevel.Count() - 1;
	// Current path in search
	TPtrC currentPath;
	currentPath.Set(aPath);
	while (currentLevel.Count() > 0 && currentPos >= 0)
		{
		CLeafDirTreeNode* currentNode = currentLevel[currentPos];
		TPtrC currentNodePath;
		currentNodePath.Set(currentNode->Path());
		TInt foundPos = currentPath.FindF(currentNodePath);
		// If current child's path is part of the searching path, 
		// 	go to next level
		// 	E.g.: current child's path = "1\2\3\", searching path = "1\2\3\5\".
		if (foundPos == 0 && currentNodePath.Length() < currentPath.Length())
			{
			currentPath.Set(currentPath.Mid(currentNodePath.Length()));
			currentLevel = currentNode->Children();
			currentPos = currentLevel.Count() - 1;
			continue;
			}
		// If current child's path matches current searching path,
		// 	check the node type.
		else if (foundPos == 0 && currentNodePath.Length() == currentPath.Length())
			{
			if (currentNode->IsPureIntermediary())
			// If found is 'pure intermediary', it is not cached. 
				{
				return KErrNotFound;
				}
			// Otherwise, we have got a cache hit!
			MakeMostRecentlyUsed(currentNode);
			aNodeFound = currentNode;
			aLeafDirData = currentNode->LeafDirData();
			return KErrNone;
			}
		// else, go through current level
		currentPos--;
		}
	// If there is no child or we have not found any matching node,
	//	return KErrNotFound
	return KErrNotFound;
	}
Пример #12
0
/**
The function parses thr database file name argument and extracts the SID from it (if the name contains SID).
The SID is expected to be found at position 0 of the file name and must have 8 hex digits.

@param aDbFileName Database file name

@return Database security UID or KNullUid if the database name does not contain SID.

@internalComponent
*/
static TUid ExtractSID(const TDesC& aDbFileName)
	{
	TParsePtrC parse(aDbFileName);//this call may panic if aDbFileName cannot be parsed, but SetL() already parsed it
	TPtrC dbName = parse.Name();
	TInt pos1 = dbName.Locate(TChar('['));
	TInt pos2 = dbName.Locate(TChar(']'));
	if(pos1 == 0 && pos2 == 9)	//position 0 for '[', 8 digits SID, position 9 for ']'
		{
		TLex lex(dbName.Mid(pos1 + 1, pos2 - pos1 - 1));
		TUid securityUid;
		TInt err = lex.Val(*(TUint32*)&securityUid, EHex);
		if(err == KErrNone)
			{
			return securityUid;	
			}
		}
	return KNullUid;
	}
Пример #13
0
// ---------------------------------------------------------
// CWtaiHandler::GetParameterL()
// ---------------------------------------------------------
//
TPtrC CWtaiHandler::GetParameterL(TInt aPos)
	{
	CLOG_ENTERFN( "CWtaiHandler::GetParameter()" );

	// wtai://<library>/<function> (; <parameter>)*

	TPtrC path = RemoveSchemeFromUrlL( KWtai );

	// <library>/<function> (; <parameter>)*

	TInt length = path.Length();
	TInt start = 0; // starting position of the required parameter
	TInt pos = 1;   // current parameter
	TInt i = 0;     // character iterator

	while( i < length )
		{
		if( ( path[i] == KSemiColon )  || ( path[i] == KExclamationMark ) )
			{
			// begining of a parameter is found
			if( ( pos == aPos ) &&  ( path[i] != KExclamationMark ) )
				{
				// begining of the required parameter
				start = i + 1; // skipping semicolon
				}
			else
				{
				if( start != 0 )
					{
					// end of the required parameter
					break;
					}
				}
			pos++;
			}
		i++;
		}

	start = ( start == 0 ) ? i : start; // there is n parameter but the (n+1). is required

	CLOG_LEAVEFN( "CWtaiHandler::GetParameter()" );

	return path.Mid( start, i-start ); // found parameter
	}
Пример #14
0
void CUrl::ConstructL(const TDesC& aUrl)
//
//	Non-trivial c'tor - can be used for all general urls
	{
	// Stripe any leading whitespace
	TPtrC url = aUrl;
	while( url.Locate(' ') == 0 )
		{
		// Remove the leading whitespace -> set pointer to second character
		url.Set(url.Mid(1));
		}
	iUrlDes = url.AllocL();

	// Check to see if there's ':' at start of aUrl
	TInt colonPos = aUrl.Locate(':');
	if (colonPos == 0)
		User::Leave(EWapErrCorruptUrl);
	TPtrC scheme(Component(EUrlScheme));
	CheckSchemeValidL(scheme);
	}
// ---------------------------------------------------------------------------
// Unpackages TConnMonWLANNetwork from TPtrC descriptor
// ---------------------------------------------------------------------------
//
EXPORT_C TConnMonWLANNetwork TConnMonWLANNetwork::FromPtrC( const TPtrC& aPtrC )
    {

    TUint len( (TUint)aPtrC[ENameLength] );
    TBuf<KMaxNameLength> name( aPtrC.Mid(EName, len) );
    TUint connectionMode( aPtrC[len+EConnectionMode] );
    TUint signalStrength( aPtrC[len+ESignalStrength] );
    TUint securityMode( aPtrC[len+ESecurityMode] );

    RArray<TInt> buf;
    TUint count( aPtrC[len+EBufCounter] );
    for ( TUint i = 1; i < count+1; ++i )
        {
        buf.Append( aPtrC[len+EBufBase+i] );
        }
    TConnMonWLANNetwork connMonWLANNetwork = TConnMonWLANNetwork( name, 
            connectionMode, signalStrength, securityMode, buf );
    buf.Close();
    return connMonWLANNetwork;
    }
Пример #16
0
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);
	}
Пример #17
0
// ---------------------------------------------------------
// CMailToHandler::GetField()
// ---------------------------------------------------------
//
TPtrC CMailToHandler::GetField(const TDesC& aHeader)
	{
	CLOG_ENTERFN( "CMailToHandler::GetField()" );

	TPtrC path = iParsedUrl->Des();

	TInt start = 0;
	TInt end = 0;

	CMailToHandler::TSchemeMailToFields posHeader = GetHeaderPos( aHeader );
	// field start from; and end at 
	switch( posHeader )
		{
		case ESchemeMailTo: // MailTo
			{
			start = FieldStart( KMailto );
			end = FieldEnd( KMailto );
			break;
			}
		case ESchemeSubject: // Subject
			{
			start = FieldStart( KSubject );
			end = FieldEnd( KSubject );
			break;
			}
		case ESchemeMsgBody: // Msg Body
			{
			start = FieldStart( KBody );
			end = FieldEnd( KBody );
			break;
			}
		case ESchemeCc: // Cc
			{
			start = FieldStart( KCc );
			end = FieldEnd( KCc );
			break;
			}
		case ESchemeTo: // To
			{
			start = FieldStart( KTo );
			end = FieldEnd( KTo );
			break;
			}
		case ESchemeBcc: // Bcc
			{
			start = FieldStart( KBcc );
			end = FieldEnd( KBcc );
			break;
			}
		case ESchemeNoMore:
			break;
		}

    // check that everything is OK
    if( start > end )
        {
        end = path.Length();
        }
	CLOG_LEAVEFN( "CMailToHandler::GetField()" );

	return path.Mid( start, end-start );
	}
Пример #18
0
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;
				}

			}
		}
	}
/**
 * Finds the java attribute specified by
 * aAttributeName from aJad and returns the value of that attribute
 * in HBufC.
 * @param[in] aJad contents of Jad file
 * @param[in] aAttributeName the name of a java attribute
 * @return the value of the attribute. Caller gets the ownership of the
 * returned HBufC.
 * If the attribute is not found, returns NULL
 */
HBufC *CSilentMIDletInstall::ParseAttribute(const HBufC *aJad, const TDesC& aAttributeName)
{
    JELOG2(EJavaPreinstaller);

    TInt    nInd(0);
    TBool   fullNameFound(EFalse);
    TUint32 ch;

    // Start parsing from the beginning of the Jad file
    TPtrC parsePtr = aJad->Mid(nInd);

    do
    {
        // Find attribute name
        nInd = parsePtr.Find(aAttributeName);
        if (nInd < 0)
        {
            // Returns NULL if the attribute cannot be found
            return NULL;
        }

        // Check that the attribute name was preceded by line break or
        // it was at the beginning of the Jad file
        if (nInd == 0)
        {
            fullNameFound = ETrue;
        }
        else
        {
            ch = parsePtr[nInd-1];
            if ((ch == CR) || (ch == LF))
            {
                fullNameFound = ETrue;
            }
            else
            {
                // Name was just a part of longer string (not 'word match')
                fullNameFound = EFalse;
                // Skip to the last character of the found match.
                // We can skip because we are insterested only in 'word' matches
                // so the next cannot start inside the area we are skipping now.
                parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length() - 1));
                continue;
            }
        }

        // Check whether Jad file ends after attribute name
        if (nInd + aAttributeName.Length() >= parsePtr.Length())
        {
            // Jad file ends immediately after the found
            // attribute name instance. No attribute value
            return NULL;
        }

        // Check that there is a white space character or colon after
        // attribute name
        ch = parsePtr[nInd + aAttributeName.Length()];
        if ((ch == COLON) || (ch == SP) || (ch == HT))
        {
            fullNameFound = ETrue;
        }
        else
        {
            // Name was just a part of longer string (not 'word match')
            fullNameFound = EFalse;
            // Skip to the next character after the found match
            parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length()));
            continue;
        }
    }
    while (!fullNameFound);

    // Skip to the end of the attribute name and find ':' after the name.
    // The skipped characters must be white space chacraters, otherwise
    // the attribute name is illegal and Java Installer will not accept
    // the Jad file.
    parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length() - 1));
    nInd = parsePtr.Locate(COLON);
    if (nInd < 0)
    {
        return NULL;
    }
    nInd++;

    // Parse attribute value (CR or LF ends)
    TInt nEndInd = parsePtr.Locate(CR);
    TInt nTmpInd = parsePtr.Locate(LF);

    if (KErrNotFound == nEndInd)
    {
        nEndInd = parsePtr.Length() - 1;
    }
    if (KErrNotFound == nTmpInd)
    {
        nTmpInd = parsePtr.Length() - 1;
    }

    if (nTmpInd < nEndInd)
    {
        nEndInd = nTmpInd;
    }

    if (nEndInd < nInd)
    {
        return NULL;
    }

    TPtrC attributeValue = parsePtr.Mid(nInd, (nEndInd - nInd));

    // Remove possible white space from the beginning and end of the value
    HBufC *bufValue = attributeValue.Alloc();
    if (NULL == bufValue)
    {
        return NULL;
    }
    TPtr value = bufValue->Des();
    value.Trim();

    return bufValue;
} // parseAttribute
/**
Resolves sub string and directionality of the sub string.
Adds no dir marker if directionality of the string not found.
*/
HBufC* CResourceLoader::ResolveSubStringL(TDes& aText, TBool* aMarker)
    {
    // Allocating heap buffer for return string.
    TInt destlength(aText.Length());
    HBufC* retbuf = HBufC::NewLC(destlength + 1); // no dir marker
    TPtr retptr(retbuf->Des());
    
    TBuf<1> marker;
    marker.Append(KDirNotFound);
        
    TPtrC remainder = aText.Right(aText.Length());
    TInt nextKey = remainder.Locate(KSubStringSeparator);
    
    if (nextKey == 0)
        {
        remainder.Set(remainder.Mid(1));
        nextKey = remainder.Locate(KSubStringSeparator);
        if (nextKey != KErrNotFound)
            {
            retptr.Insert(0, aText.Mid(1, nextKey));           
            // Remove string from aText
            aText.Delete(0, nextKey + 1);
            }
        else
            {
            TInt length = aText.Length();
            retptr.Insert(0, aText.Mid(1, length - 1));
            // Remove string from aText
            aText.Delete(0, length);
            }
        }
    else if (nextKey == KErrNotFound)
        {
        retptr.Insert(0, aText); 
        // Remove string from aText
        aText.Delete(0, aText.Length());
        }
    else
        {
        retptr.Insert(0, aText.Mid(0, nextKey));
        // Remove string from aText
        aText.Delete(0, nextKey);
        }
     
    // Resolve directionality of sub string
    HBufC* dirbuf = retbuf->AllocL();
    TPtr dirptr = dirbuf->Des();
    TBool found(EFalse);
    TBidiText::TDirectionality mainDir = ResolveDirectionality(dirptr, &found);
    delete dirbuf;
    
    if (!found)
        {
        retptr.Insert(0, marker);
        *aMarker = ETrue;
        }
    else
        {
        *aMarker = EFalse;
        }
        
    retbuf = retbuf->ReAllocL(retptr.Length());
    CleanupStack::Pop(); //retbuf
    // If the key string wasn't found, retbuf is empty.
    return retbuf;     
    }
//
// Draws the item, which might contain an icon and a text.
// The format of the item text shall look like one of the following formats:
//		- "\ttext"				(text only)
//		- "icon\ttext"			(icon and text)
//		- "\theading\ttext"		(heading and text)
//		- "icon\theading\ttext"	(icon, heading and text)
//		
void CMediaScreenListItemDrawer::DrawActualItem(TInt aItemIndex,
		const TRect& aActualItemRect, TBool aItemIsCurrent,
		TBool /*aViewIsEmphasized*/, TBool /*aViewIsDimmed*/,
		TBool aItemIsSelected) const
	{
	const MDesCArray* itemArray = iListBox.Model()->ItemTextArray();
	if ((!itemArray) || (itemArray->MdcaCount() <= aItemIndex))
		return;
    
	// Gets the item text if the conditions above are met.
	TPtrC itemText = itemArray->MdcaPoint(aItemIndex);

	// We have to find the position of tabs to decide the components
	// available in the item text (icon, heading and text).
	TInt tabPosition1 = itemText.Locate('\t');
	TInt tabPosition2 = itemText.Mid(tabPosition1 + 1).Locate('\t');
	if (tabPosition2 >= 0)
		{
		// We need to add tabPosition1 because the return value of
		// Locate() is relative to tabPosition1.
		tabPosition2 += tabPosition1 + 1;
		}
	TInt tabPosition3 = itemText.Mid(tabPosition2 + 1).Locate('\t');
	if (tabPosition3 >= 0)
		{
		// We need to add tabPosition2 because the return value of
		// Locate() is relative to tabPosition2.
		tabPosition3 += tabPosition2 + 1;
		}
	TInt tabPosition4 = itemText.Mid(tabPosition3 + 1).Locate('\t');
	if (tabPosition4 >= 0)
		{
		// We need to add tabPosition2 because the return value of
		// Locate() is relative to tabPosition2.
		tabPosition4 += tabPosition3 + 1;
		}

	// Sets the attributes to draw the icon.
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
	if ((aItemIsCurrent) || (aItemIsSelected))
		{
		iGc->SetBrushColor(iHighlightedBackColor);
		}
	else
		{
		iGc->SetBrushColor(iBackColor);
		}

	// Gets the icon index, i.e. the number in the text item before
	// the first tab.
	TInt iconIndex = 0;
	if (tabPosition1 > 0)
		{
		TLex(itemText.Mid(0, tabPosition1)).Val(iconIndex);
		}

		TRect aActualItemRect2 = aActualItemRect;

		aActualItemRect2.iBr.iX = aActualItemRect2.iBr.iX + 0;
		aActualItemRect2.iBr.iY = aActualItemRect2.iBr.iY + 0;
		aActualItemRect2.iTl.iX = aActualItemRect2.iTl.iX + 0;
		aActualItemRect2.iTl.iY = aActualItemRect2.iTl.iY + 10;

	if ((iIconArray) && (iIconArray->Count() > iconIndex)
		&& (tabPosition1 > 0))
		{
		// Draws the icon.
		CFbsBitmap* bitmap = (*iIconArray)[iconIndex]->Bitmap();
		iGc->BitBltMasked(
			aActualItemRect2.iTl,
			bitmap,
			TRect(TPoint(0, 0), bitmap->Header().iSizeInPixels),
			(*iIconArray)[iconIndex]->Mask(),
			ETrue);

		// Draws the rectangle, just in case there are some icons that are
		// smaller than the height of item width and/or height.
		iGc->SetPenStyle(CGraphicsContext::ENullPen);
		if (bitmap->Header().iSizeInPixels.iHeight < aActualItemRect2.Height())
			{
			TRect rect(
				aActualItemRect2.iTl.iX,
				aActualItemRect2.iTl.iY + bitmap->Header().iSizeInPixels.iHeight,
				aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect2.iBr.iY);
			
			TRect rect1(
				aActualItemRect2.iTl.iX,
				aActualItemRect2.iTl.iY - 10,
				aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect2.iBr.iY - 40 );

			    iGc->DrawRect(rect);
			    iGc->DrawRect(rect1);
			}

		if (bitmap->Header().iSizeInPixels.iWidth < iMaxIconSize.iWidth)
			{
			TRect rect = TRect(
				aActualItemRect2.iTl.iX + bitmap->Header().iSizeInPixels.iWidth,
				aActualItemRect2.iTl.iY,
				aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect2.iBr.iY);
			iGc->DrawRect(rect);
			}
		}
	else
		{
		iGc->SetPenStyle(CGraphicsContext::ENullPen);
		TRect rect(
			aActualItemRect.iTl.iX,
			aActualItemRect.iTl.iY,
			aActualItemRect.iTl.iX + iMaxIconSize.iWidth,
			aActualItemRect.iBr.iY);
		iGc->DrawRect(rect);
		}

	// Sets the attributes to draw text, except the font.
	const CFont* font = Font(aItemIndex);
	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
	if ((aItemIsCurrent) || (aItemIsSelected))
		{
		iGc->SetPenColor(iHighlightedTextColor);
		iGc->SetBrushColor(iHighlightedBackColor);
		}
	else
		{
		iGc->SetPenColor(iTextColor);
		iGc->SetBrushColor(iBackColor);
		}

	// If there is only one tab, it means we have to display single line item
	if (tabPosition2 < 0)
		{		
		if (!font)
			{
			font = CEikonEnv::Static()->TitleFont();
			}
		iGc->UseFont(font);
		TRect textRect(
			TPoint(aActualItemRect.iTl.iX + iMaxIconSize.iWidth,
					aActualItemRect.iTl.iY),
			aActualItemRect.iBr);
		TInt baseline =
			(textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2
				+ font->AscentInPixels();

		TBuf<2000> text;
		text.Copy(_L("   "));

		if (tabPosition1 < 0)
			{
			text.Append(itemText);
			iGc->DrawText(text, textRect, baseline,	CGraphicsContext::ELeft, 1);
			}
		else
			{
			text.Append(itemText.Mid(tabPosition1 + 1));
			iGc->DrawText(text, textRect, baseline,CGraphicsContext::ELeft, 1);
			}
		}
	else
		{
		// If there are more than one tab, then we have to display double line
		// item text
		TRect textRect(
			TPoint(aActualItemRect.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect.iTl.iY),
			aActualItemRect.iBr);
		textRect.iBr.iY -= aActualItemRect.Height() / 2;

		// Draws the first line.
		if (!font)
			{
			font = CEikonEnv::Static()->LegendFont();
			}
		iGc->UseFont(font);
		TInt baseline =
			(textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2
				+ font->AscentInPixels();

		TBuf<2000> text;
		text.Copy(_L(" "));
		text.Append(itemText.Mid(tabPosition1 + 1, tabPosition2 - tabPosition1 - 1));

		iGc->DrawText(text,textRect, baseline, CGraphicsContext::ELeft, 1);

		// Draws the second line. For the second line, we use normal font.
		font = CCoeEnv::Static()->NormalFont();
		iGc->UseFont(font);
		textRect.Move(0, aActualItemRect.Height() / 2);
		baseline =
			(textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2
				+ font->AscentInPixels();///
		
		text.Copy(_L(" "));
		//text.Append(itemText.Mid(tabPosition2 + 1));		
		text.Append(itemText.Mid(tabPosition2 + 1, tabPosition3 - tabPosition2 - 1));

		iGc->DrawText(text, textRect, baseline,	CGraphicsContext::ELeft, 1);
		
		//Loads 2nd bitmap
		TRect aActualItemRect1 = aActualItemRect;

		aActualItemRect1.iBr.iX = aActualItemRect1.iBr.iX + 0;
		aActualItemRect1.iBr.iY = aActualItemRect1.iBr.iY + 0;
		
		if (tabPosition4 >= 0)
			aActualItemRect1.iTl.iX = aActualItemRect1.iTl.iX + 160;
		else
			aActualItemRect1.iTl.iX = aActualItemRect1.iTl.iX + 180;

		aActualItemRect1.iTl.iY = aActualItemRect1.iTl.iY + 0;
		
		text.Copy(_L(""));
		text.Append(itemText.Mid((tabPosition3 + 1),1));
		
		TInt type;

		TLex lex(text);
		lex.Val(type);

		// Draws the icon.
		CFbsBitmap* bitmap = (*iIconArray)[type]->Bitmap();

		iGc->BitBltMasked(aActualItemRect1.iTl,
			bitmap,TRect(TPoint(0,0), bitmap->Header().iSizeInPixels),
			(*iIconArray)[type]->Mask(),
			ETrue);

		// Draws the rectangle, just in case there are some icons that are
		// smaller than the height of item width and/or height.
		iGc->SetPenStyle(CGraphicsContext::ENullPen);
		if (bitmap->Header().iSizeInPixels.iHeight < aActualItemRect1.Height())
			{
			TRect rect(
				aActualItemRect1.iTl.iX,
				aActualItemRect1.iTl.iY + bitmap->Header().iSizeInPixels.iHeight,
				aActualItemRect1.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect1.iBr.iY);
			iGc->DrawRect(rect);
			}

		if (bitmap->Header().iSizeInPixels.iWidth < iMaxIconSize.iWidth)
			{
			TRect rect = TRect(
				aActualItemRect1.iTl.iX + bitmap->Header().iSizeInPixels.iWidth,
				aActualItemRect1.iTl.iY,
				aActualItemRect1.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect1.iBr.iY);
			iGc->DrawRect(rect);
			}	

		if (tabPosition4 >= 0)
		{
			//load 3rd bitmap
			TRect aActualItemRect2 = aActualItemRect;

			aActualItemRect2.iBr.iX = aActualItemRect2.iBr.iX + 0;
			aActualItemRect2.iBr.iY = aActualItemRect2.iBr.iY + 0;
			aActualItemRect2.iTl.iX = aActualItemRect2.iTl.iX + 180;
			aActualItemRect2.iTl.iY = aActualItemRect2.iTl.iY + 0;
			
			text.Copy(_L(""));
			text.Append(itemText.Mid((tabPosition4 + 1),1));
			
			type = 0;

			TLex lex1(text);
			lex1.Val(type);

			// Draws the icon.
			CFbsBitmap* bitmap1 = (*iIconArray)[type]->Bitmap();
			iGc->BitBltMasked(aActualItemRect2.iTl,
				bitmap1,TRect(TPoint(0,0), bitmap1->Header().iSizeInPixels),
				(*iIconArray)[type]->Mask(),
				ETrue);

			// Draws the rectangle, just in case there are some icons that are
			// smaller than the height of item width and/or height.
			iGc->SetPenStyle(CGraphicsContext::ENullPen);
			if (bitmap1->Header().iSizeInPixels.iHeight < aActualItemRect2.Height())
				{
				TRect rect(
					aActualItemRect2.iTl.iX,
					aActualItemRect2.iTl.iY + bitmap1->Header().iSizeInPixels.iHeight,
					aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
					aActualItemRect2.iBr.iY);
				iGc->DrawRect(rect);
				}

			if (bitmap1->Header().iSizeInPixels.iWidth < iMaxIconSize.iWidth)
				{
				TRect rect = TRect(
					aActualItemRect2.iTl.iX + bitmap1->Header().iSizeInPixels.iWidth,
					aActualItemRect2.iTl.iY,
					aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
					aActualItemRect2.iBr.iY);
				iGc->DrawRect(rect);
				}
			}
		}
	}
Пример #22
0
void CUrl::Part(TComponent aComponent, const TDesC& aUrl, TInt& aStartPos, TInt& aEndPos) const
//
// Takes a descriptor as a url and parses it for the start and end positions of a particular component. 
// KCUrlInvalidCharPos is used to indicate that component is not in url.
// 
// Based on RFC2396
	{
	aStartPos = aEndPos = KCUrlInvalidCharPos;

	TPtrC url = aUrl;
	// search for first of ':' | '/' | '?' | '#'
	TInt stripped =0;

	TInt colonPos = aUrl.Locate(':');
	__ASSERT_ALWAYS(colonPos != 0,Panic(EInvalidUrl));		// if ':' is first character then it is invalid
	TInt hashPos = aUrl.Locate('#');
	TInt slashPos = aUrl.Locate('/');
	TInt queryPos = aUrl.Locate('?');

	colonPos = colonPos == KErrNotFound ? KMaxTInt : colonPos;
	hashPos = hashPos == KErrNotFound ? KMaxTInt : hashPos;
	slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;
	queryPos = queryPos == KErrNotFound ? KMaxTInt : queryPos;

	// if ':' is before others then there is a scheme so extract it
	if (colonPos < hashPos && colonPos < slashPos && colonPos < queryPos)
		{
		if (aComponent == EUrlScheme)
			{
			aStartPos = stripped;
			aEndPos = colonPos -1;
			return;
			}

		if (url.Length() == colonPos + 1) // reached the end of the url
			return;	
		url.Set(url.Mid(colonPos+1));
		stripped += colonPos+1;
		hashPos -= colonPos+1;
		slashPos -= colonPos+1;
		queryPos -= colonPos+1;
		}

	// if first 2 characters are '//' then a host exists, 
	if (url.Find(KUrlLoc) == 0)
		{
		TInt urlLocLength = KUrlLoc().Length();
		if (url.Length() == urlLocLength) // reached the end of the url
			return;
		// extract '//' and rescan for '/'
		url.Set(url.Mid(urlLocLength));
		stripped += urlLocLength;
		hashPos -= urlLocLength;
		queryPos -= urlLocLength;
		slashPos = url.Locate('/');
		slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;

		// host is ended by first of '#' | '?' | '/' | end of url
		TInt hostEndCharPos = slashPos;
		hostEndCharPos = hashPos < hostEndCharPos ? hashPos : hostEndCharPos;
		hostEndCharPos = queryPos < hostEndCharPos ? queryPos : hostEndCharPos;
		hostEndCharPos = url.Length() < hostEndCharPos ? url.Length() : hostEndCharPos;
	
		if (aComponent == EUrlAuthority)
			{
			aStartPos = stripped;
			aEndPos = hostEndCharPos+stripped-1;
			return;
			}
		if (aComponent == EUrlLocation ||
			aComponent == EUrlUsername ||
			aComponent == EUrlPassword)
			{
			aStartPos = stripped;
			aEndPos = hostEndCharPos+stripped-1;
			// We need part of the authority. Extract it
			PartOfAuthority(aComponent, aUrl, aStartPos, aEndPos);
			return;
			}
		//	Have we reached the end of the url
		if (url.Length() == hostEndCharPos)
			return; 
		// extract host	
		url.Set(url.Mid(hostEndCharPos));
		stripped += hostEndCharPos;
		slashPos -= hostEndCharPos;
		hashPos -= hostEndCharPos;
		queryPos -= hostEndCharPos;		
		}

	//	If first character is '/' | this is the start of a relative url | there is no authority then path exists
	//	as long as it isn't just a query or fragment
	if ((slashPos == 0 || stripped == 0 || stripped == colonPos +1 ) && hashPos != 0 && queryPos !=0)
		{ 
		TInt pathEndCharPos = queryPos;
		pathEndCharPos = hashPos < pathEndCharPos ? hashPos : pathEndCharPos;
		pathEndCharPos = url.Length() < pathEndCharPos ? url.Length() : pathEndCharPos;
		if (aComponent == EUrlPath)
			{
			aStartPos = stripped;
			aEndPos = pathEndCharPos+stripped-1;
			return;
			}
		if (url.Length() == pathEndCharPos) // reached the end of the url
			return;
		//	extractPath
		url.Set(url.Mid(pathEndCharPos));
		stripped += pathEndCharPos ;
		queryPos -= pathEndCharPos ;
		hashPos -= pathEndCharPos ;
		}

	// if first is '?' then query exists
	if (queryPos == 0) 	
		{
		// extract ?, query is ended by '#' | end of url
		if (url.Length() == 1)	// reached the end of the url
			return;
		url.Set(url.Mid(1));
		stripped += 1;
		hashPos -= 1;
		// extract query
		TInt queryEndCharPos = hashPos;
		queryEndCharPos = url.Length() < queryEndCharPos ? url.Length() : queryEndCharPos;
		if (aComponent == EUrlQuery)
			{
			aStartPos = stripped;
			aEndPos = queryEndCharPos+stripped-1;
			return;
			}
		if (url.Length() == queryEndCharPos) // reached the end of the url
			return;
		url.Set(url.Mid(queryEndCharPos));
		stripped += queryEndCharPos;
		hashPos -= queryEndCharPos;
		}

	if (hashPos == 0)
		{
		if (url.Length() == 1)	// reached the end of the url
			return;
		// extract hash
		url.Set(url.Mid(1));
		stripped += 1;
		// fragment left
		if (aComponent == EUrlFragment)
			{
			aStartPos = stripped;
			aEndPos = stripped + url.Length() -1;
			return;
			}
		}
	__ASSERT_DEBUG(	aStartPos == aEndPos && aEndPos == KCUrlInvalidCharPos, Panic(EInvalidUrl));
	}
/**
CountLinesOfBodyTextL()
Counts the lines of body text in the email aEntry

@param aEntry
A reference to an object representing the email

@param aFooterExists
Reference to a boolean variable - set to ETrue if the footer string is found in the body text

@param aFooterSize
Expected KB left on server inserted into footer string if present 

@return
Number of lines in the body text 
*/
TInt CT_MsgComparePopEmailMsgs::CountLinesOfBodyTextL(CMsvEntry& aEntry, TBool& aFooterExists, TInt& aFooterSize)
	{
	TInt lines = 0;
	TInt count =0;
	aFooterExists=EFalse;
	aFooterSize=0;
	aEntry.SetEntryL(aEntry.EntryId());
	if(aEntry.HasStoreL())
		{
		CMsvStore*	msvStore1= aEntry.ReadStoreL();
		CleanupStack::PushL(msvStore1);
		CParaFormatLayer*	paraFormatLayer1 = CParaFormatLayer::NewL();
		CleanupStack::PushL(paraFormatLayer1);
		CCharFormatLayer*	charFormatLayer1 = CCharFormatLayer::NewL(); 
		CleanupStack::PushL(charFormatLayer1);
		CRichText*	bodyText1=CRichText::NewL(paraFormatLayer1, charFormatLayer1, CEditableText::EFlatStorage, 256);
		CleanupStack::PushL(bodyText1);

		bodyText1->Reset();
		if (msvStore1->HasBodyTextL())
			{
			msvStore1->RestoreBodyTextL(*bodyText1);
			TUint16 val = CEditableText::ELineBreak;
			TUint16 val1 = CEditableText::EParagraphDelimiter;
			TUint16 val2 = KUnicodeValue;
			
			TInt n = 0;
			TInt pos = 0;
			for(;;)
				{
				TPtrC bodyText = bodyText1->Read(pos);
				n = bodyText.Find(&val, 1);
								
				// if iStore8BitData flag is set, the line is terminated by "CEditableText::EParagraphDelimiter"			
				if(msvStore1->IsPresentL(KMsvPlainBodyText8))
					{
					if ( 0 == count )
						{
						TPtrC buffer = bodyText.Mid(0,n+2);
						// eg for 8bit the body look as : This is a simple email message.\x2028\x2029\x2029
						// eg for 16bit the body look as: This is a simple email message.\x2028\x2028\x2029
						if((bodyText.Right(2).Compare(KParagraphDelimiter)==KErrNone) && \
									 buffer.Find(&val2,1) != 75)
							{
							lines++;	
							count++;
							}				
							// Increment the line if EParagraphDelimiter or 0x0046 is found sequence as eg:1. \x2028\x2029
							// 2. \x2028\x2029\x2028\x2029\x0046 3. \x2028\x2029\x2028\x2029\x2028\x2029
						else if ( (buffer.Find(&val1,1)==0 && n==-1) || (buffer.Find(&val2,1)==1) \
										|| (buffer.Find(&val1,1)>0) )
							{
							lines++;		
							}
						}
					}
				if(n < 0)
					break;
				lines++;
				pos += n+1;
								
				//This Check is needed to delete the extra line introduced by communigate Pro Server
				TInt fpos = CheckIfServerMessageExists(bodyText);
				if (fpos != KErrNotFound)
					{
					lines--;
					}
				}
			TPtrC	pBt = bodyText1->Read(0);
			aFooterExists = CheckIfFooterMessageExistsL(pBt , aFooterSize);
			}		
		CleanupStack::PopAndDestroy(4, msvStore1);  //bodyText1,charFormatLayer1,paraFormatLayer1,msvStore1.
		}
	return lines;
	}
TBool CTe_LbsIniFileReader::FindNextSection()
{
    _LIT(KSectionHeaderStart, "[");
    _LIT(KSectionHeaderEnd, "]");

    // Clear the previous section information.
    iSection.Set(KNullDesC);

    // Early check to see if we have already searched
    // to the end of the file.
    if (iSectionEnd == iPtr.Length())
    {
        return (EFalse);
    }

    // Begin searching from the end of the last section.
    TPtrC ptrSection = iPtr.Mid(iSectionEnd);

    // Search for the section header '[<text>]'.
    TInt sectionHeaderEnd(KErrNotFound);
    TInt sectionHeaderStart = ptrSection.Find(KSectionHeaderStart);
    if (sectionHeaderStart == KErrNotFound)
    {
        // No match, so no more sections in the file.
        iSectionEnd = iPtr.Length();
        return (EFalse);
    }
    else
    {
        sectionHeaderEnd = ptrSection.Find(KSectionHeaderEnd);
        if ((sectionHeaderEnd == KErrNotFound)
                || (sectionHeaderEnd < sectionHeaderStart))
        {
            // Parsing error - the section header was not closed properly
            iSectionEnd = iPtr.Length();
            return (EFalse);
        }
        else if (sectionHeaderEnd == ptrSection.Length())
        {
            // Parsing error - the section header ends at the end
            // of the file, so the section is empty!
            iSectionEnd = iPtr.Length();
            return (EFalse);
        }
    }
    iSection.Set(ptrSection.Mid(sectionHeaderEnd + 1));

    // Search for the start of the next section
    // - take this to be the end of the current section.
    TInt sectionEnd = iSection.Find(KSectionHeaderStart);
    if (sectionEnd != KErrNotFound)
    {
        iSection.Set(iSection.Left(sectionEnd));
        iSectionEnd += (sectionHeaderStart + sectionEnd + 1);
    }
    else
    {
        // No more sections after this one, so set the index to the end.
        iSectionEnd = iPtr.Length();
    }

    return (ETrue);
}
Пример #25
0
/**
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);
	}
Пример #26
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;
	}
Пример #27
0
void CScriptFile::ParseScriptSectionsL(const TDesC& aScript, TInt aInsertIndex)
	{
	iLastSection = NULL;

	CScriptSection* section = NULL;
	CScriptSectionItem* currentItem = NULL;
	TInt currentItemStart = 0;
	CScriptSection* sectionAll = NULL;
	RArray<TInt> sectionIndexArray;
	CleanupClosePushL(sectionIndexArray);
	TInt indexIncrement = 0;		
	HBufC* scriptContents = ReadFileLC(aScript);

	TLex input(*scriptContents);

	while (!input.Eos())
		{
	    input.SkipSpaceAndMark();

		input.SkipCharacters();
		if ( input.TokenLength() == 0 )    // if valid potential token
			{
			break;
			}

		TPtrC token = input.MarkedToken();

		if (token.CompareF(_L("endscript")) == 0)
			{
			break;
			}
		else if (token.FindF(KScriptSectionStart) == 0 && token.Length() > 2)
			{
			ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);

			TInt mid = 1;
			TInt len = token.Length() - 2;

			if (sectionAll)
				section = CScriptSection::NewLC(token.Mid(mid, len), *sectionAll);
			else
				section = CScriptSection::NewLC(token.Mid(mid, len));

			if (!sectionAll && section->SectionName().CompareF(_L("All")) == 0)
				sectionAll = section;
			
			// We have a Scripts section, store its index as we need to track where
			// it occured so that the scripts can be added in the same location
			// after the current file has parsed
			if (section->SectionName().CompareF(KScriptsSection) == 0)
				{
				if(aInsertIndex==KErrNotFound)
					{
					// Not an embedded script, simple store its index
					TInt currectSectionsCount = iSections->Count();
					sectionIndexArray.Append(currectSectionsCount);
					}
				else
					{
					// An embedded script, calculate the index it should be inserted at
					TInt currectSectionsCount = indexIncrement+aInsertIndex;
					sectionIndexArray.Append(currectSectionsCount);
					}
				}
			
			// Check if the section needs to be inserted at a particular location
			if(aInsertIndex==KErrNotFound)
				iSections->AppendL(section);
			else
				iSections->InsertL(aInsertIndex + indexIncrement++, section);
				
			CleanupStack::Pop(section);
			}
		else if (section)
			{
			TPtrC itemEnd(KScriptItemEnd);

			if (itemEnd.Length() < token.Length() && token.Right(itemEnd.Length()).CompareF(itemEnd) == 0)
				{
				FoundNewItemL(*scriptContents, input, currentItemStart, *section, currentItem);
				}
			}
		}

	ParseAndSetItemValueL(*scriptContents, input, currentItemStart, currentItem);
	CleanupStack::PopAndDestroy(scriptContents);
	
	// We have been tracking where the script sections have been inserted so we
	// want to load the sections from the embedded script file and insert them
	// at the same point. This must be done in reverse order so that the index
	// values of script sections before the current one is maintained.
	TInt scriptSectionsCount = sectionIndexArray.Count();
	for( TInt ii=scriptSectionsCount-1; ii>=0; --ii)
		{
		TInt indexOfScriptSection = sectionIndexArray[ii];
		ParseEmbeddedScriptsL(*(iSections->At(indexOfScriptSection)), indexOfScriptSection);
		}
	CleanupStack::PopAndDestroy(&sectionIndexArray);
	}
Пример #28
0
TBool CIniFile::FindVar(const TDesC &aSection,
						const TDesC &aVarName,
						TPtrC &aResult)
//
// Find a variable's value given a section name and a var name
//
	{
	__ASSERT_DEBUG(aSection.Length()<=(TInt)KTokenSize,Panic(ESectionNameTooBig));
	__ASSERT_DEBUG(aVarName.Length()<=(TInt)KTokenSize,Panic(EVarNameTooBig));

	TPtr sectionToken = iToken->Des();
	_LIT(KSectionTokenString,"[%S]");
	sectionToken.Format(KSectionTokenString,&aSection);
	TInt sectionStart = iPtr.Find(sectionToken);
	TInt ret = ETrue;
	if (sectionStart == KErrNotFound)
		{
		ret = EFalse;
		}
	else
		{		
		TPtrC section = iPtr.Mid(sectionStart);
		TInt endBracket = section.Find(TPtrC(_S("]")));
		if (endBracket == KErrNotFound)
			{
			ret = EFalse;
			}
		else
			{
			sectionStart += endBracket + 1;
			section.Set(iPtr.Mid(sectionStart));
			
			TInt sectionEnd = section.Find(TPtrC(_S("[")));
			if (sectionEnd == KErrNotFound)
				{
				sectionEnd = iPtr.Length() - sectionStart;
				}
			else
				{
				sectionEnd--;
				}
			section.Set(iPtr.Mid(sectionStart,sectionEnd));
			TPtr varToken = iToken->Des();
			_LIT(KVarTokenString,"%S=");
			varToken.Format(KVarTokenString,&aVarName);
			TInt pos = section.Find(varToken);
			if (pos == KErrNotFound)
				{
				ret = EFalse;
				}
			else
				{
				// 'lex' points at the start of the data
				TPtrC lex(section.Mid(pos));
				TInt startpos = lex.Locate(TChar('='));
				startpos++; // startpos points immediately after the =.
				while ( TChar(lex[startpos]).IsSpace() )
					{
					startpos++; // skip to start of data
					}
				TInt endpos = lex.Locate(TChar('\n')); // assumes \n is after =.
				if ( endpos == KErrNotFound ) // may not be \n on last line
					{
					endpos = section.Length()-1;
					}
				aResult.Set(lex.Mid(startpos).Ptr(),endpos-startpos-1);
				}
			}
		}

	return ret;
	}
Пример #29
0
TVerdict CForceRemove::doTestStepL()
	{

#ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
	// Wait up to 30 seconds to ensure both SWIS and the sisregistry server
	// have shut down
	_LIT(KSisRegistryServerName, "!SisRegistryServer");
	_LIT(KInstallServerName, "!InstallServer");
	TInt delaytime = 30; 

	while (delaytime-- > 0)
		{
		TFullName serverName;
		TFindServer find(KInstallServerName);
		if (KErrNotFound == find.Next(serverName))
			{
			find.Find(KSisRegistryServerName);
			if (KErrNotFound == find.Next(serverName))
				{
				break;
				}
			}
		User::After(1000000); // wait a second until the next test
		}
#endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
	
	TPtrC name;
	RTestUtilSessionSwi testutil;
	User::LeaveIfError(testutil.Connect());
	CleanupClosePushL(testutil);
	
	// If file deletion fails we'll try moving the file to a temp directory
	// for another process to clean up later.
	
	TTime currentTime;
	currentTime.UniversalTime();
	
	_LIT(KTempPathFormat, "\\temp\\%Lu");
	TDriveUnit sysDrive (RFs::GetSystemDrive());
	TBuf<128> tempPathFormat(sysDrive.Name());
	tempPathFormat.Append(KTempPathFormat);
	
	TFileName targetPath;
	targetPath.Format(tempPathFormat, currentTime.Int64());
	
	_LIT(KNumFiles, "numfiles");

#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
	RArray<TUint> removeUids;
	CleanupClosePushL(removeUids);
#endif

	TInt num(0);
	GetIntFromConfig(ConfigSection(), KNumFiles, num);

	// Get the file names and use testutil to remove them
	for (TInt i = 0; i < num; ++i)
		{
		_LIT(KFile, "file");
		TBuf<32> key(KFile);
		key.AppendNum(i);
		
		if (!GetStringFromConfig(ConfigSection(), key, name))
			continue;
			
		INFO_PRINTF2(_L("ForceRemove - trying to delete file %S"), &name);

		TInt err = testutil.Delete(name);
		if (err != KErrNone && err != KErrNotFound && err != KErrPathNotFound)
			{
			INFO_PRINTF3(_L("RTestUtilSessionSwi::Delete(%S) returned %d, attempting move instead."), &name, err);
			TFileName source(name);
			TParsePtr parse(source);
			TFileName dest(targetPath);
			dest.Append(parse.Path());
			if (parse.DrivePresent())
				{
				dest[0] = source[0];
				}
			testutil.MkDirAll(dest);
			dest.Append(parse.NameAndExt());

			err = testutil.Move(source, dest);
			
			if (err != KErrNone)
				{
				INFO_PRINTF4(_L("Attempt to move from %S to %S returned %d"),
							&source, &dest, err);
				}
			}
#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
		_LIT(KRegistryPath, "\\sys\\install\\sisregistry\\");
		if (name.FindF(KRegistryPath) == KErrNotFound)
			continue;

		// Extract the uid and add it to our list
		TInt slashPos = name.LocateReverse('\\');
		TPtrC ptrUid = name.Mid(slashPos + 1);
		if (ptrUid.Length() != 8)
			continue;

		TUint uid = 0; 
		TLex lex(ptrUid);
		if (lex.Val(uid, EHex) == KErrNone)
			{
			removeUids.InsertInOrder(uid);	// Will not allow duplicates
			}
#endif
		}

#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
	// Use the sisregistry folder uid to remove the package entries from SCR
	// Note that we remove packages present in ROM too due to two reasons:
	// This is exactly what ForceRemove used to do (delete entire registry folder containing ALL reg files)
	// After deleting an entry SWIRegistry re-registers ROM apps (missing ones)
	TInt count = removeUids.Count();

	RSisRegistryAccessSession regWrite;
	TInt err = regWrite.Connect();
	User::LeaveIfError(err);
	CleanupClosePushL(regWrite);

	Swi::RSisRegistrySession regRead;
	User::LeaveIfError(regRead.Connect());
	CleanupClosePushL(regRead);
	for (TInt i = 0; i < count; ++i)
		{ 
		TUid uid = TUid::Uid(removeUids[i]);
		Swi::RSisRegistryEntry entry;
		CleanupClosePushL(entry);
		if (entry.Open(regRead, uid) == KErrNone)
			{
			// Get its augmentations
			RPointerArray<Swi::CSisRegistryPackage> augmentations;
			CleanupResetAndDestroy<RPointerArray<Swi::CSisRegistryPackage> >::PushL(augmentations);
			
			entry.AugmentationsL(augmentations);
			TInt augCount = augmentations.Count();
			for (TInt j = 0; j < augCount; ++j)
				{
				// Remove it
				TInt dummyTime;
				regWrite.DeleteEntryL(*augmentations[j], dummyTime);
				}
			// Finally remove the base package entry
			Swi::CSisRegistryPackage* package = entry.PackageL();
			CleanupStack::PushL(package);
			TInt dummyTime;
			regWrite.DeleteEntryL(*package,dummyTime);
			CleanupStack::PopAndDestroy(2, &augmentations); // package
			}
		CleanupStack::PopAndDestroy(&entry);
		}
	CleanupStack::PopAndDestroy(3, &removeUids);	// regWrite, regRead
#endif
	
	CleanupStack::PopAndDestroy(&testutil);
	
	return EPass;
	}