1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include <apt-pkg/strutl.h>
#include "assert.h"
int main(int argc,char *argv[])
{
std::string input, output, expected;
// no input
input = "foobar";
expected = "foobar";
output = DeEscapeString(input);
equals(output, expected);
// hex and octal
input = "foo\\040bar\\x0abaz";
expected = "foo bar\nbaz";
output = DeEscapeString(input);
equals(output, expected);
// at the end
input = "foo\\040";
expected = "foo ";
output = DeEscapeString(input);
equals(output, expected);
// double escape
input = "foo\\\\ x";
expected = "foo\\ x";
output = DeEscapeString(input);
equals(output, expected);
// double escape at the end
input = "\\\\foo\\\\";
expected = "\\foo\\";
output = DeEscapeString(input);
equals(output, expected);
// the string that we actually need it for
input = "/media/Ubuntu\\04011.04\\040amd64";
expected = "/media/Ubuntu 11.04 amd64";
output = DeEscapeString(input);
equals(output, expected);
// Split
input = "status: libnet1:amd64: unpacked";
vector<std::string> result = StringSplit(input, ": ");
equals(result[0], "status");
equals(result[1], "libnet1:amd64");
equals(result[2], "unpacked");
equals(result.size(), 3);
input = "status: libnet1:amd64: unpacked";
result = StringSplit(input, "xxx");
equals(result[0], input);
equals(result.size(), 1);
input = "status: libnet1:amd64: unpacked";
result = StringSplit(input, "");
equals(result.size(), 0);
input = "x:y:z";
result = StringSplit(input, ":", 2);
equals(result.size(), 2);
equals(result[0], "x");
equals(result[1], "y:z");
input = "abc";
result = StringSplit(input, "");
equals(result.size(), 0);
return 0;
}
|