Exemple #1
0
TBool TfrLex::Eat( TLex& aLex, const TChar aChar )
{
TLexMark unget;
if ( aChar.IsSpace() )
	{
	// A space character requires its own logic = go over
	// the other space characters - x gets the next char.
	TChar x;
	aLex.Mark(unget);
	while ( x = aLex.Get(), x.IsSpace() && x != aChar )
		{};
	if ( x == aChar ) 
		return ETrue;
	}
else
	{
	// For other, non-space, characters: skip spaces and
	// get the next character x.
	aLex.SkipSpace();
	aLex.Mark(unget);
	if ( aLex.Get() == aChar ) 
	return ETrue;
	}

// The character wasn't there, unget to the start point.
aLex.UnGetToMark(unget);
return EFalse;
}
void GetEnumValuesL(TLex& aLex, RBuf& aValues, RBuf& aDescriptions)
	{
	aValues.CreateL(0x100);
	aDescriptions.CreateL(0x100);

	while (!aLex.Eos())
		{
		TLexMark mark;
		aLex.Mark(mark);
		TPtrC command(NextCommand(aLex));
		if (command == KCmndEnumValue)
			{
			TPtrC value(NextWord(aLex));
			TPtrC description(TextToNextCommand(aLex));
			if (value.Length() == 0)
				{
				User::Leave(KErrArgument);
				}
			AppendL(aValues, value, EFalse);
			if (description.Length() > 0)
				{
				AppendL(aDescriptions, description, ETrue);
				}
			}
		else
			{
			aLex.UnGetToMark(mark);
			break;
			}
		}
	}
Exemple #3
0
TBool TfrLex::EatF( TLex& aLex, const TDesC& aTerm )
{
aLex.SkipSpace();
TLexMark unget;
aLex.Mark(unget);
if ( ValF(aLex,aTerm) == KErrNone ) return ETrue;
aLex.UnGetToMark(unget);
return EFalse;
} 
// ----------------------------------------------------
// DoOrReverse()
// Calls aFunc. If it fails, the lexer is returned to 
// the state before calling DoOrReverse().
// ----------------------------------------------------
//
LOCAL_C TBool DoOrReverse( TParseFunc aFunc, TLex& aLex )
    {
    TLexMark mark;
    aLex.Mark( mark );
    if( (*aFunc)(aLex) )
        {
        return ETrue;
        }
    else
        {
        aLex.UnGetToMark( mark );
        return EFalse;
        }
    }
