Esempio n. 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;
}
// ---------------------------------------------------------------------------------
// CUpnpTmFilteredAppList::RemoveWhiteSpace
// Method is used to remove leading and trailing whitespaces from the descriptor's data
// @param aData Descriptor's data from which whitespaces have to be removed
// @return Returns the descriptor having no white spaces
// ---------------------------------------------------------------------------------
//
const TDesC8& CUpnpTmFilteredAppList::RemoveWhiteSpace( TPtrC8& aData )
    {
    OstTraceFunctionEntry0( CUPNPTMFILTEREDAPPLIST_REMOVEWHITESPACE_ENTRY );
    // Removes the leading white spaces
    TInt length = aData.Length();
    TInt i = 0;
    TBool done = EFalse;
    while( !done && i < length )
        {
        TChar current = aData[i];
        done  = !current.IsSpace();
        if( !done )
        ++i;
        }
    aData.Set(aData.Mid(i)); /* aData now does not have any white space character 
                                ahead of its actual data */
    
    // Removes the trailing white spaces
    length = aData.Length();
    i = 0;
    done = EFalse;
    while( !done && i < length )
        {
        TChar current = aData[(length-1) - i];
        done  = !current.IsSpace();
        if( !done )
        ++i;
        }
    aData.Set(aData.Left(aData.Length() - i)); /* aData now does not have any white space character
                                                following the actual data */
    OstTraceFunctionExit0( CUPNPTMFILTEREDAPPLIST_REMOVEWHITESPACE_EXIT );
    return aData;
    }
TBool CTestConfig::IsAtStartOfNewLine(const TDesC8& aSource, const TLex8& aLex, TBool aIgnoreSpaces) const
	{
	TInt offset(aLex.MarkedOffset());
	__ASSERT_ALWAYS(offset != 0, User::Invariant());

	TChar ch = NULL;

	if (aIgnoreSpaces)
		{
		while (offset--)
			{
			ch = aSource[offset];
			if (ch == KScriptLFChar || ch == KScriptCRChar || !ch.IsSpace())
				break;
			}
		}
	else
		ch = aSource[offset-1];

	TBool ret(EFalse);

	if (offset <= 0)
		ret = ETrue;
	else
		ret = (ch == KScriptLFChar || ch == KScriptCRChar);

	return ret;
	}
void CATBase::ParseBufferLC()
//
//  Parses buffer
//
/**
 * This function is currently not used by the Etel regression test harness.
 */	{
	LOGTEXT(_S8("CATBase Parse the Buffer List"));
	iBuffer.Set(iIo->GetRxBufferLC(iBufferMarker));
	TInt pos=iBuffer.FindF(KOKString);
	if(pos==KErrNotFound)
		{
		LOGTEXT(_S8("CATBase Error - Cannot find OK'"));
		User::Leave(pos);
		}
	//	Place everything before the OK into buffer
	iBuffer.Set(iBuffer.Left(pos));

	TLex8 yyLex(iBuffer);
	TChar peek;
	//	Look for '=' sign and move seeker cursor to the right of it if it exists
	pos=iBuffer.Find(_L8("="));
	if (pos!=KErrNotFound)
		{
		yyLex.Inc(pos+1);
		}
	//	Move cursor past any spaces or open brackets
	yyLex.SkipSpace();
	peek=yyLex.Peek();
	if ((TUint)peek=='(' || (TUint)peek=='[' || (TUint)peek=='{')
		yyLex.Inc();

	yyLex.SkipSpace();
	peek = yyLex.Peek();
	do
		{
		// Search for the next character that is not a comma, and mark it. Keep looking at 
		// subsequent characters until it is a space,comma,closing bracket or end of string.
		// Store the string (between marked character and current character) as an item in
		// an array of CATParamListEntry object pointers.
		if (peek!=',')
			{
			yyLex.Mark();
			do
				{
				yyLex.Inc();
				peek=yyLex.Peek();
				}
			while (peek!=',' && !peek.IsSpace() && peek!=')'&& peek!=']'&& peek!='}' && !yyLex.Eos());
			CATParamListEntry* aParamListEntry = new (ELeave) CATParamListEntry(yyLex.MarkedToken());
			iRxResults.AddLast(*aParamListEntry);
			}
		// Move cursor to the next non-space character, and end the loop if it is a closing
		// bracket or the end of the buffer.
		yyLex.Inc();
		yyLex.SkipSpace();
		peek = yyLex.Peek();
		}
	while (!yyLex.Eos() && peek!=')'&& peek!=']'&& peek!='}');
	}
