From bea545d62732fe048ca9cec7f82e4be1185cb87b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 28 Oct 2017 12:28:47 -0400 Subject: Fixed bug with token title case transform Word tokens and literal tokens that contained more than one word would only capitalize the first word; this has been fixed. --- lib/token.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'lib/token.cpp') diff --git a/lib/token.cpp b/lib/token.cpp index ce201b4..2fd6d44 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -344,12 +344,26 @@ namespace verbly { } } - if ((capitalization == casing::capitalize) || (capitalization == casing::title_case)) + if (capitalization == casing::capitalize) { if (std::isalpha(result[0])) { result[0] = std::toupper(result[0]); } + } else if (capitalization == casing::title_case) + { + std::list swords = + split>(result, " "); + + for (std::string& sword : swords) + { + if (std::isalpha(sword[0])) + { + sword[0] = std::toupper(sword[0]); + } + } + + result = implode(std::begin(swords), std::end(swords), " "); } else if (capitalization == casing::all_caps) { for (char& ch : result) @@ -381,12 +395,26 @@ namespace verbly { } } - if ((capitalization == casing::capitalize) || (capitalization == casing::title_case)) + if (capitalization == casing::capitalize) { if (std::isalpha(result[0])) { result[0] = std::toupper(result[0]); } + } else if (capitalization == casing::title_case) + { + std::list swords = + split>(result, " "); + + for (std::string& sword : swords) + { + if (std::isalpha(sword[0])) + { + sword[0] = std::toupper(sword[0]); + } + } + + result = implode(std::begin(swords), std::end(swords), " "); } else if (capitalization == casing::all_caps) { for (char& ch : result) -- cgit 1.4.1