Exemple #5
0
TInt  TfrLex::ValF( TLex& aLex, const TDesC& aTerm )
{
TLex term( aTerm );
TLexMark mark;

aLex.Mark( mark );
while ( !term.Eos() )
	{
	if ( aLex.Eos() || User::Fold(term.Get()) != User::Fold(aLex.Get()) )
		{
		aLex.UnGetToMark( mark );
		return KErrNotFound;
		}
	}
return KErrNone;
}
Exemple #6
0
TPtrC TfrLex::GetL( TLex& aLex, const TChar  aChar )
{
// Skip spaces and mark the token's start point.
aLex.SkipSpace();
TLexMark mark;

aLex.Mark(mark);    

if (aLex.Peek() == '"' )
	{
	// Skip the " and do find next " followed by eos, space or aChar.
	aLex.Inc();
	TChar x;
	while ( x = aLex.Get(), !x.Eos() )
		{
		if ( x == '"' )
			{
			// Found a " character - but is it the end of the token?
			x = aLex.Peek(); // peek the next character
			if ( x.Eos() || x.IsSpace() || x == aChar )
				// End of token: return token.
				return aLex.MarkedToken(mark);
			}
		}
	// Unget and L E A V E because did not find the end " of token.
	aLex.UnGetToMark(mark);
	User::Leave(KErrArgument);
	return aLex.MarkedToken(mark); // never reached (l e a v e).
	}
else
	{
	// Is not a "*" token: find eos or the next space or the aChar
	// and return the token.
	TChar x;
	while ( x = aLex.Peek(), !x.Eos() && !x.IsSpace() && x != aChar )
		aLex.Inc();

	return aLex.MarkedToken(mark);
	}
}
Exemple #7
0
//
//  ParseMessageL()
//
//  Simple Notification:
//      Looks for number of messages and "From:" field
//      writes numMsg into the parsed field array, sets
//      entry.iDetails to the "From:" 
//  Complicated Notification:
//      does the above and writes everything else into
//      the array....
//
void CEmailNotificationParser::ParseMessageL()
    {
    TBool isSimpleNotification = EFalse; 
    TLex  tokenLex;
    TPtrC fieldName;
    TPtrC fieldValue;

	// reset parsedfield array
	for(TInt i = iParsedFieldArray->Count();--i>=0;)
		(*iParsedFieldArray)[i]->SetFieldValueL(_L(""));

    // Set extraction mark at first character
    iSms.SkipSpaceAndMark();
	if(iSms.Peek() == KCharSlash)
		{
		// Check first line is <header>
		iSms.SkipCharacters();

		if (iSms.MarkedToken() != KEmailHeader)
			{
			User::Leave(KBspInvalidMessage);
			}
		// Get <new-amount> from second line and check for terminating linefeed
		iSms.SkipSpaceAndMark();
		}

    // Val() seeks forward from next char position, looking for valid
    // digits and incrementing next char as it goes.
    if (!(iSms.Val(iMessageCount) == KErrNone  &&  iMessageCount >= 0))     // If marked token is not a valid positive integer
        {
        iMessageCount = 0;
        User::Leave(KBspInvalidMessage);
        }
    else
        {
        fieldValue.Set(iSms.MarkedToken());                            //  The message count..
        AddParsedFieldL(KHeaderNumberMessages, fieldValue, ETrue);
        }

    // Next character may now be at newline or space after integer.
    // If at space, advance to newline.
    while (iSms.Peek() != KCharLineFeed && !iSms.Eos())
        iSms.Inc();

    iSms.SkipSpaceAndMark();

    // Now parse the rest of the fields, if any.
    while (!iSms.Eos())
        {
        while (iSms.Peek() != KCharLineFeed  &&  !iSms.Eos())
            iSms.Inc();     //  Skip to next delimiter

        if (iSms.Eos())
            break;          //  we've finished break out of the function

        if (iSms.TokenLength() == 0)
            User::Leave(KBspSmartMessageInvalidToken);

        //  Parsing....
        tokenLex.Assign(iSms.MarkedToken());        // Assign token to a new TLex
        while (tokenLex.Peek() != KCharColon  &&  !tokenLex.Eos())
            tokenLex.Inc();     //  Advance to a ':'

        if (tokenLex.Eos()  ||  tokenLex.TokenLength() == 0)
            User::Leave(KBspSmartMessageInvalidToken);


        fieldName.Set(tokenLex.MarkedToken());      // Store (pointer to) field name
        tokenLex.Inc();

		//fix for DEF017686
		LeaveIfEmptyFieldsL(fieldName,tokenLex);
		
        
        tokenLex.SkipSpaceAndMark();                // Step past optional spaces

		//fix for DEF017686
        LeaveIfEmptyFieldsL(fieldName,tokenLex);
	
		// if it's the server id field try to extract the id value
		// and match to an existing email service
		if(fieldName.CompareF(KHeaderServerId)==KErrNone)
			{
			TInt valErr = tokenLex.Val(iServerId);
			if(valErr != KErrNone)
				iServerId = 0;
			else
				GetEmailServicesL();

			tokenLex.UnGetToMark();
			}	
		fieldValue.Set(tokenLex.Remainder());       // Store (pointer to) field value

        if(!isSimpleNotification)
            {
            AddParsedFieldL(fieldName, fieldValue, EFalse);
            }		

        // Successfully parsed a token. Move iSms's next character past the
        // (linefeed) delimiter, set the extraction mark and reiterate to
        // look for next token.
        iSms.SkipSpaceAndMark();
        }
    }
