monotone

monotone Mtn Source Tree

Root/simplestring_xform.hh

1#ifndef __SIMPLESTRING_XFORM_HH__
2#define __SIMPLESTRING_XFORM_HH__
3
4#include <vector>
5
6std::string uppercase(std::string const & in);
7std::string lowercase(std::string const & in);
8
9void split_into_lines(std::string const & in,
10 std::vector<std::string> & out);
11
12void split_into_lines(std::string const & in,
13 std::string const & encoding,
14 std::vector<std::string> & out);
15
16void join_lines(std::vector<std::string> const & in,
17 std::string & out,
18 std::string const & linesep);
19
20void join_lines(std::vector<std::string> const & in,
21 std::string & out);
22
23template< class T >
24std::vector< T > split_into_words(T const & in)
25{
26 std::string const & instr = in();
27 std::vector< T > out;
28
29 std::string::size_type begin = 0;
30 std::string::size_type end = instr.find_first_of(" ", begin);
31
32 while (end != std::string::npos && end >= begin)
33 {
34 out.push_back(T(instr.substr(begin, end-begin)));
35 begin = end + 1;
36 if (begin >= instr.size())
37 break;
38 end = instr.find_first_of(" ", begin);
39 }
40 if (begin < instr.size())
41 out.push_back(T(instr.substr(begin, instr.size() - begin)));
42
43 return out;
44}
45
46template< class Container >
47typename Container::value_type join_words(Container const & in, std::string const & sep = " ")
48{
49 std::string str;
50 typename Container::const_iterator iter = in.begin();
51 while (iter != in.end())
52 {
53 str += (*iter)();
54 iter++;
55 if (iter != in.end())
56 str += sep;
57 }
58 typedef typename Container::value_type result_type;
59 return result_type(str);
60}
61
62void prefix_lines_with(std::string const & prefix,
63 std::string const & lines,
64 std::string & out);
65
66// append after removing all whitespace
67void append_without_ws(std::string & appendto, std::string const & s);
68
69// remove all whitespace
70std::string remove_ws(std::string const & s);
71
72// remove leading and trailing whitespace
73std::string trim_ws(std::string const & s);
74
75// Local Variables:
76// mode: C++
77// fill-column: 76
78// c-file-style: "gnu"
79// indent-tabs-mode: nil
80// End:
81// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
82
83#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status