Load data

Top  Previous  Next

How to ... > Load data

 

External data are needed in a project now and then. Single parameters can be submitted as a start parameter. It is, however, also possible to read larger amounts of data from an external file.

 

In the following example a list of surnames shall be used to decide whether a name recognized with a token NAME is a first name or not. This can be done with the following code if the first names are stored as keys in the map m_mFirstNames.

 

NAME                   

{{ 

  if(m_mFirstNames.findKey(to_upper_copy(xState.str())))

    xsVorname = xState.str(); 

   else

    xsNachname = xState.str();  

}}

 

To feed the first names into the map, at first a file is loaded with the names into a string buf which then is parsed with the production ReadFirstNames.

 

{{

str buf;

 

if(!load_file(buf, "FirstNames.txt"))

  throw CTT_Error("\"FirstNames.txt\" konnte nicht geladen werden");

 

ReadFirstNames(buf);  

}}

 

 

The production ReadFirstNames is called as sub-parser within the semantic action here. The list could look like:

 

AARON

ACHIM

ADALBERT

ADALIA

ADAM

ADELBERT

ADELE

...

 

It is very simple to parse it:

 

(

  SKIP   {{ m_mFirstNames[trim_right_copy(xState.str())] = ""; }}

  EOL

)*

 

 

 



This page belongs to the TextTransformer Documentation

Home  Content  German