void CCommandInfoFile::ReadDetailsL(TLex& aLex, RFs& aFs, const TDesC& aFileName)
	{
	SkipToNextCommand(aLex); // Ignore everything before the first '==' command.

	while (!aLex.Eos())
		{
		TLexMark mark;
		aLex.Mark(mark);
		TPtrC command(NextCommand(aLex));
		if (command == KNullDesC)
			{
			// Do nothing - we're at the end of the string.
			}
		else if (command == KCmndName)
			{
			aLex.SkipSpaceAndMark();
			aLex.SkipCharacters();
			iName.Set(aLex.MarkedToken());
			}
		else if (command == KCmndShortDescription)
			{
			iShortDescription.Set(TextToNextCommand(aLex));
			}
		else if (command == KCmndLongDescription)
			{
			iLongDescription.Set(TextToNextCommand(aLex));
			}
		else if (command == KCmndSeeAlso)
			{
			iSeeAlso.Set(TextToNextCommand(aLex));
			}
		else if (command == KCmndCopyright)
			{
			iCopyright.Set(TextToNextCommand(aLex));
			}
		else if (command == KCmndSmokeTest)
			{
			// Hmm no easy way to get the line number we're currently on
			iSmokeTestLineNumber = 1;
			TLex lex(aLex);
			lex.Inc(-aLex.Offset()); // Only way to put a TLex back to the beginning!
			TPtrC preceding = lex.Remainder().Left(aLex.Offset());
			const TUint16* ptr = preceding.Ptr();
			const TUint16* end = ptr + preceding.Length();
			while (ptr != end)
				{
				if (*ptr++ == '\n') iSmokeTestLineNumber++;
				}
			// At this point iSmokeTestLineNumber points to the "==smoketest" line - add 2 to skip this line and the blank line below it
			iSmokeTestLineNumber += 2;
			iSmokeTest.Set(TextToNextCommand(aLex));
			}
		else if (command == KCmndArgument)
			{
			ReadArgumentL(aLex, aFileName);
			}
		else if (command == KCmndOption)
			{
			ReadOptionL(aLex, aFileName);
			}
		else if (command == KCmndInclude)
			{
			if (iParent == NULL)
				{
				iProcessInclude = EFalse;
				TLex lineLex(LineRemainder(aLex));
				TPtrC fileName(NextWord(lineLex));
				TFileName2* fullFileName = new(ELeave) TFileName2(aFileName);
				CleanupStack::PushL(fullFileName);
				fullFileName->SetNameAndExtL(fileName);
				ReadFileL(aFs, *fullFileName);
				CleanupStack::PopAndDestroy(fullFileName);
				break;
				}
			else
				{
				// We're a sub-command. Let control return to the root to handle the include.
				aLex.UnGetToMark(mark);
				iParent->ProcessInclude(*this);
				break;
				}
			}
		else if (command == KCmndSubCommand)
			{
			if (iParent == NULL)
				{
				TLex lineLex(LineRemainder(aLex));
				AddSubCommandL(lineLex, aLex, aFs, aFileName);
				}
			else
				{
				// We're a sub-command. Let control return to the root to handle the next sub-command.
				aLex.UnGetToMark(mark);
				iParent->ProcessNewChild();
				break;
				}
			}
		else
			{
			StaticLeaveIfErr(KErrArgument, _L("Unknown command \"%S\" in \"%S\""), &command, &aFileName);
			}
		}
	}
