Titlecase does not preserve case when everything is uppercase

This commit is contained in:
Allan Odgaard
2014-10-03 20:46:21 +02:00
parent aa96f1f342
commit 6f68d2afb1
2 changed files with 3 additions and 1 deletions

View File

@@ -144,7 +144,7 @@ struct expand_visitor : boost::static_visitor<void>
static std::string capitalize (std::string const& src)
{
return format_string::replace(format_string::replace(src, "\\b\\p{Upper}\\p{^Upper}+?\\b", "${0:/downcase}"), "^([\\W\\d]*)(\\w[-\\w]*)|\\b((?!(?:else|from|over|then|when)\\b)\\w[-\\w]{3,}|\\w[-\\w]*[\\W\\d]*$)", "${1:?$1\\u$2:\\u$0}");
return format_string::replace(format_string::replace(src, "\\A\\p{^Lower}+\\z|\\b\\p{Upper}\\p{^Upper}+?\\b", "${0:/downcase}"), "^([\\W\\d]*)(\\w[-\\w]*)|\\b((?!(?:else|from|over|then|when)\\b)\\w[-\\w]{3,}|\\w[-\\w]*[\\W\\d]*$)", "${1:?$1\\u$2:\\u$0}");
}
static std::string asciify (std::string const& org)

View File

@@ -20,6 +20,8 @@ void test_capitalize ()
OAK_ASSERT_EQ(replace("# 2014-08-22: it works now again #", ".+", "${0:/capitalize}"), "# 2014-08-22: It Works now Again #");
OAK_ASSERT_EQ(replace("my NSTableView subclass", ".+", "${0:/capitalize}"), "My NSTableView Subclass");
OAK_ASSERT_EQ(replace("This Is The Wrong", ".+", "${0:/capitalize}"), "This is the Wrong");
OAK_ASSERT_EQ(replace("THIS IS THE WRONG", ".+", "${0:/capitalize}"), "This is the Wrong");
OAK_ASSERT_EQ(replace("RSA", ".+", "${0:/capitalize}"), "Rsa");
}
void test_variables ()