stringManipulation.h

Go to the documentation of this file.
00001 
00015 #ifndef _DLR_STRINGMANIPULATION_H_
00016 #define _DLR_STRINGMANIPULATION_H_
00017 
00018 #include <iostream>
00019 #include <sstream>
00020 #include <string>
00021 #include <vector>
00022 #include <dlrCommon/exception.h>
00023 #include <dlrCommon/tags.h>
00024 #include <dlrUtilities/exception.h>
00025 
00026 namespace dlr {
00027 
00028   namespace utilities {
00029     
00054     std::string
00055     cleanString(const std::string& inputString,
00056                 const std::string& 
00057                 specialCharacters="\"~#$&*()\\|[]{};'`<>/?",
00058                 char quoteCharacter='\\',
00059                 bool alreadyQuoted=false);
00060   
00061 
00077     template <class Type>
00078     Type
00079     convertString(const std::string& inputString);
00080 
00081   
00101     template <class Type>
00102     inline Type
00103     convertString(const std::string& inputString, type_tag<Type>);
00104 
00105   
00125     std::string
00126     joinString(const std::vector<std::string>& inputStringVector,
00127                const std::string& separator="");
00128   
00129 
00144     std::string
00145     lowerCaseString(const std::string& inputString);
00146   
00147 
00171     std::string
00172     replaceString(const std::string& inputString,
00173                   const std::string& target,
00174                   const std::string& replacement);
00175 
00176 
00233     std::vector<std::string>
00234     splitString(const std::string& inputString,
00235                 const std::string& delimiter,
00236                 bool includeNullStrings=false,
00237                 size_t maxSplit=0);
00238 
00239   
00253     std::string
00254     stripString(const std::string& inputString,
00255                 const std::string& whiteSpace=" \t\n");
00256 
00257 
00272     std::string
00273     upperCaseString(const std::string& inputString);
00274 
00275 
00321     std::string
00322     wrapString(const std::string& inputString,
00323                const std::string& fillPrefix="",
00324                size_t width=78,
00325                const std::string& whitespace=" \t\n",
00326                const std::string& eolString="\n");
00327 
00328 
00354     inline std::string
00355     wrapString(const std::string& inputString,
00356                size_t width,
00357                const std::string& whitespace=" \t\n",
00358                const std::string& eolString="\n") {
00359       return wrapString(inputString, "", width, whitespace, eolString);
00360     }
00361 
00362   } // namespace utilities
00363   
00364 } // namespace dlr
00365 
00366 
00367 /* ******************************************************************
00368  * Declarations to maintain compatibility with legacy code.
00369  * ***************************************************************** */
00370 
00371 namespace dlr {
00372 
00373   using utilities::cleanString;
00374   using utilities::convertString;
00375   using utilities::joinString;
00376   using utilities::lowerCaseString;
00377   using utilities::replaceString;
00378   using utilities::splitString;
00379   using utilities::stripString;
00380   using utilities::upperCaseString;
00381   using utilities::wrapString;
00382 
00383 } // namespace dlr
00384 
00385 
00386 /* ******************************************************************
00387  * Definitions of inline and template functions.
00388  * ***************************************************************** */
00389 
00390 namespace dlr {
00391 
00392   namespace utilities {
00393     
00394     // Converts the string inputString to Type.
00395     template <class Type>
00396     Type
00397     convertString(const std::string& inputString)
00398     {
00399       Type returnValue;
00400       std::istringstream inputStream(inputString);
00401       inputStream >> returnValue;
00402       if(!inputStream) {
00403         std::ostringstream message;
00404         message << "Can't convert malformed input string: " << inputString
00405                 << std::endl;
00406         DLR_THROW(ConversionException, "convertString()", message.str().c_str());
00407       }
00408       return returnValue;
00409     }
00410 
00411   
00412     // Converts the string inputString to Type.
00413     template <class Type>
00414     inline Type
00415     convertString(const std::string& inputString, type_tag<Type>)
00416     {
00417       return convertString<Type>(inputString);
00418     }
00419 
00420   } // namespace utilities
00421   
00422 } // namespace dlr
00423 
00424 #endif // #ifndef _DLR_STRINGMANIPULATION_H_

Generated on Mon Jul 9 20:34:03 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2