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; }
// ----------------------------------------------------------------------------- // CStartupAdaptationStubModel::ReadStructuredListL // // ----------------------------------------------------------------------------- // void CStartupAdaptationStubModel::ReadStructuredListL( const TInt aNumParts, TLex& aLexer, CStructuredList& aList ) { RDEBUG( _L( "CStartupAdaptationStubModel::ReadStructuredListL." ) ); while ( !aLexer.Eos() ) { aList.AppendL( ReadDurationL( aLexer ) ); TUint val( 0 ); User::LeaveIfError( aLexer.Val( val, EHex ) ); aList.AppendL( val ); for ( TInt i = 0; i < aNumParts - 1; i++ ) { if ( aLexer.Get() != ',' ) User::Leave( KErrCorrupt ); User::LeaveIfError( aLexer.Val( val, EHex ) ); aList.AppendL( val ); } if ( !aLexer.Eos() && aLexer.Get() != ';' ) User::Leave( KErrCorrupt ); } if ( aList.Count() == 0 ) User::Leave( KErrCorrupt ); RDEBUG_1( _L( "CStartupAdaptationStubModel::ReadStructuredListL finished. List length: %d" ), aList.Count() ); }
// ---------------------------------------------------- // CheckIPv4Address() // IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT // ---------------------------------------------------- // LOCAL_C TBool CheckIPv4Address( TLex& aLex ) { return CheckIPv4AddressPart( aLex ) && aLex.Get() == '.' && CheckIPv4AddressPart( aLex ) && aLex.Get() == '.' && CheckIPv4AddressPart( aLex ) && aLex.Get() == '.' && CheckIPv4AddressPart( aLex ) && aLex.Get() == '\0' ; }
// ---------------------------------------------------- // CheckIPv6HexPart() // hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ] // ---------------------------------------------------- // LOCAL_C TBool CheckIPv6HexPart( TLex& aLex ) { TBool hexSeq( DoOrReverse( CheckIPv6HexSeq, aLex ) ); TBool doubleSemiColon( EFalse ); if( aLex.Peek() == ':' ) { aLex.Inc(); if( aLex.Get() == ':' ) { doubleSemiColon = ETrue; DoOrReverse( CheckIPv6HexSeq, aLex ); } } return hexSeq || doubleSemiColon; }
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; }
// ----------------------------------------------------------------------------- // CStartupAdaptationStubModel::ReadDurationL // // ----------------------------------------------------------------------------- // TInt CStartupAdaptationStubModel::ReadDurationL( TLex& aLexer ) { RDEBUG( _L( "CStartupAdaptationStubModel::ReadDurationL." ) ); TInt val = KDefaultDuration; if ( aLexer.Peek() == '[' ) // Duration value is written to file { aLexer.Inc(); User::LeaveIfError( aLexer.Val( val ) ); if ( aLexer.Get() != ']' ) { User::Leave( KErrCorrupt ); } } RDEBUG_1( _L( "CStartupAdaptationStubModel::ReadDurationL finished with %d." ), val ); return val; }
// ----------------------------------------------------------------------------- // CSTSPinConverter::IsAllDigits // Checks, are all values in gived descriptor digits or not. // Returns: ETrue: All was digits // EFalse: At least one value was not digit // ----------------------------------------------------------------------------- TBool CSTSPinConverter::IsAllDigits(const TDesC& aPinValue) { //if empty if (aPinValue.Length() == 0) { return EFalse; } TLex lex; lex.Assign(aPinValue); while (lex.Peek() != 0) { if (!(lex.Get()).IsDigit()) { //if was not digit return EFalse; } } return ETrue; }
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); } }
// ---------------------------------------------------- // CheckIPv6ColonHex4() // ":" hex4 // Used as a helper to give to Star() // ---------------------------------------------------- // LOCAL_C TBool CheckIPv6ColonHex4( TLex& aLex ) { return aLex.Get() == ':' && CheckIPv6Hex4( aLex ); }
TBool CSettingView::SaveSettingsL() { // Save settings to the member variables StoreSettingsL(); // Validate input TLex lex; TInt maxPacketCount; lex.Assign( iMaxPacketCount ); if ( lex.Val( maxPacketCount ) != KErrNone ) { CEikonEnv::Static()->InfoMsg(_L("Packet count must be numeric")); return EFalse; } TInt packetDataSize; lex.Assign( iPacketDataSize ); if ( lex.Val( packetDataSize ) != KErrNone ) { CEikonEnv::Static()->InfoMsg(_L("Packet size must be numeric")); return EFalse; } TInt waitTime; lex.Assign( iWaitTime ); if ( lex.Val( waitTime ) != KErrNone ) { CEikonEnv::Static()->InfoMsg(_L("Wait time must be numeric")); return EFalse; } TInt lastWaitTime; lex.Assign( iLastWaitTime ); if ( lex.Val( lastWaitTime ) != KErrNone ) { CEikonEnv::Static()->InfoMsg(_L("Last wait time must be numeric")); return EFalse; } lex.Assign( iPattern ); while (!lex.Eos()) { if (!lex.Get().IsHexDigit()) { CEikonEnv::Static()->InfoMsg(_L("Pattern must be hexadecimal")); return EFalse; } } // Validation OK, so save settings to the model iPingModel->iPackLimit = iLimitPacketCount; iPingModel->iTotalPackets = maxPacketCount; iPingModel->iPacketDataSize = packetDataSize; iPingModel->iSecWait = waitTime; iPingModel->iLastSecWait = lastWaitTime; iPingModel->iPattern.Copy(iPattern); iPingModel->iQuiet = iQuiet; iPingModel->iVerbose = iVerbose; iPingModel->iDebug = iDebug; #ifdef IAPSETTING TInt iap; lex.Assign( iIAP ); lex.Val( iap ); iPingModel->iIAP = iap; #endif return ETrue; }