diff options
author | Alexander Batischev <eual.jp@gmail.com> | 2017-09-14 00:19:38 +0300 |
---|---|---|
committer | Alexander Batischev <eual.jp@gmail.com> | 2017-09-14 00:20:44 +0300 |
commit | e58d55d79aa5862b065200a3ccb770999c3eab71 (patch) | |
tree | 8f8505ef3a9b8ca1d0a5e70d6a78abe4c444b8af | |
parent | 62080f93ecc252fbd7e8fe5585b5ebc1a9b81793 (diff) |
consolidate_whitespace keeps leading whitespace
-rw-r--r-- | src/utils.cpp | 2 | ||||
-rw-r--r-- | test/utils.cpp | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/utils.cpp b/src/utils.cpp index c9ad4e34..14934561 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -201,7 +201,7 @@ std::string utils::consolidate_whitespace(const std::string& str, std::string wh std::string::size_type pos = str.find_first_of(whitespace, last_pos); if (last_pos != 0 && str != "") { - result.append(" "); + result.append(str.substr(0, last_pos)); } while (std::string::npos != pos || std::string::npos != last_pos) { diff --git a/test/utils.cpp b/test/utils.cpp index db48c399..e18dc246 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -136,12 +136,16 @@ TEST_CASE("consolidate_whitespace replaces multiple consecutive" "whitespace with a single space", "[utils]") { REQUIRE(utils::consolidate_whitespace("LoremIpsum") == "LoremIpsum"); REQUIRE(utils::consolidate_whitespace("Lorem Ipsum") == "Lorem Ipsum"); - REQUIRE(utils::consolidate_whitespace(" Lorem \t\tIpsum \t ") == " Lorem Ipsum "); - REQUIRE(utils::consolidate_whitespace(" Lorem \r\n\r\n\tIpsum") == " Lorem Ipsum"); + REQUIRE(utils::consolidate_whitespace(" Lorem \t\tIpsum \t ") == " Lorem Ipsum "); + REQUIRE(utils::consolidate_whitespace(" Lorem \r\n\r\n\tIpsum") == " Lorem Ipsum"); REQUIRE(utils::consolidate_whitespace("") == ""); - REQUIRE(utils::consolidate_whitespace(" Lorem|||Ipsum||", "|") == " Lorem Ipsum "); +} + +TEST_CASE("consolidate_whitespace preserves leading whitespace", "[utils]") { + REQUIRE(utils::consolidate_whitespace(" Lorem \t\tIpsum \t ") == " Lorem Ipsum "); + REQUIRE(utils::consolidate_whitespace(" Lorem \r\n\r\n\tIpsum") == " Lorem Ipsum"); } TEST_CASE("get_command_output()", "[utils]") { |