Hey.
As you can read from the title i'm new in this mobile word. And immediately i'm facing a problem that doesn't let me sleep.
I have to read from a text file some configurations for a certain program.
The file has this aspect:
PLAYER,NAME,10000
Three tokens separated with commas ( and these tokens are litteral for the first two and a number the last one! ). I don't care about the first token...
So here is my code, where the parameter aLine of the function is a line formatted in the way described above
TInt ReadConfigLine(TDesC& aLine)
{ // Check if it's a player
TUint charOffset = 0;
TUint markOffset = 0;
TLex lineParser(aLine);
TInt commaCount = 0;
TChar ch = lineParser.Get();
//we place the mark at the first comma we meet,
while (commaCount < 1)
{
ch = lineParser.Get();
if(ch == ','😉
{
commaCount++;
}
charOffset = lineParser.Offset();
}
lineParser.Mark();
//looking for the second comma, from here on there are the details we care about!
while (commaCount < 2)
{
ch = lineParser.Get();
if(ch == ','😉
{
commaCount++;
}
charOffset = lineParser.Offset();
}
// second comma included...
lineParser.UnGet();
TPtrC playerNamePtr = lineParser.MarkedToken();// it doesn't work as it should 😞
// The problem must be in the use of the pointer!
TText* playerName = (TText *)playerNamePtr.Ptr();
ch = lineParser.Get();
ASSERT(ch == ','😉;
lineParser.Mark();
//for this case no more commas, just mark the end of the string...
while (!lineParser.Eos())
{
ch = lineParser.Get();
}
charOffset = lineParser.Offset();
markOffset = lineParser.MarkedOffset();
TInt money;
TLex moneyToken(lineParser.MarkedToken());
moneyToken.Val(money);
return 1;
}
Mostly of this code and the inspiration was taken from http://kerncomputing.blogspot.com/2005/08/using-tlex-to-parse-gps-waypoints.html ( thanks a lot! )
Now what is wrong in my code? For sure is wrong what i get. When i try to get the token in the middle ( the second literal ) i obtain everything what goes from the first marker to the end of the line. I'm pretty sure the problem relies on the use of the TPtrC. What should i do? The token that Tlex gives me has length 4 ( the exact length of NAME ) but in the TPtrC i find: "NAME,10000".
HELP :S
Thanks in advance