/**
Search algorithm for searching phone numbers

@param aText Text that will be parsed
@return ETrue if any Phone Number items were found else returns EFalse
@leave KErrNone, if successful; otherwise one of the other system-wide error codes.
@panic ETulPanicDescriptorLength in debug build if item's position 
and/or length is out of the document's range.
*/
TBool CTulAddressStringTokenizer::SearchPhoneNumberL( const TDesC& aText )
    {
    TLexMark startMark; // Points to the start of the found phone number
    TLexMark endMark; // Points to the end of the found phone number
    TLexMark mark;
    const TInt end = aText.Length();

    TLex number = aText;

    while ( !(number.Eos()) )
        {
        TInt numberCount = 0; // How many real numbers (1234567890)
        TInt bracketsOpen = 0; // How many brackets are currently open
        TInt brackets = 0; // How many brackets overall

        TChar charac = number.Peek();

        while( (!(IsValidPhoneNumberChar( charac ) || charac == '+'
               || charac == '(' ) || charac == '-' || charac == '.' || charac == '/') 
			   && !(number.Eos()) && number.Offset() < end )
            {
            number.Inc();
            charac = number.Peek();
            }

        if ( number.Offset() >= end )
            break;
        
        if ( number.Peek() == '#' )
			{
			number.Inc();
			if (number.Peek() == '.' )
				continue;

			number.UnGet();
			}

        if ( number.Peek() == '+' )
            { // '+' has to be followed by a number (not # or * ...)
            number.Inc();
            if ( !(number.Peek().IsDigit()) )
                continue;

            number.UnGet();
            }

        if ( number.Peek() == '(' )
            { // '(' has to be followed by valid phone number 
              // character (whitespaces are allowed before) or '+' is a next character
            number.Inc();
            if ( !(number.Peek() == '+') )
                {
                number.Mark(mark);
                number.SkipSpace();
                charac = number.Peek();
                if ( !( IsValidPhoneNumberChar(charac) || charac == '+' 
                    || charac == '(' ) || charac == '-' || charac == '.' || charac == '/')
                    {
                    number.Inc();
                    continue;
                    }
                else
                    {
                    number.UnGetToMark(mark);
                    number.UnGet();
                    number.Mark(startMark);
                    }
                } 
            else
                {
                number.UnGet();
                number.Mark(startMark);
                number.Inc();
                }

            bracketsOpen++;
            brackets++;
            }
        else
            number.Mark(startMark);

        if ( number.Peek().IsDigit() )	// If the character was a number
            numberCount++;
        else if ( bracketsOpen > 0 ) 
            { 
            number.Inc();
            TChar next  = number.Peek();
            TInt bracketsOpen2 = bracketsOpen;
            while( (IsValidPhoneNumberChar( next ) || next.IsSpace()
                || next == '(' || next == ')' || next == 'p' || next == '+'
                || next == 'w' ) && !(number.Eos()) && number.Offset() < end)
                {
                if ( next == '(' )
                    bracketsOpen2++;
                else if ( next == ')' )
                    bracketsOpen2--;
                
                if ( bracketsOpen2 == 0 )
                    break;

                number.Inc();
                next = number.Peek();
                }

            number.UnGetToMark(startMark);
            if ( bracketsOpen2 != 0 )
                {
                number.Inc();
                continue;
                }
            }

        number.Inc();
        while ( number.Peek() == '(' && !(number.Eos()) && bracketsOpen > 0 )
            {
            number.Inc();
            bracketsOpen++;
            }

        if ( number.Peek() == '+' && bracketsOpen > 0 )
            number.Inc();

        // a Valid first character has been found. Let's go forward as long as valid characters are found.
        charac = number.Peek();

        while( (IsValidPhoneNumberChar( charac ) || charac.IsSpace()
            || charac == '(' || charac == ')' || charac == 'p'
            || charac == 'w' ) && !(number.Eos()) && number.Offset() < end
            && charac != KCharLinefeed && charac != KCharFormfeed 
            && charac != KCharCarriageReturn
            && charac != KCharLineSeparator
            && charac != KCharParagraphSeparator )
            {
            if ( number.Peek() == '(' )
                { // '(' can't be the last character in phone number
                number.Mark(mark);
                number.Inc();
                
                TChar spaceJump = number.Peek();
                while ( !number.Eos() && spaceJump.IsSpace() && spaceJump != KCharLinefeed 
                        && spaceJump != KCharFormfeed && spaceJump != KCharCarriageReturn 
                        && charac != KCharLineSeparator && spaceJump != KCharParagraphSeparator)
                    {
                    number.Inc();
                    spaceJump = number.Peek();
                    }
                
                if ( !(IsValidPhoneNumberChar(number.Peek())) && number.Peek() != ')'
                     && number.Peek() != '(' )
                    {
                    number.UnGetToMark(mark);
                    break;
                    }

                TChar next  = number.Peek();
                TInt bracketsOpen2 = bracketsOpen + 1;
                while( (IsValidPhoneNumberChar( next ) || next.IsSpace()
                    || next == '(' || next == ')' || next == 'p'
                    || next == 'w' ) && !(number.Eos()) && number.Offset() < end)
                    {
                    if ( next == '(' )
                        bracketsOpen2++;
                    else if ( next == ')' )
                        bracketsOpen2--;

                    if ( bracketsOpen2 == 0 )
                        break;

                    number.Inc();
                    next = number.Peek();
                    }

                number.UnGetToMark(mark);

                if ( bracketsOpen2 != 0 )
                    break;

                bracketsOpen++;
                brackets++;
                }
            else if ( number.Peek() == ')' )
                {
                if ( bracketsOpen <= 0 )	// there has to be equal number of brackets
                    break;

                bracketsOpen--;
				number.Mark(mark);
                number.Inc();
				if ( number.Peek() == '.' )	// '.' is not allowed after ')'
                    break;

                number.UnGetToMark(mark);
                }
            else if ( number.Peek() == '-' || number.Peek() == 'w' 
                        || number.Peek() == 'p' || number.Peek() == '.' || number.Peek() == '/')
                { // Hyphen mark and 'p' & 'w' chars must be followed by a number
				TChar last = number.Peek();
                number.Mark(mark);
                number.Inc();
                
                TChar spaceJump = number.Peek();
                while ( !number.Eos() && spaceJump.IsSpace() && spaceJump != KCharLinefeed 
                        && spaceJump != KCharFormfeed && spaceJump != KCharCarriageReturn 
                        && charac != KCharLineSeparator && spaceJump != KCharParagraphSeparator )
                    {
                    number.Inc();
                    spaceJump = number.Peek();
                    }
                    
                if ( !(number.Peek().IsDigit()) )
                    {
					if (last == '.' && number.Peek() == ')' && bracketsOpen > 0 )
						continue;
					else
						{
						number.UnGetToMark(mark);
						break;
						}
                    }

                number.UnGetToMark(mark);
                }
            else if ( number.Peek().IsDigit() )
                numberCount++;

            number.Inc();
            charac = number.Peek();
            }

        // Get rid of whitespaces from the end
        number.UnGet();
        while( number.Peek().IsSpace() && !(number.Eos()))
            number.UnGet();

        number.Inc();
        // ------------------------------------
        number.Mark(endMark);

        // If they exist, remove brackets from the beginning and the end
        number.Mark(mark); // Let's mark where to continue the search
        TBool endBrackets = ETrue;
        do
            {
            number.UnGet();

            if ( number.Peek() == ')' )
                {
                number.UnGetToMark(startMark);
                if ( number.Peek() == '(' )
                    {
                    // If there's more than one pair of brackets -> don't strip them.
                    if ( brackets > 1 )
                        break;

                    number.Inc();
                    number.Mark(startMark);
                    number.UnGetToMark(endMark);
                    number.UnGet();
                    number.Mark(endMark);
                    // Get rid of whitespaces and periods from the end and from the beginning
					number.UnGet();
                    while ( (number.Peek().IsSpace() || number.Peek() == '.') 
                            && number.Offset() > number.MarkedOffset(startMark) )     
                        { // from the end
                        number.UnGet();
                        }
					number.Inc();
                    number.Mark(endMark);
                    number.UnGetToMark(startMark);
                    while ( (number.Peek().IsSpace() || number.Peek() == '.') 
                            && number.Offset() < number.MarkedOffset(endMark) )     
                        { // from the beginning
                        number.Inc();
                        }
                    number.Mark(startMark);
                    number.UnGetToMark(endMark);
                    // ----
                    }
                else
                    endBrackets = EFalse;
                }
            else
                endBrackets = EFalse;
            }
        while ( endBrackets );

        number.UnGetToMark(mark);
        // ----------------        

        if ( numberCount <= KFindItemMaxNumbers && numberCount >= iMinNumbers )
            {
			TPtrC tokenPtr = number.MarkedToken(startMark);
			TInt tokensEnd = tokenPtr.Length();
			TInt numbers = 0;
			TInt partialNumber = 0;
			TBool wasValidPhoneNumber = ETrue;
			TInt i = 0;

			for ( ; i < tokensEnd; i++ )
				{
				if ( tokenPtr[i] == '.' )
					partialNumber = 0;
				else if ( ((TChar)tokenPtr[i]).IsDigit() )
					{
					numbers++;
					partialNumber++;
					}

				if ( ( partialNumber == 1 || partialNumber == 2 ) && i + 1 < tokensEnd )
					{
					if ( tokenPtr[i + 1] == '.' )
						wasValidPhoneNumber = EFalse;
					}
				}
				
			if (!wasValidPhoneNumber && numbers > 6)
				wasValidPhoneNumber = ETrue;
			
			if (wasValidPhoneNumber)
				{
	            __ASSERT_DEBUG( number.MarkedOffset(startMark) + number.MarkedOffset(endMark) 
	                            - number.MarkedOffset(startMark) <= aText.Length(), 
	                            Panic(ETulPanicDescriptorLength) );

	            AddItemL( number.MarkedOffset(startMark), 
	                      number.MarkedOffset(endMark) - number.MarkedOffset(startMark), 
	                      EFindItemSearchPhoneNumberBin );
				}
			}

        }

    return (iFoundItems->Count() > 0);
    }
