File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed
Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -308,15 +308,15 @@ std::string type_name2type_identifier(const std::string &name)
308308 static const std::regex non_alpha_numeric{" [^A-Za-z0-9\x80 -\xff ]+" };
309309 return std::regex_replace (identifier, non_alpha_numeric, " _" );
310310 };
311- const auto strip_leading_non_letters = [](const std::string &identifier) {
311+ const auto strip_leading_digits = [](const std::string &identifier) {
312312 static const std::regex identifier_regex{
313- " [A-Za-z\x80 -\xff ][A-Za-z0-9_\x80 -\xff ]*" };
313+ " [A-Za-z\x80 -\xff _ ][A-Za-z0-9_\x80 -\xff ]*" };
314314 std::smatch match_results;
315315 bool found = std::regex_search (identifier, match_results, identifier_regex);
316316 POSTCONDITION (found);
317317 return match_results.str (0 );
318318 };
319- return strip_leading_non_letters (replace_invalid_characters_with_underscore (
319+ return strip_leading_digits (replace_invalid_characters_with_underscore (
320320 replace_special_characters (name)));
321321}
322322
Original file line number Diff line number Diff line change @@ -50,18 +50,19 @@ TEST_CASE(
5050 R"( abcdefghijklmnopqrstuvwxyz{|}~)" );
5151 CHECK (
5252 type_name2type_identifier (printable_characters) ==
53- " ptr_0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz_ "
53+ " _ptr_0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz_ "
5454 " start_sub_end_sub_" );
5555}
5656
5757TEST_CASE (
58- " type_name2type_identifier leading digits " ,
58+ " type_name2type_identifier leading characters " ,
5959 " [core][ansi-c][type_name2type_identifier]" )
6060{
6161 CHECK (
62- type_name2type_identifier (
63- " 0123456789_banana_0123456789_split_0123456789" ) ==
62+ type_name2type_identifier (" 0123456789banana_0123456789_split_0123456789" ) ==
6463 " banana_0123456789_split_0123456789" );
64+ CHECK (type_name2type_identifier (" 0123456789_banana" ) == " _banana" );
65+ CHECK (type_name2type_identifier (" _0123456789" ) == " _0123456789" );
6566}
6667
6768TEST_CASE (
You can’t perform that action at this time.
0 commit comments