Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1314 runge 1
/*
2
 * string.cpp
3
 *
4
 *  Created on: Aug 04, 2009
5
 *      Author: Mattias Runge
6
 */
7
 
8
#include "string.h"
9
 
10
namespace atom {
11
namespace string_ {
12
 
13
void escape(string & in)
14
{
15
    string out;
16
 
17
    // TODO Use replace functions instead maybe?
18
    for (unsigned int n = 0; n < in.length(); n++)
19
    {
20
        switch (in[n])
21
        {
22
        case '\r':
23
            break;
24
 
25
        case '\n':
26
            out += "\\n";
27
            break;
28
 
29
        case '\'':
30
            out += "\\'";
31
            break;
32
 
33
        case '"':
34
            out += "\\\"";
35
            break;
36
 
37
        default:
38
            out += in[n];
39
            break;
40
        }
41
    }
42
 
43
    in = out;
44
}
45
 
46
void pad_right(string & in, unsigned int length, char c)
47
{
48
    while (in.length() < length)
49
    {
50
        in += c;
51
    }
52
}
53
 
54
void pad_left(string & in, unsigned int length, char c)
55
{
56
    while (in.length() < length)
57
    {
58
        in = c + in;
59
    }
60
}
61
 
62
string escape_copy(string in)
63
{
64
    escape(in);
65
    return in;
66
}
67
 
68
string pad_right_copy(string in, unsigned int length, char c)
69
{
70
    pad_right(in, length, c);
71
    return in;
72
}
73
 
74
string pad_left_copy(string in, unsigned int length, char c)
75
{
76
    pad_left(in, length, c);
77
    return in;
78
}
79
 
80
}
81
}