diff options
| -rw-r--r-- | StringTools/StringTools/StringTools.cpp | 36 | ||||
| -rw-r--r-- | StringTools/StringTools/StringTools.h | 3 | ||||
| -rw-r--r-- | StringTools/Test/Test.vcxproj | 1 | ||||
| -rw-r--r-- | StringTools/Test/Test.vcxproj.filters | 3 | ||||
| -rw-r--r-- | StringTools/Test/Upper.cpp | 200 |
5 files changed, 243 insertions, 0 deletions
diff --git a/StringTools/StringTools/StringTools.cpp b/StringTools/StringTools/StringTools.cpp index 7e26c5c..4c57292 100644 --- a/StringTools/StringTools/StringTools.cpp +++ b/StringTools/StringTools/StringTools.cpp @@ -96,3 +96,39 @@ std::string StringTools::Lower(const std::string& str) return ss.str();
}
+
+std::string StringTools::Upper(const std::string& str)
+{
+ std::stringstream ss;
+
+ for (std::size_t i = 0; i < str.size(); i++)
+ {
+ const char c = str[i];
+
+ // Quick-accept: regular letters
+ if ((c >= 'a') && (c <= 'z'))
+ ss << (char)(c - 32);
+
+ // Damned umlautes:
+ else if (c == 'ä') ss << 'Ä';
+ else if (c == 'á') ss << 'Á';
+ else if (c == 'à') ss << 'À';
+ else if (c == 'â') ss << 'Â';
+ else if (c == 'é') ss << 'É';
+ else if (c == 'è') ss << 'È';
+ else if (c == 'ê') ss << 'Ê';
+ else if (c == 'ü') ss << 'Ü';
+ else if (c == 'ú') ss << 'Ú';
+ else if (c == 'ù') ss << 'Ù';
+ else if (c == 'û') ss << 'Û';
+ else if (c == 'ö') ss << 'Ö';
+ else if (c == 'ó') ss << 'Ó';
+ else if (c == 'ò') ss << 'Ò';
+ else if (c == 'ô') ss << 'Ô';
+
+ // Else: keep the character as is
+ else ss << c;
+ }
+
+ return ss.str();
+}
diff --git a/StringTools/StringTools/StringTools.h b/StringTools/StringTools/StringTools.h index 39e512f..589c047 100644 --- a/StringTools/StringTools/StringTools.h +++ b/StringTools/StringTools/StringTools.h @@ -20,6 +20,9 @@ public: //! Will make a string all-lowercase. Only works with latin and german umlautes, plus some extras.
static std::string Lower(const std::string& str);
+ //! Will make a string all-uppercase. Only works with latin and german umlautes, plus some extras.
+ static std::string Upper(const std::string& str);
+
private:
// No instanciation! >:(
StringTools();
diff --git a/StringTools/Test/Test.vcxproj b/StringTools/Test/Test.vcxproj index 59e804a..b94c55a 100644 --- a/StringTools/Test/Test.vcxproj +++ b/StringTools/Test/Test.vcxproj @@ -165,6 +165,7 @@ <ClCompile Include="Lower.cpp" />
<ClCompile Include="Replace_Char.cpp" />
<ClCompile Include="Replace_String.cpp" />
+ <ClCompile Include="Upper.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/StringTools/Test/Test.vcxproj.filters b/StringTools/Test/Test.vcxproj.filters index c10488e..10b98cf 100644 --- a/StringTools/Test/Test.vcxproj.filters +++ b/StringTools/Test/Test.vcxproj.filters @@ -24,5 +24,8 @@ <ClCompile Include="Lower.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
+ <ClCompile Include="Upper.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/StringTools/Test/Upper.cpp b/StringTools/Test/Upper.cpp new file mode 100644 index 0000000..cbefee7 --- /dev/null +++ b/StringTools/Test/Upper.cpp @@ -0,0 +1,200 @@ +#include "CppUnitTest.h"
+#include "../StringTools/StringTools.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace _StringTools
+{
+ TEST_CLASS(_Upper)
+ {
+ public:
+
+ // Tests that uppering an empty string returns an empty string
+ TEST_METHOD(EmptyString)
+ {
+ // Setup
+ const std::string in = "";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("", out.c_str());
+ return;
+ }
+
+ // Tests that uppering a string without any letters returns an itself
+ TEST_METHOD(Symbols)
+ {
+ // Setup
+ const std::string in = "66! _-\n*";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("66! _-\n*", out.c_str());
+ return;
+ }
+
+ // Tests that uppering a string of uppercase letters returns itself
+ TEST_METHOD(AlreadyUppered)
+ {
+ // Setup
+ const std::string in = "UGHAREYOUSERIOUS";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("UGHAREYOUSERIOUS", out.c_str());
+ return;
+ }
+
+ // Tests that uppering a string of lowercase letters returns the uppercase version
+ TEST_METHOD(Lowercase)
+ {
+ // Setup
+ const std::string in = "ughareyouserious";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("UGHAREYOUSERIOUS", out.c_str());
+ return;
+ }
+
+ // Tests that uppering a string of uppercase, lowercase letters and symbols returns the uppercase version
+ TEST_METHOD(Mixed)
+ {
+ // Setup
+ const std::string in = "Ugh, Are You Serious?! DON'T do that!!!";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("UGH, ARE YOU SERIOUS?! DON'T DO THAT!!!", out.c_str());
+ return;
+ }
+
+ // Tests that uppering already uppered umlautes returns itself
+ TEST_METHOD(Umlautes_already_upper_a)
+ {
+ // Setup
+ const std::string in = "ÄÁÀÂ";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÄÁÀÂ", out.c_str());
+ }
+
+ // Tests that uppering uppercase umlautes returns the upper umlautes
+ TEST_METHOD(Umlautes_upper_a)
+ {
+ // Setup
+ const std::string in = "äáàâ";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÄÁÀÂ", out.c_str());
+ }
+
+ // Tests that uppering already uppered umlautes returns itself
+ TEST_METHOD(Umlautes_already_upper_e)
+ {
+ // Setup
+ const std::string in = "ÉÈÊ";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÉÈÊ", out.c_str());
+ }
+
+ // Tests that uppering uppercase umlautes returns the upper umlautes
+ TEST_METHOD(Umlautes_upper_e)
+ {
+ // Setup
+ const std::string in = "éèê";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÉÈÊ", out.c_str());
+ }
+
+ // Tests that uppering already uppered umlautes returns itself
+ TEST_METHOD(Umlautes_already_upper_u)
+ {
+ // Setup
+ const std::string in = "ÜÚÙÛ";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÜÚÙÛ", out.c_str());
+ }
+
+ // Tests that uppering uppercase umlautes returns the upper umlautes
+ TEST_METHOD(Umlautes_upper_u)
+ {
+ // Setup
+ const std::string in = "üúùû";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÜÚÙÛ", out.c_str());
+ }
+
+ // Tests that uppering already uppered umlautes returns itself
+ TEST_METHOD(Umlautes_already_upper_o)
+ {
+ // Setup
+ const std::string in = "ÖÓÒÔ";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÖÓÒÔ", out.c_str());
+ }
+
+ // Tests that uppering uppercase umlautes returns the upper umlautes
+ TEST_METHOD(Umlautes_upper_o)
+ {
+ // Setup
+ const std::string in = "öóòô";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÖÓÒÔ", out.c_str());
+ }
+
+ // Tests that uppering a string of uppercase, lowercase letters and symbols returns the lowercase version, even with umlauts
+ TEST_METHOD(Mixed_with_umlautes)
+ {
+ // Setup
+ const std::string in = "Ügh, Àrä Yóü Seriöûs?! DÒN'T DÔ THÄT!!!";
+
+ // Exercise
+ const std::string out = StringTools::Upper(in);
+
+ // Verify
+ Assert::AreEqual("ÜGH, ÀRÄ YÓÜ SERIÖÛS?! DÒN'T DÔ THÄT!!!", out.c_str());
+ return;
+ }
+ };
+}
|
