FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

string.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::string
00026 
00027 Description
00028     A class for handling character strings derived from std::string.
00029 
00030     Strings may contain any characters and therefore are delimited by quotes
00031     for IO : "any list of characters".
00032 
00033     Used as a base class for word and fileName.
00034 
00035 See Also
00036     Foam::findEtcFile() for information about the site/user OpenFOAM
00037     configuration directory
00038 
00039 SourceFiles
00040     string.C
00041     stringIO.C
00042 
00043 \*---------------------------------------------------------------------------*/
00044 
00045 #ifndef string_H
00046 #define string_H
00047 
00048 #include <OpenFOAM/char.H>
00049 #include <OpenFOAM/Hasher.H>
00050 
00051 #include <string>
00052 #include <cstring>
00053 #include <cstdlib>
00054 
00055 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00056 
00057 namespace Foam
00058 {
00059 
00060 // Forward declaration of classes
00061 class Istream;
00062 class Ostream;
00063 
00064 // Forward declaration of friend functions and operators
00065 class string;
00066 Istream& operator>>(Istream&, string&);
00067 Ostream& operator<<(Ostream&, const string&);
00068 Ostream& operator<<(Ostream&, const std::string&);
00069 
00070 
00071 /*---------------------------------------------------------------------------*\
00072                            Class string Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 class string
00076 :
00077     public std::string
00078 {
00079 public:
00080 
00081     // Static data members
00082 
00083         static const char* const typeName;
00084         static int debug;
00085         static const string null;
00086 
00087 
00088     //- Hashing function class, shared by all the derived classes
00089     class hash
00090     {
00091     public:
00092         hash()
00093         {}
00094 
00095         inline unsigned operator()(const string&, unsigned seed = 0) const;
00096     };
00097 
00098 
00099     // Constructors
00100 
00101         //- Construct null
00102         inline string();
00103 
00104         //- Construct from std::string
00105         inline string(const std::string&);
00106 
00107         //- Construct as copy of character array
00108         inline string(const char*);
00109 
00110         //- Construct as copy of specified number of characters
00111         inline string(const char*, const size_type);
00112 
00113         //- Construct from a single character
00114         inline string(const char);
00115 
00116         //- Construct from Istream
00117         string(Istream&);
00118 
00119 
00120     // Member Functions
00121 
00122         //- Count and return the number of a given character in the string
00123         size_type count(const char) const;
00124 
00125         //- Is this string type valid?
00126         template<class String>
00127         static inline bool valid(const string&);
00128 
00129         //- Does this string have particular meta-characters?
00130         //  The meta characters can be optionally quoted.
00131         template<class String>
00132         static inline bool meta(const string&, const char quote='\\');
00133 
00134         //- Strip invalid characters from the given string
00135         template<class String>
00136         static inline bool stripInvalid(string&);
00137 
00138         //- Return a valid String from the given string
00139         template<class String>
00140         static inline String validate(const string&);
00141 
00142         //- Return a String with quoted meta-characters from the given string
00143         template<class String>
00144         static inline string quotemeta(const string&, const char quote='\\');
00145 
00146         //- Avoid masking the normal std::string replace
00147         using std::string::replace;
00148 
00149         //- Replace first occurence of sub-string oldStr with newStr
00150         //  starting at start
00151         string& replace
00152         (
00153             const string& oldStr,
00154             const string& newStr,
00155             size_type start = 0
00156         );
00157 
00158         //- Replace all occurences of sub-string oldStr with newStr
00159         //  starting at start
00160         string& replaceAll
00161         (
00162             const string& oldStr,
00163             const string& newStr,
00164             size_type start = 0
00165         );
00166 
00167             //- Expand initial tildes and all occurences of environment variables
00168             //  Expansion includes:
00169             //  -# environment variables
00170             //     - "$VAR", "${VAR}"
00171             //  -# current directory
00172             //     - leading "./" : the current directory
00173             //  -# tilde expansion
00174             //     - leading "~/" : home directory
00175             //     - leading "~user" : home directory for specified user
00176             //     - leading "~FreeFOAM" : site/user FreeFOAM configuration directory
00177             //     - leading "~OpenFOAM" : site/user FreeFOAM configuration directory (alias for ~FreeFOAM)
00178             //
00179             //  @sa
00180             //  Foam::findEtcFile
00181             string& expand();
00182 
00183         //- Remove repeated characters returning true if string changed
00184         bool removeRepeated(const char);
00185 
00186         //- Return string with repeated characters removed
00187         string removeRepeated(const char) const;
00188 
00189         //- Remove trailing character returning true if string changed
00190         bool removeTrailing(const char);
00191 
00192         //- Return string with trailing character removed
00193         string removeTrailing(const char) const;
00194 
00195 
00196     // Member Operators
00197 
00198         //- Return the sub-string from the i-th character for @a n characters
00199         inline string operator()
00200         (
00201             const size_type i,
00202             const size_type n
00203         ) const;
00204 
00205         //- Return the sub-string from the first character for @a n characters
00206         inline string operator()
00207         (
00208             const size_type n
00209         ) const;
00210 
00211 
00212     // IOstream Operators
00213 
00214         friend Istream& operator>>(Istream&, string&);
00215         friend Ostream& operator<<(Ostream&, const string&);
00216 };
00217 
00218 
00219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00220 
00221 } // End namespace Foam
00222 
00223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00224 
00225 #include "stringI.H"
00226 
00227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00228 
00229 #endif
00230 
00231 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines