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 ncstrwidth() that returns column width of valid prefix #2153

Closed
dankamongmen opened this issue Sep 8, 2021 · 0 comments
Closed

add ncstrwidth() that returns column width of valid prefix #2153

dankamongmen opened this issue Sep 8, 2021 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@dankamongmen
Copy link
Owner

ncstrwidth() returns the column width of a utf8 string, but returns -1 if any element is invalid. depending on a given libc's unicode conformance, valid utf8 might not be recognized. ncplane_put*() will output up to the first invalid input. we ought then have an analogue, call it ehhhhh ncstrwidth_valid() (better name?):

int ncstrwidth_valid(const char* egcs, int* validbytes, *validwidth);

which will write into a non-NULL validbytes the length in bytes of the valid prefix, and write into a non-NULL validwidth the length in columns of the valid prefix. if the return value is non-negative, all input was processed (and the return value will be equal to *validwidth). if it is negative, there was an invalid character.

we could just return one or the other as the negative magnitude, but that's kinda sleazy imho (though i think we do it for ncplane_put*() actually, so maybe we ought do so here as well, for conformity?).

ncstrwidth() ought then be implemented as a static inline wrapper around this function, though that won't fly until ABI3; we'll need keep it a symbol for now.

@dankamongmen dankamongmen added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 8, 2021
@dankamongmen dankamongmen added this to the 3.0.0 milestone Sep 8, 2021
@dankamongmen dankamongmen self-assigned this Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant