Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum capitalization in cpp_stl generates non-utf8 characters #708

Closed
lvntbkdmr opened this issue Feb 27, 2020 · 4 comments
Closed

enum capitalization in cpp_stl generates non-utf8 characters #708

lvntbkdmr opened this issue Feb 27, 2020 · 4 comments
Milestone

Comments

@lvntbkdmr
Copy link

lvntbkdmr commented Feb 27, 2020

I try to generate cpp_stl files from zip.ksy that is already available by running;

kaitai-struct-compiler.bat --target=cpp_stl zip.ksy

Generated zip.h contains enums like this:

    enum compression_t {
        COMPRESSİON_NONE = 0,
        COMPRESSİON_SHRUNK = 1,
        COMPRESSİON_REDUCED_1 = 2,
        COMPRESSİON_REDUCED_2 = 3,
        COMPRESSİON_REDUCED_3 = 4,
        COMPRESSİON_REDUCED_4 = 5,
        COMPRESSİON_İMPLODED = 6,
        COMPRESSİON_DEFLATED = 8,
        COMPRESSİON_ENHANCED_DEFLATED = 9,
        COMPRESSİON_PKWARE_DCL_İMPLODED = 10,
        COMPRESSİON_BZİP2 = 12,
        COMPRESSİON_LZMA = 14,
        COMPRESSİON_İBM_TERSE = 18,
        COMPRESSİON_İBM_LZ77_Z = 19,
        COMPRESSİON_PPMD = 98
    };

    enum extra_codes_t {
        EXTRA_CODES_ZİP64 = 1,
        EXTRA_CODES_AV_İNFO = 7,
        EXTRA_CODES_OS2 = 9,
        EXTRA_CODES_NTFS = 10,
        EXTRA_CODES_OPENVMS = 12,
        EXTRA_CODES_PKWARE_UNİX = 13,
        EXTRA_CODES_FİLE_STREAM_AND_FORK_DESCRİPTORS = 14,
        EXTRA_CODES_PATCH_DESCRİPTOR = 15,
        EXTRA_CODES_PKCS7 = 20,
        EXTRA_CODES_X509_CERT_İD_AND_SİGNATURE_FOR_FİLE = 21,
        EXTRA_CODES_X509_CERT_İD_FOR_CENTRAL_DİR = 22,
        EXTRA_CODES_STRONG_ENCRYPTİON_HEADER = 23,
        EXTRA_CODES_RECORD_MANAGEMENT_CONTROLS = 24,
        EXTRA_CODES_PKCS7_ENC_RECİP_CERT_LİST = 25,
        EXTRA_CODES_İBM_S390_UNCOMP = 101,
        EXTRA_CODES_İBM_S390_COMP = 102,
        EXTRA_CODES_POSZİP_4690 = 18064,
        EXTRA_CODES_EXTENDED_TİMESTAMP = 21589,
        EXTRA_CODES_İNFOZİP_UNİX = 30805,
        EXTRA_CODES_İNFOZİP_UNİX_VAR_SİZE = 30837
    };

As you can see, capitalizing small "i" results in capital İ which is available in my native language (Turkish). However, as you can imagine, it does not compile.. It gives me

In file included from src\zip.cpp:3:
include/zip.h:31:17: error: stray '\335' in program
         COMPRESSİON_NONE = 0,

There are also macro issues such as

#ifndef ZİP_H_
#define ZİP_H_
@GreyCat
Copy link
Member

GreyCat commented Feb 27, 2020

Great catch, thanks! Looks like we need to test capitalization to be locale-independent.

@generalmimon
Copy link
Member

generalmimon commented Mar 2, 2020

@GreyCat
Relying on toUpperCase(java.Locale.ROOT) apparently doesn't work for JavaScript. As suggested in this issue, we'll probably need to use https://github.com/cquiroz/scala-java-locales.

@GreyCat
Copy link
Member

GreyCat commented Mar 3, 2020

I've started this thread on SO, but so far the proposed simple solution doesn't quite work for me :( Will try to get to it more...

@GreyCat
Copy link
Member

GreyCat commented Mar 9, 2020

Confirming that it works! Thanks, @generalmimon, I've played with it a lot but for some reason that solution at SO never worked for me — but you've demonstrated that it clearly works!

@GreyCat GreyCat added this to the v0.9 milestone Mar 9, 2020
generalmimon added a commit to kaitai-io/kaitai_struct_compiler that referenced this issue Sep 15, 2022
Using this function has already caused problems in the past, see kaitai-io/kaitai_struct#708.
generalmimon added a commit to kaitai-io/kaitai_struct_compiler that referenced this issue Feb 26, 2024
Avoid the problem with the Turkish locale that we have encountered in
the past, see kaitai-io/kaitai_struct#708.
generalmimon added a commit to kaitai-io/kaitai_struct_compiler that referenced this issue Mar 3, 2024
Avoid the problem with the Turkish locale that we have encountered in
the past, see kaitai-io/kaitai_struct#708.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants