summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-10-28 12:28:47 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-10-28 12:28:47 -0400
commitbea545d62732fe048ca9cec7f82e4be1185cb87b (patch)
tree48aed6ebeb1a0d4261feca7c4cddde4735f23452 /lib
parent1fd518d1c2b1d4e88ad88218b606a284b7128107 (diff)
downloadverbly-bea545d62732fe048ca9cec7f82e4be1185cb87b.tar.gz
verbly-bea545d62732fe048ca9cec7f82e4be1185cb87b.tar.bz2
verbly-bea545d62732fe048ca9cec7f82e4be1185cb87b.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/token.cpp32
1 files changed, 30 insertions, 2 deletions
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 {
344 } 344 }
345 } 345 }
346 346
347 if ((capitalization == casing::capitalize) || (capitalization == casing::title_case)) 347 if (capitalization == casing::capitalize)
348 { 348 {
349 if (std::isalpha(result[0])) 349 if (std::isalpha(result[0]))
350 { 350 {
351 result[0] = std::toupper(result[0]); 351 result[0] = std::toupper(result[0]);
352 } 352 }
353 } else if (capitalization == casing::title_case)
354 {
355 std::list<std::string> swords =
356 split<std::list<std::string>>(result, " ");
357
358 for (std::string& sword : swords)
359 {
360 if (std::isalpha(sword[0]))
361 {
362 sword[0] = std::toupper(sword[0]);
363 }
364 }
365
366 result = implode(std::begin(swords), std::end(swords), " ");
353 } else if (capitalization == casing::all_caps) 367 } else if (capitalization == casing::all_caps)
354 { 368 {
355 for (char& ch : result) 369 for (char& ch : result)
@@ -381,12 +395,26 @@ namespace verbly {
381 } 395 }
382 } 396 }
383 397
384 if ((capitalization == casing::capitalize) || (capitalization == casing::title_case)) 398 if (capitalization == casing::capitalize)
385 { 399 {
386 if (std::isalpha(result[0])) 400 if (std::isalpha(result[0]))
387 { 401 {
388 result[0] = std::toupper(result[0]); 402 result[0] = std::toupper(result[0]);
389 } 403 }
404 } else if (capitalization == casing::title_case)
405 {
406 std::list<std::string> swords =
407 split<std::list<std::string>>(result, " ");
408
409 for (std::string& sword : swords)
410 {
411 if (std::isalpha(sword[0]))
412 {
413 sword[0] = std::toupper(sword[0]);
414 }
415 }
416
417 result = implode(std::begin(swords), std::end(swords), " ");
390 } else if (capitalization == casing::all_caps) 418 } else if (capitalization == casing::all_caps)
391 { 419 {
392 for (char& ch : result) 420 for (char& ch : result)