Skip to content

Commit 4ac8ae9

Browse files
committed
Deal with more illegal chars in C variable
1 parent 78001c0 commit 4ac8ae9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tool/rawstr4c/lib/Generator.rakumod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ my class CVariableNameGenerator {
8080
$global-config.get('keep-postfix', 'true').as-bool();
8181

8282
my $name = $section-config.get('name', $title.lc).as-string();
83-
$name = $name.subst(/\s+/, '_', :g);
83+
# 替换非法字符
84+
$name = $name.subst(/<-[a..z A..Z 0..9 _]>/, '_', :g);
85+
# 合并连续的下划线
86+
$name = $name.subst(/_+/, '_', :g);
87+
# 移除结尾的下划线
88+
$name = $name.subst(/_+$/, '');
8489

8590
# 组装变量名
8691
my $var-name = "";

tool/rawstr4c/lib/Version.rakumod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
unit module Version;
1212

13-
constant VERSION = "0.1.0.1";
13+
constant VERSION = "0.1.0.2";
1414
constant RELEASE_DATE = "2025/07/14";
1515

1616
constant Maintain_URL = "https://github.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c";

0 commit comments

Comments
 (0)