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

add new utf8proc_codepoint_units function #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add new utf8proc_codepoint_units function #172

wants to merge 1 commit into from

Conversation

markand
Copy link

@markand markand commented Jan 28, 2020

I propose a simple function to determine the number of UTF-8 bytes that a codepoint require. This mostly addresses the issue #170

Example:

utf8proc_codepoint_units(233)    // é -> 2
utf8proc_codepoint_units(0x20ac) // € -> 3

@stevengj
Copy link
Member

Maybe utf8proc_sizeof_char?

@markand
Copy link
Author

markand commented Jan 29, 2020

Hmm, the term sizeof in C has special meaning, here the functions is meant to obtain a variable number between 0 and 4 which to me is the opposite of what "sizeof" sounds to me which always evaluates to a constant object size.

Other alternatives:

  • utf8proc_codepoint_utf8len
  • utf8proc_codepoint_mblength (multibyte length)
  • utf8proc_codepoint_length (pretty name but still confusing at a glance IMHO)

@stevengj
Copy link
Member

sizeof refers to a size in bytes, which is why it seems appropriate here.

@markand
Copy link
Author

markand commented Jan 29, 2020

Updated.

(void) argv; /* unused */

/* some simple sanity tests of */
for (c = 0; c < 0x80; c++) {
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to check consistency with utf8proc_encode_char, i.e. check utf8proc_sizeof_char(c) == utf8proc_encode_char(c, buf) where you declare utf8proc_uint8_t buf[4].

@stevengj
Copy link
Member

Not sure what the Travis failure is here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants