Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trim.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/trim.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2007-2017 Timo Bingmann <[email protected]>
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 
21 /******************************************************************************/
22 
23 /*!
24  * Trims the given string in-place on the left and right. Removes all
25  * characters in the given drop array, which defaults to " ".
26  *
27  * \param str string to process
28  * \param drop remove these characters
29  * \return reference to the modified string
30  */
31 std::string& trim(std::string* str, const char* drop = " \r\n\t");
32 
33 /*!
34  * Trims the given string in-place on the left and right. Removes all
35  * characters in the given drop array, which defaults to " ".
36  *
37  * \param str string to process
38  * \param drop remove these characters
39  * \return reference to the modified string
40  */
41 std::string& trim(std::string* str, const std::string& drop);
42 
43 /*!
44  * Trims the given string in-place on the left and right. Removes all
45  * characters in the given drop array, which defaults to " ".
46  *
47  * \param str string to process
48  * \param drop remove these characters
49  * \return reference to the modified string
50  */
51 std::string trim(const std::string& str,
52  const char* drop = " \r\n\t");
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 " ".
57  *
58  * \param str string to process
59  * \param drop remove these characters
60  * \return reference to the modified string
61  */
62 std::string trim(const std::string& str, const std::string& drop);
63 
64 /******************************************************************************/
65 
66 /*!
67  * Trims the given string in-place only on the right. Removes all characters in
68  * the given drop array, which defaults to " ".
69  *
70  * \param str string to process
71  * \param drop remove these characters
72  * \return reference to the modified string
73  */
74 std::string& trim_right(std::string* str, const char* drop = " \r\n\t");
75 
76 /*!
77  * Trims the given string in-place only on the right. Removes all characters in
78  * the given drop array, which defaults to " ".
79  *
80  * \param str string to process
81  * \param drop remove these characters
82  * \return reference to the modified string
83  */
84 std::string& trim_right(std::string* str, const std::string& drop);
85 
86 /*!
87  * Trims the given string only on the right. Removes all characters in the
88  * given drop array, which defaults to " ". Returns a copy of the string.
89  *
90  * \param str string to process
91  * \param drop remove these characters
92  * \return new trimmed string
93  */
95  const char* drop = " \r\n\t");
96 
97 /*!
98  * Trims the given string only on the right. Removes all characters in the
99  * given drop array, which defaults to " ". Returns a copy of the string.
100  *
101  * \param str string to process
102  * \param drop remove these characters
103  * \return new trimmed string
104  */
105 std::string trim_right(const std::string& str, const std::string& drop);
106 
107 /******************************************************************************/
108 
109 /*!
110  * Trims the given string in-place only on the left. Removes all characters in
111  * the given drop array, which defaults to " ".
112  *
113  * \param str string to process
114  * \param drop remove these characters
115  * \return reference to the modified string
116  */
117 std::string& trim_left(std::string* str, const char* drop = " \r\n\t");
118 
119 /*!
120  * Trims the given string in-place only on the left. Removes all characters in
121  * the given drop array, which defaults to " ".
122  *
123  * \param str string to process
124  * \param drop remove these characters
125  * \return reference to the modified string
126  */
127 std::string& trim_left(std::string* str, const std::string& drop);
128 
129 /*!
130  * Trims the given string only on the left. Removes all characters in the given
131  * drop array, which defaults to " ". Returns a copy of the string.
132  *
133  * \param str string to process
134  * \param drop remove these characters
135  * \return new trimmed string
136  */
138  const char* drop = " \r\n\t");
139 
140 /*!
141  * Trims the given string only on the left. Removes all characters in the given
142  * drop array, which defaults to " ". Returns a copy of the string.
143  *
144  * \param str string to process
145  * \param drop remove these characters
146  * \return new trimmed string
147  */
148 std::string trim_left(const std::string& str, const std::string& drop);
149 
150 //! \}
151 
152 } // namespace tlx
153 
154 #endif // !TLX_STRING_TRIM_HEADER
155 
156 /******************************************************************************/
std::string & trim(std::string *str, const char *drop)
Trims the given string in-place on the left and right.
Definition: trim.cpp:20
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
std::string & trim_right(std::string *str, const char *drop)
Trims the given string in-place only on the right.
Definition: trim.cpp:86
std::string & trim_left(std::string *str, const char *drop)
Trims the given string in-place only on the left.
Definition: trim.cpp:112