1 /******************************************************************************* 2 * tlx/string/trim.hpp 3 * 4 * Part of tlx - http://panthema.net/tlx 5 * 6 * Copyright (C) 2007-2017 Timo Bingmann <tb@panthema.net> 7 * 8 * All rights reserved. Published under the Boost Software License, Version 1.0 9 ******************************************************************************/ 10 11 #ifndef TLX_STRING_TRIM_HEADER 12 #define TLX_STRING_TRIM_HEADER 13 14 #include <string> 15 16 namespace tlx { 17 18 //! \addtogroup tlx_string 19 //! \{ 20 //! \name Trim 21 //! \{ 22 23 /******************************************************************************/ 24 25 /*! 26 * Trims the given string in-place on the left and right. Removes all 27 * characters in the given drop array, which defaults to " \r\n\t". 28 * 29 * \param str string to process 30 * \return reference to the modified string 31 */ 32 std::string& trim(std::string* str); 33 34 /*! 35 * Trims the given string in-place on the left and right. Removes all 36 * characters in the given drop array, which defaults to " \r\n\t". 37 * 38 * \param str string to process 39 * \param drop remove these characters 40 * \return reference to the modified string 41 */ 42 std::string& trim(std::string* str, const char* drop); 43 44 /*! 45 * Trims the given string in-place on the left and right. Removes all 46 * characters in the given drop array, which defaults to " \r\n\t". 47 * 48 * \param str string to process 49 * \param drop remove these characters 50 * \return reference to the modified string 51 */ 52 std::string& trim(std::string* str, const std::string& drop); 53 54 /*! 55 * Trims the given string in-place on the left and right. Removes all 56 * characters in the given drop array, which defaults to " \r\n\t". 57 * 58 * \param str string to process 59 * \return reference to the modified string 60 */ 61 std::string trim(const std::string& str); 62 63 /*! 64 * Trims the given string in-place on the left and right. Removes all 65 * characters in the given drop array, which defaults to " \r\n\t". 66 * 67 * \param str string to process 68 * \param drop remove these characters 69 * \return reference to the modified string 70 */ 71 std::string trim(const std::string& str, const char* drop); 72 73 /*! 74 * Trims the given string in-place on the left and right. Removes all 75 * characters in the given drop array, which defaults to " \r\n\t". 76 * 77 * \param str string to process 78 * \param drop remove these characters 79 * \return reference to the modified string 80 */ 81 std::string trim(const std::string& str, const std::string& drop); 82 83 /******************************************************************************/ 84 85 /*! 86 * Trims the given string in-place only on the right. Removes all characters in 87 * the given drop array, which defaults to " \r\n\t". 88 * 89 * \param str string to process 90 * \return reference to the modified string 91 */ 92 std::string& trim_right(std::string* str); 93 94 /*! 95 * Trims the given string in-place only on the right. Removes all characters in 96 * the given drop array, which defaults to " \r\n\t". 97 * 98 * \param str string to process 99 * \param drop remove these characters 100 * \return reference to the modified string 101 */ 102 std::string& trim_right(std::string* str, const char* drop); 103 104 /*! 105 * Trims the given string in-place only on the right. Removes all characters in 106 * the given drop array, which defaults to " \r\n\t". 107 * 108 * \param str string to process 109 * \param drop remove these characters 110 * \return reference to the modified string 111 */ 112 std::string& trim_right(std::string* str, const std::string& drop); 113 114 /*! 115 * Trims the given string only on the right. Removes all characters in the 116 * given drop array, which defaults to " \r\n\t". Returns a copy of the string. 117 * 118 * \param str string to process 119 * \return new trimmed string 120 */ 121 std::string trim_right(const std::string& str); 122 123 /*! 124 * Trims the given string only on the right. Removes all characters in the 125 * given drop array, which defaults to " \r\n\t". Returns a copy of the string. 126 * 127 * \param str string to process 128 * \param drop remove these characters 129 * \return new trimmed string 130 */ 131 std::string trim_right(const std::string& str, const char* drop); 132 133 /*! 134 * Trims the given string only on the right. Removes all characters in the 135 * given drop array, which defaults to " \r\n\t". Returns a copy of the string. 136 * 137 * \param str string to process 138 * \param drop remove these characters 139 * \return new trimmed string 140 */ 141 std::string trim_right(const std::string& str, const std::string& drop); 142 143 /******************************************************************************/ 144 145 /*! 146 * Trims the given string in-place only on the left. Removes all characters in 147 * the given drop array, which defaults to " \r\n\t". 148 * 149 * \param str string to process 150 * \return reference to the modified string 151 */ 152 std::string& trim_left(std::string* str); 153 154 /*! 155 * Trims the given string in-place only on the left. Removes all characters in 156 * the given drop array, which defaults to " \r\n\t". 157 * 158 * \param str string to process 159 * \param drop remove these characters 160 * \return reference to the modified string 161 */ 162 std::string& trim_left(std::string* str, const char* drop); 163 164 /*! 165 * Trims the given string in-place only on the left. Removes all characters in 166 * the given drop array, which defaults to " \r\n\t". 167 * 168 * \param str string to process 169 * \param drop remove these characters 170 * \return reference to the modified string 171 */ 172 std::string& trim_left(std::string* str, const std::string& drop); 173 174 /*! 175 * Trims the given string only on the left. Removes all characters in the given 176 * drop array, which defaults to " \r\n\t". Returns a copy of the string. 177 * 178 * \param str string to process 179 * \return new trimmed string 180 */ 181 std::string trim_left(const std::string& str); 182 183 /*! 184 * Trims the given string only on the left. Removes all characters in the given 185 * drop array, which defaults to " \r\n\t". Returns a copy of the string. 186 * 187 * \param str string to process 188 * \param drop remove these characters 189 * \return new trimmed string 190 */ 191 std::string trim_left(const std::string& str, const char* drop); 192 193 /*! 194 * Trims the given string only on the left. Removes all characters in the given 195 * drop array, which defaults to " \r\n\t". Returns a copy of the string. 196 * 197 * \param str string to process 198 * \param drop remove these characters 199 * \return new trimmed string 200 */ 201 std::string trim_left(const std::string& str, const std::string& drop); 202 203 //! \} 204 //! \} 205 206 } // namespace tlx 207 208 #endif // !TLX_STRING_TRIM_HEADER 209 210 /******************************************************************************/ 211