-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringWithNull.cpp
More file actions
121 lines (95 loc) · 2.68 KB
/
StringWithNull.cpp
File metadata and controls
121 lines (95 loc) · 2.68 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* \file StringWithNull.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
// #1
{
std::string sFileName;
sFileName.push_back('x');
sFileName.push_back('\0');
sFileName.push_back('y');
std::string sExceptedChars = "/\0";
STD_TEST(sExceptedChars.size() == 1);
size_t uiPos = sFileName.find_first_of(sExceptedChars);
if (std::string::npos == uiPos) {
std::cout << "Not found" << std::endl;
} else {
std::cout << "Found" << std::endl;
}
STD_TEST(std::string::npos == uiPos);
#if OUTPUT
Not found
#endif
}
// #2
{
std::string sFileName;
sFileName.push_back('x');
sFileName.push_back('\0');
sFileName.push_back('y');
std::string sExceptedChars;
sExceptedChars.push_back('/');
sExceptedChars.push_back('\0');
STD_TEST(sExceptedChars.size() == 2);
size_t uiPos = sFileName.find_first_of(sExceptedChars);
if (std::string::npos == uiPos) {
std::cout << "Not found" << std::endl;
} else {
std::cout << "Found" << std::endl;
}
STD_TEST(std::string::npos != uiPos)
#if OUTPUT
Found
#endif
}
// #3
{
std::string sFileName;
sFileName.push_back('x');
sFileName.push_back('\0');
sFileName.push_back('y');
char szExceptedChars[] = {'/', '\0', '\0'};
size_t uiPos = sFileName.find_first_of(szExceptedChars);
if (std::string::npos == uiPos) {
std::cout << "Not found" << std::endl;
} else {
std::cout << "Found" << std::endl;
}
STD_TEST(std::string::npos == uiPos);
#if OUTPUT
Not found
#endif
}
// #4
{
std::string sFileName;
sFileName.push_back('x');
sFileName.push_back('\0');
sFileName.push_back('y');
char chExceptedChars = '\0';
size_t uiPos = sFileName.find_first_of(chExceptedChars);
if (std::string::npos == uiPos) {
std::cout << "Not found" << std::endl;
} else {
std::cout << "Found" << std::endl;
}
STD_TEST(std::string::npos != uiPos);
#if OUTPUT
Found
#endif
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
Not found
Found
Not found
Found
#endif