Skip to content

Commit

Permalink
avoid multiple underscores in module name
Browse files Browse the repository at this point in the history
  • Loading branch information
ygorpontelo committed Oct 27, 2024
1 parent 8e273d3 commit 45f90c9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/build/project_creation.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,27 +301,35 @@ static const char *module_name(BuildOptions *build_options)
scratch_buffer_clear();
size_t len = strlen(build_options->project_name);
bool has_char = false;
bool appended_underscore = false;
for (size_t i = 0; i < len; i++)
{
char c = build_options->project_name[i];
if (c >= '0' && c <= '9')
{
if (!has_char) scratch_buffer_append("m_");
has_char = true;
scratch_buffer_append_char(c);
has_char = true;
appended_underscore=false;
continue;
}
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
{
scratch_buffer_append_char(c | 0x20);
has_char = true;
appended_underscore=false;
continue;
}
scratch_buffer_append_char('_');
if (!appended_underscore)
{
scratch_buffer_append_char('_');
appended_underscore = true;
}
}
if (!has_char) scratch_buffer_append("module");
return scratch_buffer_to_string();
}

static void create_file_or_fail(BuildOptions *build_options, const char *filename, const char *fmt, ...)
{
if (!fmt)
Expand Down

0 comments on commit 45f90c9

Please sign in to comment.