6 // Written by Bernie Bright, started 1998
8 // Copyright (C) 1998 Bernie Bright - bbright@bigpond.net.au
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <simgear/compiler.h>
36 typedef std::vector < std::string > string_list;
42 // * atof() wrapper for "string" type
45 // atof( const string& str )
47 // return ::atof( str.c_str() );
51 // * atoi() wrapper for "string" type
54 // atoi( const string& str )
56 // return ::atoi( str.c_str() );
60 * Strip leading and/or trailing whitespace from s.
61 * @param s String to strip.
62 * @return The stripped string.
64 std::string lstrip( const std::string& s );
65 std::string rstrip( const std::string& s );
66 std::string strip( const std::string& s );
69 * Right-padding of a string to a given length
70 * @param s String to pad
71 * @param length The total length of the resulting string
72 * @param c The character to pad with
73 * @return The padded string
75 std::string rpad( const std::string & s, size_t length, char c );
78 * Left-padding of a string to a given length
79 * @param s String to pad
80 * @param length The total length of the resulting string
81 * @param c The character to pad with
82 * @return The padded string
84 std::string lpad( const std::string & s, size_t length, char c );
87 * Split a string into a words using 'sep' as the delimiter string.
88 * Produces a result similar to the perl and python functions of the
91 * @param s The string to split into words,
92 * @param sep Word delimiters. If not specified then any whitespace is a separator,
93 * @param maxsplit If given, splits at no more than maxsplit places,
94 * resulting in at most maxsplit+1 words.
95 * @return Array of words.
98 split( const std::string& s,
103 * create a single string by joining the elements of a list with
106 std::string join(const string_list& l, const std::string& joinWith = "");
109 * Test if a string starts with a string
111 * @param s The string to be tested
112 * @param substr The string to test
113 * @return True, if s starts with substr, False otherwise
115 bool starts_with( const std::string & s, const std::string & substr );
118 * Test if a string ends with a string
120 * @param s The string to be tested
121 * @param substr The string to test
122 * @return True, if s ends with substr, False otherwise
124 bool ends_with( const std::string & s, const std::string & substr );
127 * Strip all leading/trailing whitespace, and transform all interal
128 * whitespace into a single ' ' character - i.e newlines/carriage returns/
129 * tabs/multiple spaces will be condensed.
131 std::string simplify(const std::string& s);
134 * convert a string representing a decimal number, to an int
136 int to_int(const std::string& s, int base = 10);
139 * Like strcmp(), but for dotted versions strings NN.NN.NN
140 * any number of terms are support.
141 * @return 0 if versions match, -ve number if v1 is lower, +ve if v1
144 int compare_versions(const std::string& v1, const std::string& v2);
145 } // end namespace strutils
146 } // end namespace simgear