Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14267
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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is there a function to remove leading white space?
Next Topic: TimeDate.cpp [BUG][FIXED]
Goto Forum:
  


Current Time: Thu Sep 04 00:56:08 CEST 2025

Total time taken to generate the page: 0.04961 seconds