Exemplo n.º 1
0
TBool TAzenqosEngineUtils::TokenizeCSV(const TDesC16& whole,TPtrC16& ret, TPtrC16& remainder, TChar aDelim)
	{
		TPtrC16 afterFristQuote(0,0);

		TBuf<3> aDelimStr;
		aDelimStr.Append(aDelim);

		TInt firstQuotePos = whole.Find(KQuote16);
		TInt CommaPos = whole.Find(aDelimStr);
		TInt secondQuotePos = -1;

		TBool encounteredQuote = EFalse;
		if(firstQuotePos>=0 && firstQuotePos<CommaPos)
		{
			encounteredQuote = ETrue;
			afterFristQuote.Set(whole.Right(whole.Length()-firstQuotePos-1));

			secondQuotePos = afterFristQuote.Find(KQuote16);

			if(secondQuotePos<0)
			{
				TBuf<32> countbuf;
				countbuf =_L("Parse Error: Mis-Quote");
		/*
			CAknErrorNote* informationNote = new (ELeave) CAknErrorNote(ETrue);
	       	informationNote->SetTimeout(CAknNoteDialog::EShortTimeout);
	       	informationNote->ExecuteLD(countbuf);*/
				return EFalse;//misquote
			}

			secondQuotePos += (firstQuotePos+1);
			CommaPos = secondQuotePos+1;



		}
		else
		{
			//csv.Set(incsv);
		}



		if(CommaPos>=0)
		{
			/*if(encounteredQuote)
			{
				ret.Set(incsv.Mid(1,CommaPos-1));
			}
			else
			{

			}*/
			ret.Set(whole.Left(CommaPos));

			if(ret.Length()>=2 && ret[0] == '"' && ret[ret.Length()-1] == '"' )
			{
				if(ret.Length()>2)
				{
					TPtrC16 tmp(0,0);
					tmp.Set(whole.Left(CommaPos));
					ret.Set(tmp.Mid(1,tmp.Length()-2));
				}
				else //ret==2
				{
					ret.Set(0,0);
				}

			}




			remainder.Set(whole.Right(whole.Length()-CommaPos-1));





			return ETrue;
		}


		//remainder.Set(incsv);
		return EFalse;
	}