Xmipp  v3.23.11-Nereus
xmipp_strings.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: J.R. Bilbao-Castro (jrbcast@ace.ual.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef CORE_XMIPP_STRINGS_H
27 #define CORE_XMIPP_STRINGS_H
28 
29 #include <vector>
30 #include <string>
31 #include <string.h>
32 
33 //TODO: For now just a typedef, I think that would be worth to write a String class
34 typedef std::string String;
35 typedef std::vector<String> StringVector;
36 
39 
40 
42 #define STR_EQUAL(str1, str2) (strcmp((str1), (str2)) == 0)
43 
44 //@name String processing
46 
49 String removeChar( const String& str, char character );
50 
52 String unescape( const String& str );
53 
88 int bestPrecision(float F, int _width);
89 
96 float textToFloat(const char* str);
97 
99 inline float textToFloat(const String& str)
100 {
101  return textToFloat(str.c_str());
102 }
103 
110 int textToInteger(const char* str);
111 
113 size_t textToSizeT(const char * str);
114 
116 inline int textToInteger(const String& str)
117 {
118  return textToInteger(str.c_str());
119 }
120 
128 long long textToLongLong(const char* str);
129 
141 String floatToString(float F, int _width = 8, int _prec = 0);
142 
153 String integerToString(int I, int _width = 0, char fill_with = '0');
154 
166  int charToInt(const char* str);
167 
175 String stringToString(const String& str, size_t _width = 0);
176 
181 void checkAngle(const String& str);
182 
188 void toLower(char* _str);
189 
192 void toLower(String& _str);
193 
198 String simplify( const String& str );
199 
201 void trim(String& str);
202 
208 String removeSpaces(const String& _str);
209 
220 void removeQuotes(char** _str);
221 
226 String findAndReplace(const String& tInput, const String &tFind,
227  const String &tReplace);
229 
261 int splitString(const String& input,
262  const String& delimiter,
263  StringVector & results,
264  bool includeEmpties = false);
265 
274 inline char* firstToken(const char* str)
275 {
276  return strtok((char*) str, " \t\n");
277 }
278 
287 inline char* firstToken(const String& str)
288 {
289  return strtok((char*) str.c_str(), " \t\n");
290 }
291 
309 inline char* nextToken()
310 {
311  return strtok((char*) NULL, " \t\n");
312 }
313 
319 String nextToken(const String& str, size_t& i);
320 
329 char* firstWord(char* str);
330 
335 inline char* firstWord(String& str)
336 {
337  // FIXME C-style cast
338  return firstWord((char*) str.c_str());
339 }
340 
346 inline char* nextWord()
347 {
348  return firstWord((char*) NULL);
349 }
350 
354 void tokenize(const String& str,
355  StringVector & tokens,
356  const String& delimiters = " \t");
357 
388 char *memtok(char **src, char **_end, const char *sep);
389 
391 void * _memmem ( const void *haystack, size_t haystack_len, const void *needle, size_t needle_len);
393 
397 String formatString(const char * format, ...);
398 
402 void formatStringFast(String &str, const char * format, ...);
403 
405 bool matchRegExp(const String &inputString, const String &pattern);
407 String WordWrap(const String &inputString, size_t lineLength);
408 
413 
417 bool endsWith(const char* str1, const char* str2);
419 #endif
char * firstWord(char *str)
bool endsWith(const char *str1, const char *str2)
String removeSpaces(const String &_str)
void trim(String &str)
String WordWrap(const String &inputString, size_t lineLength)
int bestPrecision(float F, int _width)
String integerToString(int I, int _width=0, char fill_with='0')
char * nextToken()
std::vector< String > StringVector
Definition: xmipp_strings.h:35
#define i
char * memtok(char **src, char **_end, const char *sep)
void * _memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len)
void checkAngle(const String &str)
float textToFloat(const char *str)
int splitString(const String &input, const String &delimiter, StringVector &results, bool includeEmpties=false)
String simplify(const String &str)
String findAndReplace(const String &tInput, const String &tFind, const String &tReplace)
void removeQuotes(char **_str)
String removeChar(const String &str, char character)
void tokenize(const String &str, StringVector &tokens, const String &delimiters=" \)
char * nextWord()
long long textToLongLong(const char *str)
String stringToString(const String &str, size_t _width=0)
String escapeForRegularExpressions(const String &str)
bool matchRegExp(const String &inputString, const String &pattern)
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
int textToInteger(const char *str)
char * firstToken(const char *str)
int charToInt(const char *str)
String unescape(const String &str)
void toLower(char *_str)
String floatToString(float F, int _width=8, int _prec=0)
size_t textToSizeT(const char *str)
void formatStringFast(String &str, const char *format,...)