Looking for a class that provides tokens

  • Thread starter Ramon F Herrera
  • Start date
R

Ramon F Herrera

I have many files that contain multiple lines like this:

This is the variable name = This is the variable value
Name of Player = George Herman Babe Ruth

IOW, in each line there are 3 tokens:

- VariableName
- Equal Sign
- VariableValue

Contrary to many variable syntaxes commonly used, my variables and
values may contain plenty of blank space between words.

It could be great if the class can ignore empty lines, and lines that
begin with some comment symbol(s).

I am teaching myself C++. Finally decided to take the plunge motivated
by the richness of classes available.

TIA,

-Ramon
 
R

Ramon F Herrera

I have many files that contain multiple lines like this:

This is the variable name = This is the variable value
Name of Player = George Herman Babe Ruth

IOW, in each line there are 3 tokens:

 - VariableName
 - Equal Sign
 - VariableValue

Contrary to many variable syntaxes commonly used, my variables and
values may contain plenty of blank space between words.

It could be great if the class can ignore empty lines, and lines that
begin with some comment symbol(s).

I am teaching myself C++. Finally decided to take the plunge motivated
by the richness of classes available.

TIA,

-Ramon

Here's one:

http://cttl.sourceforge.net

-RFH
 
R

Ramon F Herrera

I have many files that contain multiple lines like this:

This is the variable name = This is the variable value
Name of Player = George Herman Babe Ruth

IOW, in each line there are 3 tokens:

 - VariableName
 - Equal Sign
 - VariableValue

Contrary to many variable syntaxes commonly used, my variables and
values may contain plenty of blank space between words.

It could be great if the class can ignore empty lines, and lines that
begin with some comment symbol(s).

I am teaching myself C++. Finally decided to take the plunge motivated
by the richness of classes available.

TIA,

-Ramon


This seems to have about the right complexity:

http://www.boost.org/doc/libs/1_40_0/doc/html/xpressive.html

More powerful then regex, not as complex as ANTLR.

-RFH
 
R

Ramon F Herrera

Take your learning materials, and read about the strings library, the
algorithms library, the iterators library, and also other parts of the C++
library. There is no standard class that can parse something like this, and
deliver to you the parsed results on a silver platter. However, it would be
fairly simple to use the available functions in these libraries to create a
suitable parser.

Use the std::ifstream class to open your configuration file, and
std::getline() to read its contents, one line at a time. After skipping
blank lines, and lines whose first character is the comment character, use
std::find() to find the equals sign, and use the beginning and the ending
iterators, together with the result of std::find(), to retrieve your
variable name and value (with suitable error checking, of course).

 application_pgp-signature_part
< 1KViewDownload

Thanks, Sam.

I guess when it comes to reading and recognizing text, there are 3
distinctly layered and increasingly complex approaches:

(1) String class

(2) Regex

(3) Full blown parsing, grammar generators, etc.

Since my files can get a little more complex (for instance, they may
have blocks and multiline variables), I am trying to decide the
caliber of the gun :) to match the problem.

-Ramon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top