// --------------------------------------------------------------------------- // SdpUtil::ChopElementsFromLineL // Chops all the elements that are divided by delimiter from the string // --------------------------------------------------------------------------- // void SdpUtil::ChopElementsFromLineL( RArray<TPtrC8>& aArray, TLex8& aLexer, TChar aDelimiter, TInt aErrCode ) { // Chop the elements to the array from lexer TBool eofcFound = EFalse; while (!eofcFound) { aLexer.Mark(); // Parse single token, leave other special characters // to token except aDelimiter | '\r' | '\n' | '\0' while ( aLexer.Peek() != aDelimiter && aLexer.Peek() != KCRChar && aLexer.Peek() != KLFChar && aLexer.Peek() != KEofChar ) { aLexer.Inc(); } if ( aLexer.MarkedToken().Length() > 0 ) { aArray.AppendL( aLexer.MarkedToken() ); } if ( aDelimiter == KSPChar && aLexer.Peek() == aDelimiter ) { SkipSpacesUntilNextLineBreak( aLexer ); } // Check if its end-of-line if ( aLexer.Peek() == KCRChar ) { aLexer.Inc(); } if ( aLexer.Peek() == KLFChar ) { aLexer.Inc(); if ( aLexer.Peek() != KEofChar ) { User::Leave( aErrCode ); } eofcFound = ETrue; } else if ( aLexer.Peek() == KEofChar ) { // EoF character not tolerated at the middle of the string User::Leave( aErrCode ); } else { aLexer.Inc(); } } }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetTokenText // ----------------------------------------------------------------------------- // TPtrC8 CWPPushMessage::GetTokenText( TLex8& aPointer ) const { // Token text is just characters with an end-of-string marker. aPointer.Mark(); while( !aPointer.Eos() && aPointer.Get() != EKeyNull ) { // Do nothing } return aPointer.MarkedToken(); }
TInt CTestConfig::GetNextElement(TLex8& aInput, TChar aDelimiter, TPtrC8& aOutput) { if (aInput.Eos()) return KErrNotFound; //Get to the start of the descriptor while (!aInput.Eos() && aInput.Peek() != aDelimiter) aInput.Inc(); aOutput.Set(aInput.MarkedToken()); if (!aInput.Eos()) aInput.SkipAndMark(1); return KErrNone; }
TBool CTestConfig::IsNewComment(const TDesC8& aSource, const TLex8& aLex) const { TBool ret(EFalse); const TPtrC8 token(aLex.MarkedToken()); const TPtrC8 commentStart(KScriptCommentStart); const TInt commentStartLen(commentStart.Length()); const TInt tokenLen(token.Length()); if (commentStartLen <= tokenLen && token.Left(commentStartLen).Compare(commentStart) == 0) { ret = IsAtStartOfNewLine(aSource, aLex, ETrue); } return ret; }
TBool CTestConfig::IsNewItem(const TDesC8& aSource, const TLex8& aLex, TPtrC8& aItem, TInt& aStartOfVal) const { TBool ret(EFalse); if (IsAtStartOfNewLine(aSource, aLex, ETrue)) { const TPtrC8 itemEnd(KScriptItemEnd); const TInt itemEndLen(itemEnd.Length()); TPtrC8 token(aLex.MarkedToken()); //First check to see if this token contains '=' const TInt find = token.Find(itemEnd); if (find > 0) { aStartOfVal = find + itemEndLen; aItem.Set(token.Left(find)); ret = ETrue; } else { aItem.Set(token); aStartOfVal = token.Length(); const TPtrC8 remain(aLex.Remainder()); TLex8 lex(remain); //Check that the next token starts with and '=' lex.SkipSpaceAndMark(); lex.SkipCharacters(); token.Set(lex.MarkedToken()); if (token.Find(itemEnd) == 0) { aStartOfVal += lex.MarkedOffset() + itemEndLen; ret = ETrue; } } } return ret; }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetTextString // ----------------------------------------------------------------------------- // TPtrC8 CWPPushMessage::GetTextString( TLex8& aPointer ) const { // Text-string can be quoted. if( aPointer.Peek() == KQuotedTextStringStart ) { aPointer.Inc(); } aPointer.Mark(); while( aPointer.Get() != EKeyNull ) { // Nothing } // We don't want to have NULL in the resulting descriptor, so // back that out. aPointer.UnGet(); TPtrC8 result( aPointer.MarkedToken() ); aPointer.Inc(); return result; }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetTextValue // ----------------------------------------------------------------------------- // TPtrC8 CWPPushMessage::GetTextValue( TLex8& aPointer ) const { // Text-value can be quoted, so skip that first. if( aPointer.Peek() == KQuotedStringStart ) { aPointer.Inc(); } aPointer.Mark(); // It is null-terminated while( aPointer.Get() != EKeyNull ) { // Do nothing } // We don't want to have NULL in the resulting descriptor, so // back that out. TPtrC8 result( aPointer.MarkedToken() ); result.Set( result.Left( Max( 0, result.Length()-1 ) ) ); return result; }
// ----------------------------------------------------------------------------- // SdpUtil::GetElementsFromLineL // Gets all the elements from a single line // ----------------------------------------------------------------------------- // RArray<TPtrC8> SdpUtil::GetElementsFromLineL( TLex8& aLexer, TChar aDelimiter, TInt aErrCode ) { RArray<TPtrC8> lineArray; CleanupClosePushL( lineArray ); // Header is special case, because it is joined _without_ // space character with the first attribute, so it must be // parsed separately aLexer.Mark(); // curChar must be != KEqualChar at first comparison for ( TChar curChar( KSPChar ); curChar != KEqualChar; ) { curChar = aLexer.Peek(); // Syntax check if ( curChar == KEofChar || curChar == KLFChar || curChar == KCRChar ) { User::Leave( aErrCode ); } aLexer.Inc(); } // Append header to array User::LeaveIfError( lineArray.Append( aLexer.MarkedToken() ) ); // Whitespace MUST NOT be used after the "=" sign if (aLexer.Peek() == KSPChar) { User::Leave( aErrCode ); } // Get the other elements from the string to the array ChopElementsFromLineL( lineArray, aLexer, aDelimiter, aErrCode ); CleanupStack::Pop(); // lineArray return lineArray; }
TBool CTestConfig::IsNewSection(const TDesC8& aSource, const TLex8& aInput) const /** * Checks whether the current marked token in aInput starts with a '[' and ends with a ']', * and checks that this token is at the start of a line. * * @returns Whether this is a new section in the script file */ { const TPtrC8 token(aInput.MarkedToken()); const TInt offset(aInput.MarkedOffset()); TBool ret = token.Length() > 2 && token.Find(KScriptSectionStart) == 0; ret = ret && token.Find(KScriptSectionEnd) != KErrNotFound; if (ret && offset > 0) { const TPtrC8 lastChar(aSource.Mid(offset-1, 1)); ret = ret && (lastChar == KScriptLF || lastChar == KScriptCR); } return ret; }
void CDomainNameCodec::EncodeL(TDomainNameArray& aNames, RBuf8& aBuf8) { TUint requiredLength = 0; TUint8 nameIdx = 0; for (nameIdx=0;nameIdx<aNames.Count();nameIdx++) { // The total length required for the labels that comprise an // individual domain name needs to take into the length octet // for the initial label and the null-termination character. // Hence the '+ 2' below. requiredLength += (aNames[nameIdx].Length() + 2); // A further length check is performed on each domain name to // ensure it does not exceed the maximum length permitted according // to RFC 1035. if(aNames[nameIdx].Length() > KMaxDomainNameLength) { User::Leave(KErrArgument); } } aBuf8.Zero(); aBuf8.ReAllocL(requiredLength); TLex8 domainName; TPtrC8 currentLabel; for (nameIdx=0;nameIdx<aNames.Count();nameIdx++) { domainName.Assign(aNames[nameIdx]); domainName.Mark(); while (!domainName.Eos()) { TChar ch; do { ch = domainName.Get(); } while ( ch != TChar('.') && !domainName.Eos() ); // if not the end of the string, unget the previous char to skip the trailing // dot in our marked token // if( !domainName.Eos() ) { domainName.UnGet(); } currentLabel.Set(domainName.MarkedToken()); // move past the dot again, or do nothing in particular at EOS // domainName.Get(); User::LeaveIfError(currentLabel.Length() > KMaxDnsLabelLength ? KErrArgument : KErrNone); aBuf8.Append(TChar(currentLabel.Length())); aBuf8.Append(currentLabel); domainName.Mark(); } aBuf8.Append(TChar(0)); } }