Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unicode version check #13154

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

Merged
merged 2 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions enc/unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,6 @@ onigenc_unicode_case_map(OnigCaseFoldType* flagP,
return (int )(to - to_start);
}

#if 0
const char onigenc_unicode_version_string[] =
#ifdef ONIG_UNICODE_VERSION_STRING
ONIG_UNICODE_VERSION_STRING
Expand All @@ -817,4 +816,3 @@ const int onigenc_unicode_version_number[3] = {
0
#endif
};
#endif
11 changes: 11 additions & 0 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,17 @@ Init_Encoding(void)
rb_marshal_define_compat(rb_cEncoding, Qnil, 0, enc_m_loader);
}

void
Init_unicode_version(void)
{
extern const char onigenc_unicode_version_string[];

VALUE str = rb_usascii_str_new_static(onigenc_unicode_version_string,
strlen(onigenc_unicode_version_string));
OBJ_FREEZE(str);
rb_define_const(rb_cEncoding, "UNICODE_VERSION", str);
}

void
Init_encodings(void)
{
Expand Down
1 change: 1 addition & 0 deletions inits.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rb_call_inits(void)
CALL(ast);
CALL(shape);
CALL(Prism);
CALL(unicode_version);

// enable builtin loading
CALL(builtin);
Expand Down
3 changes: 3 additions & 0 deletions lib/unicode_normalize/tables.rb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry to be late with my review, but I don't understand why the Unicode version is hardcoded here. That only produces additional work when upgrading to a new version next time.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# coding: us-ascii
# frozen_string_literal: true

Encoding::UNICODE_VERSION == "16.0.0" or
raise "Unicode version mismatch: 16.0.0 expected but #{Encoding::UNICODE_VERSION}"

# automatically generated by template/unicode_norm_gen.tmpl

module UnicodeNormalize # :nodoc:
Expand Down
3 changes: 3 additions & 0 deletions template/unicode_norm_gen.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ end
# frozen_string_literal: true
%# >

Encoding::UNICODE_VERSION == <%= unicode_version.dump %><%=%> or
raise "Unicode version mismatch: <%= unicode_version %> expected but #{Encoding::UNICODE_VERSION}"

# automatically generated by template/unicode_norm_gen.tmpl

module UnicodeNormalize # :nodoc:
Expand Down
Loading