jsoysouvanh / Refureku

Cross-platform C++17 Runtime Reflection Library
https://jsoysouvanh.github.io/Refureku/
MIT License
218 stars 21 forks source link

Filenames with dashes (-) generate invalid macros #6

Closed ataulien-thqnordic closed 2 years ago

ataulien-thqnordic commented 2 years ago

When using Refureku on sourcefiles which contain a dash (like sample-code.hpp), the generator will create a makro named File_sample-code_GENERATED, which is not valid C++.

One solution could be to extend the generator like so:

std::string MacroCodeGenUnitSettings::getHeaderFileFooterMacro(fs::path const& targetFile) const noexcept
{
    std::string headerFileFooterMacroName = _headerFileFooterMacroPattern;

    replaceTags(headerFileFooterMacroName, filenameTag, targetFile.filename().stem().string());
    replaceTags(headerFileFooterMacroName, "-", "_");

    return headerFileFooterMacroName;
}

I haven't tested other characters. Maybe spaces will cause issues, too?

jsoysouvanh commented 2 years ago

Hi!

Thank you for your report, I've taken note of the issue. I have indeed not taken these cases into consideration. I will update the base implementation to handle most common cases such as '-' and ' ' but simply using non-ASCII characters would break the system again, so I'll let very specific cases up to the user by inheriting from MacroCodeGenUnitSettings and override the get[Location]Macro methods.

I'll try to update the base implementation ASAP.

jsoysouvanh commented 2 years ago

@ataulien-thqnordic I should have fixed the problem in the latest release (v2.0.1). Let me know if it works for you :)