Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:43:50

0001 #ifndef STRING_UTILS_H
0002 #define STRING_UTILS_H
0003 
0004 /**

0005  * @file StringUtils.h

0006  * @author Bryan BERTHOU

0007  * @date April 04, 2009

0008  * @version 0.1

0009  */
0010 
0011 #include <stddef.h>
0012 #include <ctime>
0013 #include <string>
0014 #include <utility>
0015 #include <vector>
0016 
0017 //TODO uniformiser le fichier, corriger les parametres des fonctions (const, &, ...) refaire la documentation

0018 
0019 namespace ElemUtils {
0020 
0021 /**

0022  * @class StringUtils

0023  *

0024  * @brief Manipulations et traitements sur les chaines de caracteres

0025  */
0026 class StringUtils {
0027 
0028 public:
0029 
0030     static std::string EMPTY;
0031 
0032     /**

0033      * @fn static bool isEmpty(const std::string & str)

0034      * @brief Test si la chaine de caracteres cible est NULL ou vide ""

0035      * @param str : chaine de caracteres a tester

0036      * @return bool

0037      */
0038     static bool isEmpty(const std::string & str);
0039 
0040     /*!

0041      * \fn static bool equals(const std::string & str, const std::string & str2)

0042      * \brief Applique une comparaison entre la chaine 1 et 2 en tenant compte de la casse

0043      * \param _chaine1 : chaine de caracteres a comparer

0044      * \param _chaine2 : chaine de caracteres a comparer

0045      * \return bool : true si les deux chaines de caracteres sont egales

0046      */
0047     static bool equals(const std::string & str, const std::string & str2);
0048 
0049     /*!

0050      * \fn static bool equalsIgnoreCase( std::string _chaine1, std::string _chaine2, bool toUpperCase )

0051      * \brief Applique une comparaison entre la chaine 1 et 2 sans tenir compte de la casse

0052      * \param _chaine1 : chaine de caracteres a comparer

0053      * \param _chaine2 : chaine de caracteres a comparer

0054      * \return bool : true si les deux chaines de caracteres sont egales

0055      */
0056     static bool equalsIgnoreCase(const std::string &chaine,
0057             const std::string &chaine2, const bool &toUpperCase = true);
0058 
0059     static bool contains(const std::string & str,
0060             const std::string & searchString);
0061 
0062     static bool containsIgnoreCase(std::string* chaine,
0063             std::string* searchString, bool toUpperCase);
0064 
0065     static void replaceAll(std::string & str, const std::string & searchString,
0066             const std::string & replaceString);
0067 
0068     static void replaceAllIgnoreCase(std::string* chaine,
0069             std::string* searchString, std::string* replaceString,
0070             bool toUpperCase);
0071 
0072     // Remove leading and trailing spaces from a string

0073     static void trim(std::string &str, const std::string& whitespace = " \t");
0074 
0075     // Remove all white spaces from a string

0076     static void trimAll(std::string &str, const std::string& whitespace = " \t");
0077 
0078     static unsigned int count(std::string str,
0079             const std::string & searchString);
0080 
0081     /*!

0082      * \fn static std::vector<std::string> stringToVector( std::string _chaine, char splitCharacter )

0083      * \brief Transforme une chaine de caracteres en un vector de string

0084      * \param _chaine : chaine a splitter

0085      * \param splitCharacter : caractere de split

0086      * \return std::vector<std::string>

0087      */
0088     static std::vector<std::string> split(const std::string &chaine,
0089             char splitCharacter);
0090 
0091     static std::vector<std::string> split(const std::string &chaine,
0092             const std::string & splitSymbols);
0093 
0094     /*!

0095      * \fn static std::string vectorToString( std::vector<std::string> vector )

0096      * \brief Transforme un vector de string en une chaine de caracteres

0097      * \param vector : vector a transformer en chaine de caracteres

0098      * \return std::string

0099      */
0100     static std::string vectorToString(std::vector<std::string>* vector);
0101 
0102     static void to_upperCase(std::string &chaine);
0103 
0104     static void to_lowerCase(std::string* chaine);
0105 
0106     static std::pair<std::string, std::vector<char> > fromStringToArrayOfChar(
0107             const std::string &string);
0108 
0109     static std::string removeAfterLast(const std::string &chaine,
0110             const char lastCharacter);
0111 
0112     /**

0113      * Find first occurrence of the pattern in the string and return index position on the string where the last character is matching pattern.

0114      *

0115      * @param file

0116      * @param pattern

0117      * @param startIndex

0118      * @return

0119      */
0120     static size_t findFirstJustAfter(const std::string &file,
0121             const std::string &pattern, const size_t startIndex = 0);
0122 
0123     /**

0124      * Find first occurrence of the pattern in the string and return index position on the string where pattern is starting.

0125      *

0126      * @param file

0127      * @param pattern

0128      * @param startIndex

0129      * @return

0130      */
0131     static size_t findFirst(const std::string &file, const std::string &pattern,
0132             const size_t startIndex = 0);
0133 
0134     static std::string formatDate(const time_t &time,
0135             const std::string &format);
0136 };
0137 
0138 } // namespace ElemUtils

0139 
0140 #endif /* STRING_UTILS_H */