monotone

monotone Mtn Source Tree

Root/simplestring_xform.hh

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

Archive Download this file

Branches

Tags

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