Skip to content

Commit 5f2a04f

Browse files
[tool] fix the String tests
1 parent 79af5df commit 5f2a04f

File tree

6 files changed

+39
-41
lines changed

6 files changed

+39
-41
lines changed

src/examples/FileIo/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ include_directories(../../framework)
44

55
add_executable(FileIo main.cxx driver.cxx)
66

7-
# target_include_directories (cpp-net-framework PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
87
target_link_libraries (cpp-net-framework)
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
cmake_minimum_required (VERSION 2.8)
22

3-
#get_cmake_property(_variableNames VARIABLES)
4-
#foreach (_variableName ${_variableNames})
5-
# message(STATUS "${_variableName}=${${_variableName}}")
6-
#endforeach()
7-
83
include_directories(../../framework)
94

105
add_executable(GTest2Html
@@ -17,5 +12,4 @@ set (DEST ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE_INIT})
1712

1813
file(COPY gtest_out.txt DESTINATION ${DEST})
1914

20-
# target_include_directories (cpp-net-framework PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
2115
target_link_libraries (cpp-net-framework)

src/examples/HelloWorld/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ include_directories(../../framework)
44

55
add_executable(HelloWorld main.cxx driver.cxx)
66

7-
# target_include_directories (cpp-net-framework PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
87
target_link_libraries (cpp-net-framework)

src/framework/NetString.h

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -160,70 +160,70 @@ namespace System
160160

161161
bool StartsWith(const String& s) const
162162
{
163-
if (String::IsNullOrEmpty(s)){
163+
if (String::IsNullOrEmpty(s)) {
164164
return false;
165165
}
166-
return (IndexOf(s)==0);
166+
return (IndexOf(s) == 0);
167167
}
168168

169169
bool EndsWith(const String& s) const
170170
{
171-
if (String::IsNullOrEmpty(s)){
171+
if (String::IsNullOrEmpty(s)) {
172172
return false;
173173
}
174-
return (IndexOf(s)==Length()-s.Length());
174+
return (IndexOf(s) == Length() - s.Length());
175175
}
176176

177177
String Replace(const String& from, const String& with)
178178
{
179-
int pos=IndexOf(from);
180-
if (pos==-1){
179+
int pos = IndexOf(from);
180+
if (pos == -1) {
181181
return (*this);
182182
}
183183

184-
String newstring=(*this);
185-
186-
int maxCount=10;
187-
while (pos!=-1 && maxCount--){
188-
newstring.m_str.replace(pos,pos+from.Length(),with.str());
189-
190-
int lastpos = pos;
191-
pos=newstring.IndexOf(from);
192-
193-
// try to prevent it going infinite
194-
if (pos < lastpos){
195-
break;
196-
}
197-
}
184+
String newstring = (*this);
185+
186+
//int maxCount=10;
187+
//while (pos!=-1 && maxCount--){
188+
newstring.m_str.replace(pos, pos + from.Length(), with.str());
189+
190+
//int lastpos = pos;
191+
//pos=newstring.IndexOf(from);
192+
193+
// try to prevent it going infinite
194+
//if (pos < lastpos){
195+
// break;
196+
//}
197+
//}
198198

199199
return newstring;
200200
}
201201

202202
String Trim() const
203203
{
204-
String s=(*this);
205-
s=s.TrimEnd();
206-
s=s.TrimStart();
207-
return s;
204+
String s = (*this);
205+
s = s.TrimEnd();
206+
s = s.TrimStart();
207+
return s;
208208
}
209209

210210
String TrimEnd() const
211211
{
212-
String s=(*this);
213-
s.m_str.erase(s.m_str.find_last_not_of(" \n\r\t")+1);
214-
return s;
212+
String s = (*this);
213+
s.m_str.erase(s.m_str.find_last_not_of(" \n\r\t") + 1);
214+
return s;
215215
}
216216

217217
String TrimStart() const
218218
{
219-
String s=(*this);
220-
s.m_str.erase(s.m_str.find_first_not_of(" \n\r\t")+1);
221-
return s;
219+
String s = (*this);
220+
s = s.Substring(s.m_str.find_first_not_of(" \n\r\t"));
221+
return s;
222222
}
223223

224224
static bool IsNullOrEmpty(const String &s)
225225
{
226-
return (s.Length()==0);
226+
return (s.Length() == 0);
227227
}
228228
};
229229

@@ -250,6 +250,8 @@ namespace System
250250
{
251251
return (a.str() != b.str());
252252
}
253+
254+
// void PrintTo(const System::String& str, ::std::ostream* os);
253255
}
254256

255257
typedef System::String string;

src/framework/System.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11

22
#include "System.h"
3+
4+
//void System::PrintTo(const System::String& str, ::std::ostream* os) {
5+
// *os << str.str().c_str();
6+
//}

src/unittests/String_Test.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ TEST(StringTest, Trim)
127127
EXPECT_EQ(String("Hello"),String(" Hello ").Trim());
128128

129129
EXPECT_EQ(String("Hello"),String(" Hello").TrimStart());
130-
EXPECT_EQ(String("Hello "),String("Hello ").TrimStart());
130+
EXPECT_EQ(String("Hello "),String("Hello ").TrimStart());
131131
EXPECT_EQ(String("Hello"),String("Hello").TrimStart());
132132
EXPECT_EQ(String("Hello "),String(" Hello ").TrimStart());
133133

134-
EXPECT_EQ(String(" Hello"),String(" Hello").TrimEnd());
134+
EXPECT_EQ(String(" Hello"),String(" Hello").TrimEnd());
135135
EXPECT_EQ(String("Hello"),String("Hello ").TrimEnd());
136136
EXPECT_EQ(String("Hello"),String("Hello").TrimEnd());
137137
EXPECT_EQ(String(" Hello"),String(" Hello ").TrimEnd());

0 commit comments

Comments
 (0)