Skip to content

Commit 4f923b4

Browse files
author
waybeforenow
committed
capitalize() should match first character regardless of whether it is alphanumeric
1 parent 8a7c0a5 commit 4f923b4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/string_converter_filter.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,18 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
304304
result = Apply<UrlStringEncoder>(baseVal);
305305
break;
306306
case CapitalMode:
307-
result = ApplyStringConverter<GenericStringEncoder>(baseVal, [isFirstChar = true, &isAlNum](auto ch, auto&& fn) mutable {
308-
if (isFirstChar && isAlNum(ch)) {
309-
isFirstChar = false;
310-
fn(std::toupper(ch, std::locale()));
311-
} else if (isAlNum(ch)) {
312-
fn(std::tolower(ch, std::locale()));
307+
result = ApplyStringConverter<GenericStringEncoder>(baseVal, [isFirstChar = true, &isAlpha](auto ch, auto&& fn) mutable {
308+
if (isAlpha(ch)) {
309+
if (isFirstChar) {
310+
fn(std::toupper(ch, std::locale()));
311+
} else {
312+
fn(std::tolower(ch, std::locale()));
313+
}
313314
} else {
314315
fn(ch);
315316
}
317+
318+
isFirstChar = false;
316319
});
317320
break;
318321
default:

test/filters_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ INSTANTIATE_TEST_CASE_P(Capitalize, FilterGenericTest, ::testing::Values(
473473
InputOutputPair{"'1234string' | capitalize | pprint", "'1234string'"},
474474
InputOutputPair{"'1234String' | capitalize | pprint", "'1234string'"},
475475
InputOutputPair{"'Hello World' | capitalize | pprint", "'Hello world'"},
476+
InputOutputPair{"' Hello World' | capitalize | pprint", "' hello world'"},
476477
InputOutputPair{"'Hello123OOO, World!' | capitalize | pprint", "'Hello123ooo, world!'"}
477478
));
478479

0 commit comments

Comments
 (0)