45 template<
typename StreamType,
typename StringType>
51 if ( str[ str.size() - 1 ] ==
typename StringType::value_type(
'\r') )
52 str.erase( str.size() - 1 );
63 template<
typename StringType>
65 const typename StringType::value_type*
const s )
67 typename StringType::size_type p = str.find_first_not_of(s);
69 if (p != StringType::npos)
79 template<
typename StringType>
81 const typename StringType::value_type*
const s )
83 typename StringType::size_type p = str.find_last_not_of(s);
85 if (p != StringType::npos)
86 str = str.substr( 0, p+1 );
95 template<
typename StringType>
97 const typename StringType::value_type*
const s )
99 typename StringType::size_type
first = str.find_first_not_of(s);
100 typename StringType::size_type last = str.find_last_not_of(s);
102 if (first != StringType::npos)
103 str = str.substr( first, last - first + 1 );
119 template<
typename StringType>
121 const typename StringType::value_type*
const s )
123 typedef typename StringType::size_type size_type;
129 first = str.find_first_of(s, first);
131 if ( first != StringType::npos )
133 size_type last = str.find_first_not_of(str[first], first+1);
135 if ( last == StringType::npos )
136 str = str.substr(0, first+1);
137 else if ( last - first > 1 )
138 str = str.substr(0, first+1) + str.substr(last);
143 while ( (first != StringType::npos) && (first != str.length()) );
165 template<
typename StringType>
167 ( StringType& str,
const StringType& e1,
const StringType& e2 )
171 ( str.begin(), str.end(), e1.begin(), e1.end(), e2.begin(), e2.end() );
179 template<
typename T,
typename StringType>
182 std::basic_istringstream<
typename StringType::value_type,
183 typename StringType::traits_type,
184 typename StringType::allocator_type > iss(str);
203 template<
typename Sequence>
205 ( Sequence& sequence,
const typename Sequence::value_type& str,
206 const typename Sequence::value_type::value_type sep )
208 split(sequence, str.begin(), str.end(), sep);
220 template<
typename Sequence>
222 ( Sequence& sequence,
typename Sequence::value_type::const_iterator
first,
223 typename Sequence::value_type::const_iterator last,
224 const typename Sequence::value_type::value_type sep )
226 typedef typename Sequence::value_type string_type;
229 std::basic_istringstream<
typename string_type::value_type,
230 typename string_type::traits_type,
231 typename string_type::allocator_type > iss( string_type(first, last) );
234 *std::insert_iterator<Sequence>(sequence, sequence.end()) = line;
259 template<
typename InputIterator,
typename OutputIterator>
261 ( InputIterator first, InputIterator last, OutputIterator out )
263 typedef typename std::iterator_traits<InputIterator>::value_type char_type;
264 typedef std::basic_string<char_type> string_type;
266 const string_type oct(
"01234567");
267 const string_type hex(
"0123456789ABCDEFabcdef");
271 for ( ; first!=last; ++out )
276 case 'a': *out =
'\a'; ++first;
break;
277 case 'b': *out =
'\b'; ++first;
break;
278 case 'f': *out =
'\f'; ++first;
break;
279 case 'n': *out =
'\n'; ++first;
break;
280 case 'r': *out =
'\r'; ++first;
break;
281 case 't': *out =
'\t'; ++first;
break;
282 case 'v': *out =
'\v'; ++first;
break;
287 const InputIterator e
290 std::basic_istringstream<char_type> iss( string_type(first, e) );
291 iss >> std::oct >> v;
300 const InputIterator e
303 std::basic_istringstream<char_type> iss( string_type(first, e) );
304 iss >> std::hex >> v;
309 default: *out = *first; ++first;
314 else if ( *first ==
'\\' )
336 template<
typename StringType>
338 (
const StringType& pattern,
const StringType& text,
339 const typename StringType::value_type any_sequence,
340 const typename StringType::value_type zero_or_one,
341 const typename StringType::value_type any )
344 ( pattern.begin(), pattern.end(), text.begin(), text.end(), any_sequence,
358 template<
typename StringType>
360 (
const StringType& pattern,
const StringType& text,
361 const typename StringType::value_type any_sequence,
362 const typename StringType::value_type zero_or_one,
363 const typename StringType::value_type any )
366 ( pattern.begin(), pattern.end(), text.begin(), text.end(), any_sequence,