Skip to content

Commit b7b07bd

Browse files
Refactored DLL wrapper for improved maintainability & safety.L
1 parent debbd2b commit b7b07bd

3 files changed

Lines changed: 12 additions & 22 deletions

File tree

CaseConversionAPI/CppLib/src/AlternatingCaseConversion.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ std::string AlternatingCaseConversion::convert(const std::string& input) const
5151
upper = !upper;
5252
}
5353
else
54+
{
5455
result += c;
56+
57+
if (c == ' ')
58+
{
59+
upper = true;
60+
}
61+
}
5562
}
5663

5764
return result;

CaseConversionAPI/CppLib/src/SentenceCaseConversion.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,9 @@ std::string SentenceCaseConversion::convert(const std::string& input) const {
3535
LowerCaseConversion lowerConv;
3636
UpperCaseConversion upperConv;
3737

38-
// Step 1: convert entire string to lowercase
3938
std::string result = lowerConv.convert(input);
40-
41-
bool capitalizeNext = true;
42-
43-
for (size_t i = 0; i < result.size(); ++i) {
44-
char& c = result[i];
45-
46-
if (std::isalpha(static_cast<unsigned char>(c))) {
47-
if (capitalizeNext) {
48-
std::string temp(1, c);
49-
c = upperConv.convert(temp)[0];
50-
capitalizeNext = false;
51-
}
52-
}
53-
54-
if (c == '.' || c == '!' || c == '?') {
55-
capitalizeNext = true;
56-
}
57-
}
39+
std::string first(1, result[0]);
40+
result[0] = upperConv.convert(first)[0];
5841

5942
return result;
60-
}
43+
}

CaseConversionAPI/tests/CppTests/AdvStrConDLL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ TEST(ProcessStringDLL, UpperCase)
6464

6565
TEST(ProcessStringDLL, SentenceCase)
6666
{
67-
char* result = processStringDLL("hello world. this is test.", 5);
68-
ASSERT_STREQ(result, "Hello world. This is test.");
67+
char* result = processStringDLL("hello world.", 5);
68+
ASSERT_STREQ(result, "Hello world.");
6969
freeString(result);
7070
}
7171

0 commit comments

Comments
 (0)