Esempio n. 5
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);
	}
}
Esempio n. 6
0
TInt CIniData::GetSetting(const TDesC &aValue, TPtrC &aSetting)
/**
Retrieves the value for a particular setting within a block

@param aValue The setting to be retrieved 
@param aSetting On return it contains the value for the setting
@return KErrNone if successful or KErrArgument for fields simply left blank. If the global BlockState is unknown returns KErrNotReady.
*/
	{
	TInt valid(KErrNotReady);	

	if (BlockState != E_UNKNOWN)
	    {
		// first check for CONDITION field
		// if we are NOT looking for this field, we need to trim off any condition
		// field from the block because there may be a setting within it we 
		// want to ignore during our search for this field
        TPtrC pBlock(block);
		TInt tempEnd = blockEnd;
		TPtrC Condition = CONDITION;
		if (aValue.Compare(Condition) != 0)
		    {
			TPtr varCondToken = iToken->Des();
			_LIT(varCondTokenString, "%S=");
			varCondToken.Format(varCondTokenString, &Condition);
			TInt CondPos = pBlock.FindF(varCondToken);
			if (CondPos != KErrNotFound)
				{
				tempEnd = CondPos;
				}
		    }

		// now look for the actual value
        TBool searchAgain = EFalse;
        _LIT(varTokenString, "%S=");
		TPtr varToken = iToken->Des();
		varToken.Format(varTokenString, &aValue);

        TInt pos = KErrNotFound;
        do
            {
            searchAgain = EFalse;
            pos = pBlock.FindF(varToken);
		    if (pos != KErrNotFound && pos < tempEnd)
		        {
                // check that this is a complete match, not a substring
                // match against another similar field, e.g. LoginScript
                // must only match against "LoginScript" not "UseLoginScript"
                if  (pos > 0)
                    {
                    // Previous character must be white space
                    const TChar previousCharacter = pBlock[pos - 1];
                    if  (previousCharacter.IsSpace())
                        {
			            // make sure we haven't overrun our block
			            TInt length = varToken.Length();
			            if (pos + length < tempEnd)
			                {
				            TLex lex(pBlock.Mid(pos + length));

				            // if enclosed by quotes, extract the text within
				            if (lex.Peek() == '"')
				                {
					            lex.SkipAndMark(1);			// start of data

					            // stop at end of quote or line
					            while(lex.Peek() != '"' && lex.Peek() != 10 && lex.Peek() != 13)
									{
						            lex.Inc();
									}
				                }
							else if(lex.Peek() == 10 || lex.Peek() == 13)	// skip empty or blank field value
								{
								return KErrArgument;
								}
							else	// skip any unwanted spaces or tabs in a field value
								{
								TBool fieldValFound=EFalse;
								while(lex.Peek() != 10 && lex.Peek() != 13) 
									{
									if(!fieldValFound)
										{
										while(lex.Peek() == 9 || lex.Peek() == 32) // skip any space or a tab
											{
											lex.SkipAndMark(1);
											}
										if(lex.Peek() == 10 || lex.Peek() == 13) // field value simply filled with space or tab
											{
											return KErrArgument;
											}
										}
									fieldValFound=ETrue;	// start of real data
									lex.Inc();
									}
								}

				            aSetting.Set(lex.MarkedToken().Ptr(),lex.MarkedToken().Length());
							valid = KErrNone;
                            }
                        }
                    else
                        {
                        // E.g. LoginScript matched against UseLoginScript -> must look
                        // for another match after the current one
                        pBlock.Set(pBlock.Mid(pos+1));
                        searchAgain = ETrue;
                        }
                    }
			    }
            }
        while(searchAgain);

	    }

	return valid;
    }
Esempio n. 7
0
// ----------------------------------------------------------------------------
// TTunnelParser::NextToken
// Returns the next token type in the input stream. iToken gets the value of
// the (string) token.
// ----------------------------------------------------------------------------
//
TTunnelParser::TTokenType TTunnelParser::NextToken ()
{
    TChar ch;
    TTokenType val;

    SkipSpaceAndMark ();
    if (Eos ())
        val = ETokenTypeEof;
    else
    {
        ch = Get ();
        switch (ch)
        {
        case '{':
            val = ETokenTypeBraceLeft;
            break;
        case '}':
            val = ETokenTypeBraceRight;
            break;
        case '(':
            val = ETokenTypeParLeft;
            break;
        case ')':
            val = ETokenTypeParRight;
            break;
        case '=':
            val = ETokenTypeEqual;
            break;
        case ',':
            val = ETokenTypeComma;
            break;
        case '#':
            val = ETokenTypeComment;
            while (!Eos())
            {
                ch = Get();
                if (ch == '\n' || ch == '\r')
                    break;
            }
            break;
        default:
            // Integers, ip addresses, etc. are mapped to strings.
            val = ETokenTypeString;
            while (!Eos ())
            {
                ch = Peek ();
                if (ch == '{' || ch == '}' ||
                        ch == '(' || ch == ')' ||
                        ch == '=' || ch == '#' ||
                        ch == ',' || ch.IsSpace ())
                    break;
                Inc ();
            }
        }
    }

    iToken.Set (MarkedToken ());
    SkipSpaceAndMark ();

    return val;
}
/**
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);
    }