]> git.mxchange.org Git - simgear.git/blob - simgear/misc/strutils.hxx
Bernie Bright:
[simgear.git] / simgear / misc / strutils.hxx
1 /**
2  * \file strutils.hxx
3  * String utilities.
4  */
5
6 // Written by Bernie Bright, started 1998
7 //
8 // Copyright (C) 1998  Bernie Bright - bbright@bigpond.net.au
9 //
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.
14 //
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.
19 //
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA  02111-1307, USA.
24 //
25 // $Id$
26
27
28 #ifndef STRUTILS_H
29 #define STRUTILS_H
30
31 #include <simgear/compiler.h>
32
33 #include STL_STRING
34
35 #include <vector>
36 SG_USING_STD(vector);
37
38 #ifdef SG_HAVE_STD_INCLUDES
39 #  include <cstdlib>
40 #else
41 #  include <stdlib.h>
42 #endif
43
44 SG_USING_STD(string);
45
46 namespace simgear {
47     namespace strutils {
48
49 //      /** 
50 //       * atof() wrapper for "string" type
51 //       */
52 //      inline double
53 //      atof( const string& str )
54 //      {
55 //          return ::atof( str.c_str() );
56 //      }
57
58 //      /**
59 //       * atoi() wrapper for "string" type
60 //       */
61 //      inline int
62 //      atoi( const string& str )
63 //      {
64 //          return ::atoi( str.c_str() );
65 //      }
66
67         /**
68          * Strip leading and/or trailing whitespace from s.
69          * @param s String to strip.
70          * @return The stripped string.
71          */
72         string lstrip( const string& s );
73         string rstrip( const string& s );
74         string strip( const string& s );
75
76         /**
77          * Split a string into a words using 'sep' as the delimiter string.
78          * Produces a result similar to the perl and python functions of the
79          * same name.
80          * 
81          * @param s The string to split into words,
82          * @param sep Word delimiters.  If not specified then any whitespace is a separator,
83          * @param maxsplit If given, splits at no more than maxsplit places,
84          * resulting in at most maxsplit+1 words.
85          * @return Array of words.
86          */
87         vector<string>
88         split( const string& s,
89                const char* sep = 0,
90                int maxsplit = 0 );
91
92     } // end namespace strutils
93 } // end namespace simgear
94
95 #endif // STRUTILS_H
96