Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions utils/base64-encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ inline std::string int_to_string(int value)
return oss.str();
}

// A C++ implementation of the CMAKE string-operation MAKE_C_IDENTIFIER
std::string make_c_identifier(const std::string& input)
{
std::string output;

// If the first character is a digit, prepend an underscore
if (!input.empty() && std::isdigit(input[0]))
output += '_';

// Process each character
for(int i = 0; i < input.size(); i++)
{
const char ch = input[i];
if (std::isalnum(ch) || ch == '_')
output += ch; // Keep letters, numbers, and underscores
else
output += '_'; // Replace other characters with underscore
}

return output;
}

int main(int argc, char ** argv)
{
if ((argc < 2) || (argc > 4))
Expand Down Expand Up @@ -108,11 +130,7 @@ int main(int argc, char ** argv)
exit(-1);
}

std::string encodeFormatFileName = input;
std::replace(
encodeFormatFileName.begin(), encodeFormatFileName.end(), '.', '_');
std::replace(
encodeFormatFileName.begin(), encodeFormatFileName.end(), '-', '_');
std::string encodeFormatFileName = make_c_identifier(input);

std::string header
= "extern unsigned char " + encodeFormatFileName + "[] = \n\"";
Expand Down
Loading