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)
308
308
static const std::regex non_alpha_numeric{" [^A-Za-z0-9\x80 -\xff ]+" };
309
309
return std::regex_replace (identifier, non_alpha_numeric, " _" );
310
310
};
311
- const auto strip_leading_non_letters = [](const std::string &identifier) {
311
+ const auto strip_leading_digits = [](const std::string &identifier) {
312
312
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 ]*" };
314
314
std::smatch match_results;
315
315
bool found = std::regex_search (identifier, match_results, identifier_regex);
316
316
POSTCONDITION (found);
317
317
return match_results.str (0 );
318
318
};
319
- return strip_leading_non_letters (replace_invalid_characters_with_underscore (
319
+ return strip_leading_digits (replace_invalid_characters_with_underscore (
320
320
replace_special_characters (name)));
321
321
}
322
322
Original file line number Diff line number Diff line change @@ -50,18 +50,19 @@ TEST_CASE(
50
50
R"( abcdefghijklmnopqrstuvwxyz{|}~)" );
51
51
CHECK (
52
52
type_name2type_identifier (printable_characters) ==
53
- " ptr_0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz_ "
53
+ " _ptr_0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz_ "
54
54
" start_sub_end_sub_" );
55
55
}
56
56
57
57
TEST_CASE (
58
- " type_name2type_identifier leading digits " ,
58
+ " type_name2type_identifier leading characters " ,
59
59
" [core][ansi-c][type_name2type_identifier]" )
60
60
{
61
61
CHECK (
62
- type_name2type_identifier (
63
- " 0123456789_banana_0123456789_split_0123456789" ) ==
62
+ type_name2type_identifier (" 0123456789banana_0123456789_split_0123456789" ) ==
64
63
" banana_0123456789_split_0123456789" );
64
+ CHECK (type_name2type_identifier (" 0123456789_banana" ) == " _banana" );
65
+ CHECK (type_name2type_identifier (" _0123456789" ) == " _0123456789" );
65
66
}
66
67
67
68
TEST_CASE (
You can’t perform that action at this time.
0 commit comments