/**
Search algorithm for searching e-mail addresses

@param aText Text that will be parsed
@return ETrue if any EMail items were found else returns EFalse
@leave KErrNone, if successful; otherwise one of the other system-wide error codes.
@panic ETulPanicDescriptorLength in debug build if item's position 
and/or length is out of the document's range.
*/
TBool CTulAddressStringTokenizer::SearchMailAddressL( const TDesC& aText )
    {
    TInt searchStart = 0;
    TInt searchResult = 0;
    const TInt end = aText.Length(); // end of document

    do
        {
        TPtrC segment = aText.Right( end - searchStart );
        searchResult = segment.LocateF('@');

        if (searchResult != KErrNotFound)
            { // @ found
            // There should be valid characters (not a period) before and after the @ character
            if ( searchResult == 0 // first char
                || (searchResult >= segment.Length() - 1) // last char 
                || !(IsValidEmailChar(segment[searchResult - 1])) 
                || !(IsValidEmailHostChar(segment[searchResult + 1]))
                || segment[searchResult - 1] == '.' 
                || segment[searchResult + 1] == '.'
               )
                {
                searchStart += searchResult + 1;
                continue;
                }

            TBool wasPeriod = EFalse; // To prevent sequential periods
            // Get TLex from the pointer to get a better API for parsing
            TLexMark startPos;
            TLexMark endPos;
            TLex token = segment;
            
            // Go to searchResult and un-get until the beginning of e-mail address is reached
            token.Inc( searchResult );
            token.Mark();
            do
                {
                token.UnGet();
                if ( token.Peek() == '.' )
                    { // If it was a period
                    if (wasPeriod)	// and if the former was also -> break
                        break;
                    else	// else mark that this one was a period
                        wasPeriod = ETrue;
                    }
                else
                    wasPeriod = EFalse;
                }
            while (token.Offset() > 0 && IsValidEmailChar(token.Peek()));
            
            if (token.Offset() != 0 || !IsValidEmailChar(token.Peek()))
                token.Inc();

            // Get rid of periods from the start of address
            // Does it have to start with a number or char(abc...).
            // If it does, the loop should check that it gets rid of all special chars also.
            while (token.Peek() == '.')
                token.Inc();

            token.Mark( startPos ); // Mark the beginning of address
            token.UnGetToMark();
            wasPeriod = EFalse;
            
            do	// Go forward until a nonvalid character
                {
                token.Inc();
                if ( token.Peek() == '.' )
                    { // If it was a period
                    if ( wasPeriod )	// and if the former was also -> break
                        break;
                    else	// else mark that this one was a period
                        wasPeriod = ETrue;
                    }
                else
                    wasPeriod = EFalse;
                }
            while ( !token.Eos() && IsValidEmailHostChar( token.Peek() ) );
            
            // If address ends with a period take it away
            token.UnGet();
            if (token.Peek() != '.')
                token.Inc();

            token.Mark( endPos ); // Mark the beginning of address

            // Append the found string to the array
            __ASSERT_DEBUG( searchStart + token.MarkedOffset( startPos ) 
                            + token.MarkedOffset( endPos ) 
                            - token.MarkedOffset( startPos ) <= aText.Length(), 
                            Panic(ETulPanicDescriptorLength) );
            AddItemL( searchStart + token.MarkedOffset( startPos ), 
                      token.MarkedOffset( endPos ) - token.MarkedOffset( startPos ), 
                      EFindItemSearchMailAddressBin);
            searchStart += token.MarkedOffset( endPos ) + 1;
            }
        }
    while ( searchResult != KErrNotFound && searchStart < end );

    return (iFoundItems->Count() > 0);
    }