#include "StringLine.hxx"
|
string | ReplaceAll (string InLine, string ToReplace, string By) |
|
template<class out_T , class in_T > |
out_T | convert (const in_T &t) |
|
|
static string | NextWord (string Line, int &start, char sep=' ', char alt_sep='\0') |
|
static string | PreviousWord (string Line, int &start, char sep=' ', char alt_sep='\0') |
|
static void | ToLower (string &Line) |
|
static void | ToUpper (string &Line) |
|
static int | Find (const char *search, string Line) |
|
static int | rFind (const char *search, string Line) |
|
template<class out_T , class in_T > |
static out_T | convert (const in_T &t) |
|
static int | GetStartWord (string Line, int CurrentPosition, char sep=' ', char alt_sep='\0') |
|
static int | GetEndWord (string Line, int CurrentPosition, char sep=' ', char alt_sep='\0') |
|
The aim of this class is to provide tools to extract fields ("word") from a string and convert a string in Upper/Lower case. All methods are static so that it is not necessary to create object to use them
example:
string line="The temperature is : 300.6 K";
int start;
start=0;
string temperature_is=SL.
NextWord(line,start,
':');
double T=atof(SL.
NextWord(line,start).c_str());
cout<<the<<endl<<temperature_is<<endl<<T<<endl;
2nd method: "using" the static methods
start=0;
cout<<the<<endl<<temperature_is<<endl<<T<<endl;
- Auteur
- PTO
- Version
- 2.01
Définition à la ligne 49 du fichier StringLine.hxx.
template<class out_T , class in_T >
static out_T StringLine::convert |
( |
const in_T & |
t | ) |
|
|
static |
Example:
string s="32.12";
double t=StringLine::convert<double>(s);
string temperature=StringLine::convert<string>(300.);
- Paramètres
-
template<class out_T , class in_T >
out_T StringLine::convert |
( |
const in_T & |
t | ) |
|
|
inline |
int StringLine::Find |
( |
const char * |
search, |
|
|
string |
Line |
|
) |
| |
|
inlinestatic |
returns the position, starting from the begenning of the first occurence of search
in Line
if it is found, else returns -1
- Paramètres
-
search | : a string to find |
Line | : where to search |
Définition à la ligne 235 du fichier StringLine.hxx.
237 size_t Pos=Line.find(search);
238 if(Pos != string::npos )
return Pos;
int StringLine::GetEndWord |
( |
string |
Line, |
|
|
int |
CurrentPosition, |
|
|
char |
sep = ' ' , |
|
|
char |
alt_sep = '\0' |
|
) |
| |
|
inlinestatic |
- Paramètres
-
Line | : a line containing words |
CurrentPosition | : from where to start to find the end of a word |
sep | : the separator between 2 words (default=space) |
alt_sep | : the alternative separator between 2 words (default='') |
Définition à la ligne 217 du fichier StringLine.hxx.
219 int pos=Line.find(sep,CurrentPosition);
222 alt_pos=Line.find(alt_sep,CurrentPosition);
226 real_pos=min(pos,alt_pos);
227 if(pos==
int(string::npos))real_pos=alt_pos;
229 if(real_pos==
int(string::npos))
int StringLine::GetStartWord |
( |
string |
Line, |
|
|
int |
CurrentPosition, |
|
|
char |
sep = ' ' , |
|
|
char |
alt_sep = '\0' |
|
) |
| |
|
inlinestatic |
- Paramètres
-
Line | : a line containing words |
CurrentPosition | : from where to start to find the begining of a word |
sep | : the separator between 2 words (default=space) |
alt_sep | : the alternative separator between 2 words (default='') |
Définition à la ligne 195 du fichier StringLine.hxx.
197 int pos=Line.find(sep,CurrentPosition);
200 alt_pos=Line.find(alt_sep,CurrentPosition);
205 real_pos=min(pos,alt_pos);
206 if(pos==
int(string::npos))real_pos=alt_pos;
210 if(real_pos==
int(string::npos))
return CurrentPosition;
211 while(CurrentPosition<
int(Line.size()) && Line[CurrentPosition]==real_sep)
213 return CurrentPosition;
string StringLine::NextWord |
( |
string |
Line, |
|
|
int & |
start, |
|
|
char |
sep = ' ' , |
|
|
char |
alt_sep = '\0' |
|
) |
| |
|
inlinestatic |
Find Next word in a line starting from position "start" in the line. If an alternative separator is given, the word length is defined by the first position of sep or alt_sep found. The first value of start is in general 0 (i.e. the beginning of the Line)
- Paramètres
-
Line | : a line containing words |
start | : from where to start to find the begining of a word |
sep | : the separator between 2 words (default=space) |
alt_sep | : the alternative separator between 2 words (default='') |
Définition à la ligne 131 du fichier StringLine.hxx.
134 if(start>=
int(Line.size()))
139 int wordlength=
GetEndWord(Line,start,sep,alt_sep)-start;
141 Word=Line.substr(start,wordlength);
string StringLine::PreviousWord |
( |
string |
Line, |
|
|
int & |
start, |
|
|
char |
sep = ' ' , |
|
|
char |
alt_sep = '\0' |
|
) |
| |
|
inlinestatic |
Find Previous word in a line starting from position "start" in the line. If an alternative separator is given, the word length is defined by the first position of sep or alt_sep found. The first value of start is in general the end of the Line.
- Paramètres
-
Line | : a line containing words |
start | : from where to start to find the begining of a word |
sep | : the separator between 2 words (default=space) |
alt_sep | : the alternative separator between 2 words (default='') |
Définition à la ligne 147 du fichier StringLine.hxx.
154 int pos=Line.rfind(sep,start);
160 alt_pos=Line.rfind(alt_sep,start);
161 real_pos=max(pos,alt_pos);
165 int wordlength=start-Line.rfind(real_sep,real_pos);
168 Word=Line.substr(0,start+1);
172 Word=Line.substr(real_pos+1,wordlength);
string StringLine::ReplaceAll |
( |
string |
InLine, |
|
|
string |
ToReplace, |
|
|
string |
By |
|
) |
| |
|
inline |
- Paramètres
-
InLine | : the string which contains the sub-string to replace |
ToReplace | : the sub-string to replace |
By | : the sub-string ToReplace is replaced by the sub-string By in Inline |
Définition à la ligne 262 du fichier StringLine.hxx.
265 int pos=InLine.find(ToReplace,start);
266 while(pos!=
int(string::npos))
268 InLine.replace(pos,ToReplace.size(),By);
270 pos=InLine.find(ToReplace,start);
int StringLine::rFind |
( |
const char * |
search, |
|
|
string |
Line |
|
) |
| |
|
inlinestatic |
returns the position, starting from the end of the first occurence of search
in Line
if it is found, else returns -1
- Paramètres
-
search | : a string to find |
Line | : where to search |
Définition à la ligne 243 du fichier StringLine.hxx.
245 size_t Pos=Line.rfind(search);
246 if(Pos != string::npos)
return Pos;
void StringLine::ToLower |
( |
string & |
Line | ) |
|
|
inlinestatic |
Définition à la ligne 179 du fichier StringLine.hxx.
181 transform (Line.begin(), Line.end(),
183 (int(*)(int))tolower);
void StringLine::ToUpper |
( |
string & |
Line | ) |
|
|
inlinestatic |
Définition à la ligne 187 du fichier StringLine.hxx.
189 transform (Line.begin(), Line.end(),
191 (int(*)(int))toupper);
La documentation de cette classe a été générée à partir du fichier suivant :