Deal with more illegal chars in C variable

This commit is contained in:
Aoran Zeng 2025-07-15 00:10:34 +08:00
parent 78001c002f
commit 4ac8ae9cc0
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
2 changed files with 7 additions and 2 deletions

View File

@ -80,7 +80,12 @@ my class CVariableNameGenerator {
$global-config.get('keep-postfix', 'true').as-bool();
my $name = $section-config.get('name', $title.lc).as-string();
$name = $name.subst(/\s+/, '_', :g);
# 替换非法字符
$name = $name.subst(/<-[a..z A..Z 0..9 _]>/, '_', :g);
# 合并连续的下划线
$name = $name.subst(/_+/, '_', :g);
# 移除结尾的下划线
$name = $name.subst(/_+$/, '');
# 组装变量名
my $var-name = "";

View File

@ -10,7 +10,7 @@
unit module Version;
constant VERSION = "0.1.0.1";
constant VERSION = "0.1.0.2";
constant RELEASE_DATE = "2025/07/14";
constant Maintain_URL = "https://github.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c";