Main MRPT website > C++ reference
MRPT logo
string_utils.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef  MRPT_STRING_UTILS_H
00029 #define  MRPT_STRING_UTILS_H
00030 
00031 #include <mrpt/utils/utils_defs.h>
00032 
00033 namespace mrpt
00034 {
00035         namespace system
00036         {
00037                 /** \addtogroup string_manage String management and utilities
00038                   * \ingroup mrpt_base_grp
00039                   * @{ */
00040 
00041                 /** An OS-independent method for tokenizing a string.
00042                   * The extra parameter "context" must be a pointer to a "char*" variable, which needs no initialization and is used to save information between calls to strtok.
00043                   * \sa system::tokenize
00044                   */
00045                 char BASE_IMPEXP  *strtok( char *str, const char *strDelimit, char **context ) MRPT_NO_THROWS;
00046 
00047                 /** Tokenizes a string according to a set of delimiting characters.
00048                   * Example:
00049                   * \code
00050                   std::vector<std::string>      tokens;
00051                   tokenize( " - Pepe-Er  Muo"," -",tokens);
00052                   * \endcode
00053                   *
00054                   *  Will generate 3 tokens:
00055                   *             - "Pepe"
00056                   *             - "Er"
00057                   *             - "Muo"
00058                   */
00059                 void  BASE_IMPEXP tokenize(
00060                         const std::string                       &inString,
00061                         const std::string                       &inDelimiters,
00062                         std::deque<std::string>         &outTokens ) MRPT_NO_THROWS;
00063 
00064                 /** Tokenizes a string according to a set of delimiting characters.
00065                   * Example:
00066                   * \code
00067                   std::vector<std::string>      tokens;
00068                   tokenize( " - Pepe-Er  Muo"," -",tokens);
00069                   * \endcode
00070                   *
00071                   *  Will generate 3 tokens:
00072                   *             - "Pepe"
00073                   *             - "Er"
00074                   *             - "Muo"
00075                   */
00076                 void BASE_IMPEXP  tokenize(
00077                         const std::string                       &inString,
00078                         const std::string                       &inDelimiters,
00079                         std::vector<std::string>                &outTokens ) MRPT_NO_THROWS;
00080 
00081                 /**  Removes leading and trailing spaces */
00082                 std::string BASE_IMPEXP trim(const std::string &str);
00083 
00084                 /** Returns a lower-case version of a string.
00085                   * \sa lowerCase  */
00086                 std::string  BASE_IMPEXP upperCase(const std::string& str);
00087 
00088                 /** Returns an upper-case version of a string.
00089                   * \sa upperCase  */
00090                 std::string  BASE_IMPEXP lowerCase(const std::string& str);
00091 
00092                 /** Decodes a UTF-8 string into an UNICODE string.
00093                   *  See http://en.wikipedia.org/wiki/UTF-8  and http://www.codeguru.com/cpp/misc/misc/multi-lingualsupport/article.php/c10451/.
00094                   */
00095                 void BASE_IMPEXP decodeUTF8( const std::string &strUTF8, vector_word &out_uniStr );
00096 
00097                 /** Encodes a 2-bytes UNICODE string into a UTF-8 string.
00098                   *  See http://en.wikipedia.org/wiki/UTF-8 and http://www.codeguru.com/cpp/misc/misc/multi-lingualsupport/article.php/c10451/.
00099                   */
00100         void BASE_IMPEXP encodeUTF8( const vector_word &input, std::string &output );
00101 
00102                 /** Encode a sequence of bytes as a string in base-64.
00103                   * \sa decodeBase64  */
00104                 void BASE_IMPEXP encodeBase64( const vector_byte &inputData,  std::string &outString );
00105 
00106                 /** Decode a base-64 string into the original sequence of bytes.
00107                   * \sa encodeBase64
00108                   * \return false on invalid base-64 string passed as input, true on success.
00109                   */
00110                 bool BASE_IMPEXP decodeBase64( const std::string &inString, vector_byte &outData );
00111 
00112                 /** This function implements formatting with the appropriate SI metric unit prefix: 1e-12->'p', 1e-9->'n', 1e-6->'u', 1e-3->'m', 1->'', 1e3->'K', 1e6->'M', 1e9->'G', 1e12->'T'
00113                  * \sa intervalFormat */
00114                 std::string BASE_IMPEXP unitsFormat(const double val,int nDecimalDigits=2, bool middle_space=true);
00115 
00116                 /** Enlarge the string with spaces up to the given length. */
00117                 std::string BASE_IMPEXP rightPad(const std::string &str, const size_t total_len, bool truncate_if_larger = false);
00118 
00119                 /** Return true if the two strings are equal (case sensitive)  \sa strCmpI  */
00120                 bool BASE_IMPEXP strCmp(const std::string &s1, const std::string &s2);
00121 
00122                 /** Return true if the two strings are equal (case insensitive)  \sa strCmp */
00123                 bool BASE_IMPEXP strCmpI(const std::string &s1, const std::string &s2);
00124 
00125                 /** Return true if "str" starts with "subStr" (case sensitive)  \sa strStartsI  */
00126                 bool BASE_IMPEXP strStarts(const std::string &str, const std::string &subStr);
00127 
00128                 /** Return true if "str" starts with "subStr" (case insensitive)  \sa strStarts */
00129                 bool BASE_IMPEXP strStartsI(const std::string &str, const std::string &subStr);
00130 
00131                 /** @} */
00132         } // End of namespace
00133 } // End of namespace
00134 
00135 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011