Merged ascii.cpp into stringTools.cpp
This commit is contained in:
parent
4d95b4c2c5
commit
4d45bf7c89
|
@ -190,7 +190,6 @@ set(SOURCE_FILES
|
||||||
src/ContinuousTimeline.h
|
src/ContinuousTimeline.h
|
||||||
src/pairs.h
|
src/pairs.h
|
||||||
src/Exporter.cpp src/Exporter.h
|
src/Exporter.cpp src/Exporter.h
|
||||||
src/ascii.cpp src/ascii.h
|
|
||||||
src/tokenization.cpp src/tokenization.h
|
src/tokenization.cpp src/tokenization.h
|
||||||
)
|
)
|
||||||
add_executable(rhubarb ${SOURCE_FILES})
|
add_executable(rhubarb ${SOURCE_FILES})
|
||||||
|
@ -205,14 +204,12 @@ set(TEST_FILES
|
||||||
tests/BoundedTimelineTests.cpp
|
tests/BoundedTimelineTests.cpp
|
||||||
tests/ContinuousTimelineTests.cpp
|
tests/ContinuousTimelineTests.cpp
|
||||||
tests/pairsTests.cpp
|
tests/pairsTests.cpp
|
||||||
tests/asciiTests.cpp
|
|
||||||
tests/tokenizationTests.cpp
|
tests/tokenizationTests.cpp
|
||||||
src/stringTools.cpp src/stringTools.h
|
src/stringTools.cpp src/stringTools.h
|
||||||
src/Timeline.h
|
src/Timeline.h
|
||||||
src/TimeRange.cpp src/TimeRange.h
|
src/TimeRange.cpp src/TimeRange.h
|
||||||
src/centiseconds.cpp src/centiseconds.h
|
src/centiseconds.cpp src/centiseconds.h
|
||||||
src/pairs.h
|
src/pairs.h
|
||||||
src/ascii.cpp src/ascii.h
|
|
||||||
src/tokenization.cpp src/tokenization.h
|
src/tokenization.cpp src/tokenization.h
|
||||||
)
|
)
|
||||||
add_executable(runTests ${TEST_FILES})
|
add_executable(runTests ${TEST_FILES})
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
#include "ascii.h"
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::u32string;
|
|
||||||
using boost::optional;
|
|
||||||
|
|
||||||
optional<char> toASCII(char32_t ch) {
|
|
||||||
switch (ch) {
|
|
||||||
#include "asciiCases.cpp"
|
|
||||||
default:
|
|
||||||
return ch < 0x80 ? static_cast<char>(ch) : optional<char>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string toASCII(const u32string& s) {
|
|
||||||
string result;
|
|
||||||
for (char32_t ch : s) {
|
|
||||||
optional<char> ascii = toASCII(ch);
|
|
||||||
if (ascii) result.append(1, *ascii);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <boost/optional.hpp>
|
|
||||||
|
|
||||||
boost::optional<char> toASCII(char32_t ch);
|
|
||||||
std::string toASCII(const std::u32string& s);
|
|
|
@ -2,7 +2,9 @@
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::u32string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using boost::optional;
|
||||||
|
|
||||||
vector<string> splitIntoLines(const string& s) {
|
vector<string> splitIntoLines(const string& s) {
|
||||||
vector<string> lines;
|
vector<string> lines;
|
||||||
|
@ -79,3 +81,19 @@ vector<string> wrapString(const string& s, int lineLength, int hangingIndent) {
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional<char> toASCII(char32_t ch) {
|
||||||
|
switch (ch) {
|
||||||
|
#include "asciiCases.cpp"
|
||||||
|
default:
|
||||||
|
return ch < 0x80 ? static_cast<char>(ch) : optional<char>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string toASCII(const u32string& s) {
|
||||||
|
string result;
|
||||||
|
for (char32_t ch : s) {
|
||||||
|
optional<char> ascii = toASCII(ch);
|
||||||
|
if (ascii) result.append(1, *ascii);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -2,9 +2,14 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
std::vector<std::string> splitIntoLines(const std::string& s);
|
std::vector<std::string> splitIntoLines(const std::string& s);
|
||||||
|
|
||||||
std::vector<std::string> wrapSingleLineString(const std::string& s, int lineLength, int hangingIndent = 0);
|
std::vector<std::string> wrapSingleLineString(const std::string& s, int lineLength, int hangingIndent = 0);
|
||||||
|
|
||||||
std::vector<std::string> wrapString(const std::string& s, int lineLength, int hangingIndent = 0);
|
std::vector<std::string> wrapString(const std::string& s, int lineLength, int hangingIndent = 0);
|
||||||
|
|
||||||
|
boost::optional<char> toASCII(char32_t ch);
|
||||||
|
|
||||||
|
std::string toASCII(const std::u32string& s);
|
|
@ -1,6 +1,6 @@
|
||||||
#include "tokenization.h"
|
#include "tokenization.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "ascii.h"
|
#include "stringTools.h"
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#include <gmock/gmock.h>
|
|
||||||
#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""));
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include "stringTools.h"
|
#include "stringTools.h"
|
||||||
|
|
||||||
using namespace testing;
|
using namespace testing;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
// splitIntoLines
|
// 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", ""));
|
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""));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue