cbsref/telephonyrefplugins/atltsy/atcommand/generic/src/respondbufparser.cpp
changeset 49 f50f4094acd7
equal deleted inserted replaced
48:14460bf2a402 49:f50f4094acd7
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This contains CRespondBufParser which provide an algorithm to analize the passed data from baseband
       
    15 //
       
    16 
       
    17 #include "respondbufparser.h"
       
    18 #include "mslogger.h"
       
    19 
       
    20 _LIT8(KSpace, " ");
       
    21 
       
    22 CRespondBufParser::CRespondBufParser() 
       
    23 	{	
       
    24 	}
       
    25 
       
    26 CRespondBufParser::~CRespondBufParser()
       
    27 	{
       
    28 	}
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CRespondBufParser::ParseRespondedBuffer
       
    32 // other items were commented in a header
       
    33 // ---------------------------------------------------------------------------		
       
    34 void CRespondBufParser::ParseRespondedBuffer(RArray<TPtrC8>& aArray, const TDesC8& aBuf)
       
    35 	{
       
    36 	aArray.Reset();
       
    37 	
       
    38 	TBool firstDoubleQuoteFound = EFalse;
       
    39 	TBool endByComma = EFalse;
       
    40 	TBool Marked = EFalse;
       
    41 	TLex8 tmpLex(aBuf);
       
    42 	
       
    43 	//Move cursor past any spaces or open brackets
       
    44 	while(!tmpLex.Eos())
       
    45 		{
       
    46 		TChar peek=tmpLex.Peek();
       
    47 		switch(peek)
       
    48 			{
       
    49 			//Skip the '(','[', and '{' in end
       
    50 			case '(':
       
    51 			case '[':
       
    52 			case '{':
       
    53 				break;
       
    54 			//Skip the '(','[', and '{' in end
       
    55 			case ')':
       
    56 			case ']':
       
    57 			case '}':
       
    58 				break;
       
    59 			case '"': 
       
    60 				//Skip first '"'
       
    61 				if(!firstDoubleQuoteFound)
       
    62 					{
       
    63 					firstDoubleQuoteFound = ETrue;
       
    64 					}
       
    65 				else
       
    66 					{
       
    67 					//Extracts the marked token(No include the '"' in end)
       
    68 					firstDoubleQuoteFound = EFalse;
       
    69 					TPtrC8 temp = tmpLex.MarkedToken();
       
    70 					aArray.Append(temp);
       
    71 					LOGTEXT2(_L8("normal parameter >%S<"),&(temp));
       
    72 					Marked = EFalse;
       
    73 					endByComma = EFalse;
       
    74 					}
       
    75 				break;
       
    76 			case ',':
       
    77 				if(!firstDoubleQuoteFound)
       
    78 					{
       
    79 					if(Marked)
       
    80 						{
       
    81 						//Extracts the marked token
       
    82 						TPtrC8 temp = tmpLex.MarkedToken();
       
    83 						aArray.Append(temp);
       
    84 						LOGTEXT2(_L8("normal parameter >%S<"),&(temp));
       
    85 						Marked = EFalse;
       
    86 						}
       
    87 					else if(endByComma)
       
    88 						{
       
    89 						//Add a space between two camma
       
    90 						aArray.Append(KSpace());
       
    91 						LOGTEXT2(_L8("normal parameter >%S<"),&(KSpace()));
       
    92 						}
       
    93 					endByComma = ETrue;
       
    94 					}
       
    95 				break;
       
    96 			case ';':
       
    97 			case ' ': 
       
    98 			case '\r': 
       
    99 			case '\n': 
       
   100 				if(!firstDoubleQuoteFound&&Marked)
       
   101 					{
       
   102 					//Extracts the marked token
       
   103 					TPtrC8 temp = tmpLex.MarkedToken();
       
   104 					aArray.Append(temp);
       
   105 					LOGTEXT2(_L8("normal parameter >%S<"),&(temp));
       
   106 					Marked = EFalse;	
       
   107 					endByComma = EFalse;
       
   108 					}
       
   109 				break;
       
   110 			case ':': 
       
   111 				if(!firstDoubleQuoteFound&&Marked)
       
   112 					{
       
   113 					//Extracts the marked token(Include ':')
       
   114 					tmpLex.Inc();
       
   115 					TPtrC8 temp = tmpLex.MarkedToken();
       
   116 					aArray.Append(temp);
       
   117 					LOGTEXT2(_L8("normal parameter >%S<"),&(temp));
       
   118 					//back one char because add it in end 
       
   119 					tmpLex.Inc(-1);
       
   120 					Marked = EFalse;
       
   121 					endByComma = EFalse;
       
   122 					}
       
   123 				break;
       
   124 			default:
       
   125 				if(!Marked)
       
   126 					{
       
   127 					tmpLex.Mark();
       
   128 					Marked = ETrue;	
       
   129 					}
       
   130 				break;
       
   131 			}
       
   132 		tmpLex.Inc();
       
   133 		}
       
   134 	if(Marked)
       
   135 		{
       
   136 		//Extracts the marked token which haven't 
       
   137 		TPtrC8 temp = tmpLex.MarkedToken();
       
   138 		aArray.Append(temp);
       
   139 		LOGTEXT2(_L8("normal parameter >%S<"),&(temp));
       
   140 		}
       
   141 	}