From 4d45bf7c8945c6165b2267b0b4d5c846077876b1 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Thu, 2 Jun 2016 20:09:37 +0200 Subject: [PATCH] Merged ascii.cpp into stringTools.cpp --- CMakeLists.txt | 3 --- src/ascii.cpp | 22 ---------------------- src/ascii.h | 7 ------- src/stringTools.cpp | 18 ++++++++++++++++++ src/stringTools.h | 5 +++++ src/tokenization.cpp | 2 +- tests/asciiTests.cpp | 13 ------------- tests/stringToolsTests.cpp | 11 ++++++++++- 8 files changed, 34 insertions(+), 47 deletions(-) delete mode 100644 src/ascii.cpp delete mode 100644 src/ascii.h delete mode 100644 tests/asciiTests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ca91b2..4ec1b86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,7 +190,6 @@ set(SOURCE_FILES src/ContinuousTimeline.h src/pairs.h src/Exporter.cpp src/Exporter.h - src/ascii.cpp src/ascii.h src/tokenization.cpp src/tokenization.h ) add_executable(rhubarb ${SOURCE_FILES}) @@ -205,14 +204,12 @@ set(TEST_FILES tests/BoundedTimelineTests.cpp tests/ContinuousTimelineTests.cpp tests/pairsTests.cpp - tests/asciiTests.cpp tests/tokenizationTests.cpp src/stringTools.cpp src/stringTools.h src/Timeline.h src/TimeRange.cpp src/TimeRange.h src/centiseconds.cpp src/centiseconds.h src/pairs.h - src/ascii.cpp src/ascii.h src/tokenization.cpp src/tokenization.h ) add_executable(runTests ${TEST_FILES}) diff --git a/src/ascii.cpp b/src/ascii.cpp deleted file mode 100644 index bcdffda..0000000 --- a/src/ascii.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "ascii.h" - -using std::string; -using std::u32string; -using boost::optional; - -optional toASCII(char32_t ch) { - switch (ch) { - #include "asciiCases.cpp" - default: - return ch < 0x80 ? static_cast(ch) : optional(); - } -} - -string toASCII(const u32string& s) { - string result; - for (char32_t ch : s) { - optional ascii = toASCII(ch); - if (ascii) result.append(1, *ascii); - } - return result; -} diff --git a/src/ascii.h b/src/ascii.h deleted file mode 100644 index fc61bf9..0000000 --- a/src/ascii.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include -#include - -boost::optional toASCII(char32_t ch); -std::string toASCII(const std::u32string& s); \ No newline at end of file diff --git a/src/stringTools.cpp b/src/stringTools.cpp index 73a6e3d..9da85c1 100644 --- a/src/stringTools.cpp +++ b/src/stringTools.cpp @@ -2,7 +2,9 @@ #include using std::string; +using std::u32string; using std::vector; +using boost::optional; vector splitIntoLines(const string& s) { vector lines; @@ -79,3 +81,19 @@ vector wrapString(const string& s, int lineLength, int hangingIndent) { return lines; } +optional toASCII(char32_t ch) { + switch (ch) { +#include "asciiCases.cpp" + default: + return ch < 0x80 ? static_cast(ch) : optional(); + } +} + +string toASCII(const u32string& s) { + string result; + for (char32_t ch : s) { + optional ascii = toASCII(ch); + if (ascii) result.append(1, *ascii); + } + return result; +} diff --git a/src/stringTools.h b/src/stringTools.h index 522cc9e..9257e68 100644 --- a/src/stringTools.h +++ b/src/stringTools.h @@ -2,9 +2,14 @@ #include #include +#include std::vector splitIntoLines(const std::string& s); std::vector wrapSingleLineString(const std::string& s, int lineLength, int hangingIndent = 0); std::vector wrapString(const std::string& s, int lineLength, int hangingIndent = 0); + +boost::optional toASCII(char32_t ch); + +std::string toASCII(const std::u32string& s); \ No newline at end of file diff --git a/src/tokenization.cpp b/src/tokenization.cpp index aa1d944..bf57ebe 100644 --- a/src/tokenization.cpp +++ b/src/tokenization.cpp @@ -1,6 +1,6 @@ #include "tokenization.h" #include "tools.h" -#include "ascii.h" +#include "stringTools.h" #include extern "C" { diff --git a/tests/asciiTests.cpp b/tests/asciiTests.cpp deleted file mode 100644 index 5b4dd65..0000000 --- a/tests/asciiTests.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "ascii.h" - -using namespace testing; -using std::string; - -TEST(toASCII, string) { - EXPECT_EQ( - "A naive man called was having pina colada and creme brulee.", - toASCII(U"A naïve man called 晨 was having piña colada and crème brûlée.")); - EXPECT_EQ(string(""), toASCII(U"")); -} - diff --git a/tests/stringToolsTests.cpp b/tests/stringToolsTests.cpp index b30f630..f135c9a 100644 --- a/tests/stringToolsTests.cpp +++ b/tests/stringToolsTests.cpp @@ -1,7 +1,8 @@ -#include +#include #include "stringTools.h" using namespace testing; +using std::string; // splitIntoLines @@ -71,3 +72,11 @@ TEST(wrapString, basic) { EXPECT_THAT(wrapString("\n\nLine no 3\n\nLine no 4\n", 8), ElementsAre("", "", "Line no", "3", "", "Line no", "4", "")); } +// toASCII + +TEST(toASCII, string) { + EXPECT_EQ( + "A naive man called was having pina colada and creme brulee.", + toASCII(U"A naïve man called 晨 was having piña colada and crème brûlée.")); + EXPECT_EQ(string(""), toASCII(U"")); +}