Orxonox  0.0.5 Codename: Arcturus
StringUtils.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Fabian 'x3n' Landau
24  * Co-authors:
25  * ...
26  *
27  */
28 
40 #ifndef _StringUtils_H__
41 #define _StringUtils_H__
42 
43 #include "UtilPrereqs.h"
44 #include <string>
45 #include <vector>
46 
47 namespace orxonox
48 {
50 
52 
53  _UtilExport void strip(std::string* str);
55 
57 
58  _UtilExport void vectorize(const std::string& str, char delimiter, std::vector<std::string>* output);
59 
60  _UtilExport size_t getNextQuote(const std::string& str, size_t start = 0);
61  _UtilExport bool isBetweenQuotes(const std::string& str, size_t pos);
62 
65 
68 
69  _UtilExport bool isEmpty(const std::string& str);
70  _UtilExport bool isComment(const std::string& str);
71 
74 
77 
80 
81  _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2);
82  _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2, size_t len);
83 
84  _UtilExport bool hasComment(const std::string& str);
86  _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0);
87 
88  _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement);
89 
90  _UtilExport unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2);
91 
93 }
94 
95 #endif /* _StringUtils_H__ */
void uppercase(std::string *str)
Replaces each char between a and z with its uppercase equivalent.
Definition: StringUtils.cc:350
std::string BLANKSTRING
A blank string (""). Used to return a blank string by reference.
Definition: StringUtils.cc:46
#define _UtilExport
Definition: UtilPrereqs.h:60
bool hasStringBetweenQuotes(const std::string &str)
Returns true if the string contains something like &#39;..."between quotaton marks"...&#39;.
Definition: StringUtils.cc:142
size_t getNextQuote(const std::string &str, size_t start)
Returns the position of the next quotation mark in the string, starting with start.
Definition: StringUtils.cc:98
std::string addSlashes(const std::string &str)
Adds backslashes to the given string which makes special chars visible.
Definition: StringUtils.cc:260
std::string getTimestamp(void)
Get a timestamp for the current time instant.
Definition: StringUtils.cc:503
bool hasComment(const std::string &str)
Returns true if the string contains a comment, introduced by #, %, ; or //.
Definition: StringUtils.cc:413
::std::string string
Definition: gtest-port.h:756
std::string getUniqueNumberString()
Returns a string of a unique number. This function is guaranteed to never return the same string twic...
Definition: StringUtils.cc:49
std::string removeSlashes(const std::string &str)
Removes backslashes from the given string.
Definition: StringUtils.cc:297
int nocaseCmp(const std::string &s1, const std::string &s2)
Compares two strings ignoring different casing.
Definition: StringUtils.cc:367
bool isComment(const std::string &str)
Determines if a string is a comment (starts with a comment-symbol).
Definition: StringUtils.cc:219
void strip(std::string *str)
Removes all whitespaces from a string.
Definition: StringUtils.cc:55
std::string removeTrailingWhitespaces(const std::string &str)
Returns a copy of a string without trailing whitespaces.
Definition: StringUtils.cc:69
bool isBetweenQuotes(const std::string &str, size_t pos)
Returns true if pos is between two quotation marks.
Definition: StringUtils.cc:123
std::string getLowercase(const std::string &str)
Returns a copy of the given string where all chars are converted to lowercase.
Definition: StringUtils.cc:342
size_t getNextCommentPosition(const std::string &str, size_t start)
Returns the beginning of the next comment including whitespaces in front of the comment symbol...
Definition: StringUtils.cc:433
size_t replaceCharacters(std::string &str, char target, char replacement)
Replaces individual charaters.
Definition: StringUtils.cc:449
std::string stripEnclosingQuotes(const std::string &str)
Removes enclosing quotation marks if available (including whitespaces at the outside of the quotation...
Definition: StringUtils.cc:164
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Shared library macros, enums, constants and forward declarations for the util library ...
bool isEmpty(const std::string &str)
Determines if a string is empty (contains only whitespaces).
Definition: StringUtils.cc:244
void lowercase(std::string *str)
Replaces each char between A and Z with its lowercase equivalent.
Definition: StringUtils.cc:336
std::string getComment(const std::string &str)
If the string contains a comment, the comment gets returned (including the comment symbol and white s...
Definition: StringUtils.cc:419
std::string getStringBetweenQuotes(const std::string &str)
If the string contains something like &#39;..."between quotaton marks"...&#39; then &#39;between quotaton marks&#39; ...
Definition: StringUtils.cc:150
std::string stripEnclosingBraces(const std::string &str)
Removes enclosing braces &#39;{&#39; and &#39;}&#39; (the braces must be exactly on the beginning and the end of the ...
Definition: StringUtils.cc:195
std::string getUppercase(const std::string &str)
Returns a copy of the given string where all chars are converted to uppercase.
Definition: StringUtils.cc:356
unsigned int getLevenshteinDistance(const std::string &str1, const std::string &str2)
Calculates the Levenshtein distance between two strings.
Definition: StringUtils.cc:469
std::string getStripped(const std::string &str)
Returns a copy of a string without whitespaces.
Definition: StringUtils.cc:61
void vectorize(const std::string &str, char delimiter, std::vector< std::string > *output)
Splits a given string by a delimiter and stores it in an output vector. See SubString for a more soph...
Definition: StringUtils.cc:82