| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add :func:`unicodedata.block` function to return the `Unicode block | ||
| <https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G64189>`_ of a | ||
| character. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Expand Up | @@ -1493,7 +1493,7 @@ | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (i < (int)Py_ARRAY_LENGTH(derived_name_prefixes)) { | ||||||||||||||
| Py_UCS4 v = parse_hex_code(name + prefixlen, namelen - prefixlen); | ||||||||||||||
|
Check warning on line 1496 in Modules/unicodedata.c
|
||||||||||||||
| if (find_prefix_id(v) != i) { | ||||||||||||||
| return 0; | ||||||||||||||
| } | ||||||||||||||
| Expand Down Expand Up | @@ -2066,6 +2066,39 @@ | |||||||||||||
| return (PyObject*)gbi; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /*[clinic input] | ||||||||||||||
| unicodedata.block | ||||||||||||||
|
|
||||||||||||||
| chr: int(accept={str}) | ||||||||||||||
| / | ||||||||||||||
|
|
||||||||||||||
| Return block assigned to the character chr. | ||||||||||||||
| [clinic start generated code]*/ | ||||||||||||||
|
|
||||||||||||||
| static PyObject * | ||||||||||||||
| unicodedata_block_impl(PyObject *module, int chr) | ||||||||||||||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHave you tried other approaches for this, and compared the performances?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
* ./python -m timeit -v -r 10 -n 1000000 -s "import unicodedata; b=unicodedata.block" "b('\u0041');b('\u4E00');b('\U0010FFFF')" The lookup difference is minor, and we save quite a bit of memory (~17%), so I think this approach is better.
Sorry, something went wrong.
All reactions
|
||||||||||||||
| /*[clinic end generated code: output=5f8b40c49eaec75a input=0834cf2642d6eaae]*/ | ||||||||||||||
| { | ||||||||||||||
| Py_UCS4 c = (Py_UCS4)chr; | ||||||||||||||
| int lo = 0, hi = BLOCK_COUNT - 1; | ||||||||||||||
| while (lo <= hi) { | ||||||||||||||
| int mid = (lo + hi) / 2; | ||||||||||||||
| if (c < _PyUnicode_Blocks[mid].start) { | ||||||||||||||
| hi = mid - 1; | ||||||||||||||
| } | ||||||||||||||
| else if (c > _PyUnicode_Blocks[mid].end) { | ||||||||||||||
| lo = mid + 1; | ||||||||||||||
| } | ||||||||||||||
| else { | ||||||||||||||
| size_t name = _PyUnicode_Blocks[mid].name; | ||||||||||||||
| return PyUnicode_FromString(_PyUnicode_BlockNames[name]); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| // Otherwise, return the default value per | ||||||||||||||
| // https://www.unicode.org/versions/latest/core-spec/chapter-3/#G64189 | ||||||||||||||
| return PyUnicode_FromString("No_Block"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /*[clinic input] | ||||||||||||||
| unicodedata.grapheme_cluster_break | ||||||||||||||
|
|
||||||||||||||
| Expand Down Expand Up | @@ -2128,6 +2161,7 @@ | |||||||||||||
| // an UCD instance. | ||||||||||||||
| static PyMethodDef unicodedata_functions[] = { | ||||||||||||||
| // Module only functions. | ||||||||||||||
| UNICODEDATA_BLOCK_METHODDEF | ||||||||||||||
| UNICODEDATA_GRAPHEME_CLUSTER_BREAK_METHODDEF | ||||||||||||||
| UNICODEDATA_INDIC_CONJUNCT_BREAK_METHODDEF | ||||||||||||||
| UNICODEDATA_EXTENDED_PICTOGRAPHIC_METHODDEF | ||||||||||||||
| Expand All | @@ -2137,7 +2171,7 @@ | |||||||||||||
|
|
||||||||||||||
| // The following definitions are shared between the module | ||||||||||||||
| // and the UCD class. | ||||||||||||||
| #define DB_methods (unicodedata_functions + 6) | ||||||||||||||
| #define DB_methods (unicodedata_functions + 7) | ||||||||||||||
|
|
||||||||||||||
| UNICODEDATA_UCD_DECIMAL_METHODDEF | ||||||||||||||
| UNICODEDATA_UCD_DIGIT_METHODDEF | ||||||||||||||
| Expand Down | ||||||||||||||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.