|
|
Home » U++ Library support » U++ Core » Is there a token function?
|
Re: Is there a token function? [message #2717 is a reply to message #2716] |
Sat, 22 April 2006 22:39 |
|
mirek
Messages: 14105 Registered: November 2005
|
Ultimate Member |
|
|
Well, if you are not to process 100MB+ files that are not well divided into lines and has similar lexical syntax to C, the easiest and fastest U++ way is to LoadFile into String and then use CParser.
If you DO want to process 100MB+ files and/or they are divided into lines, usually you can use similar approach, just use CParser per each single line. Or process it in any other way - in this particular case, I believe "Split" would be the best option (as you have fields separated by ';').
BTW, what you present is kind of import I have to provide for my customers quite often. Skeleton of such parser usually looks like
FileIn in(path_to_file);
in.GetLine(); // to eat "header" line
try {
while(!in.IsEof()) {
Vector<String> field = Split(in.GetLine(), ';');
if(field.GetCount() != 11)
throw CParser::Error("");
String name = field[0];
String coutnry = field[1];
CParser p(field[2]);
Date d;
d.day = p.ReadInt();
p.PassChar('.');
d.month = p.ReadInt();
p.PassChar('.');
d.year = p.ReadInt();
if(d.year < 20)
d.year += 2000;
else
if(d.year < 100)
d.year += 1900;
}
}
catch(CParser::Error) {
// invalid file
}
[Updated on: Sun, 23 April 2006 10:03] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Is there a token function? [message #2744 is a reply to message #2737] |
Mon, 24 April 2006 01:01 |
|
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
luzr wrote on Sun, 23 April 2006 14:44 |
fudadmin wrote on Sun, 23 April 2006 09:33 | Yes, I'had seen that in streams. I just wanted to know why GetLine is absent in String?
|
What should it do? I can't imagine anything reasonable...
Mirek
|
In fact, I want something like in FOX:
/// Return num partition(s) beginning at start from a string separated by delimiters delim.
FXString section(FXchar delim,FXint start,FXint num=1) const;
/// Return num partition(s) beginning at start from a string separated by set of delimiters from delim of size n
FXString section(const FXchar* delim,FXint n,FXint start,FXint num) const;
FXString section(const FXchar* delim,FXint start,FXint num=1) const;
FXString section(const FXString& delim,FXint start,FXint num=1) const;
I think, it's much more convienient than to have separate Vector<String> and Split for each delimiter if you work with text manipulations...
And, as I understand you have coded something similar in Uvs2 (textdiff) but that's not in the library...
|
|
|
|
Goto Forum:
Current Time: Fri Nov 01 00:52:42 CET 2024
Total time taken to generate the page: 0.04790 seconds
|
|
|