Repository navigation
utf8.c: do not encode or decode after the terminating NUL byte - #285
Explorer09 wants to merge 1 commit into
Conversation
A C string can terminate before the specified string size (`n`). By terminating the decode operation at the NUL byte, this function can be more useful for encoding and decoding strings in C. **This change affects function behavior.** The client code can enclose the wcwidth_decode_u32() call within a loop to retain the old behavior. On the other hand, without this behavior change, the client code will have to call strlen() (or strnlen()) to ensure it doesn't over-specify the length of the string. Such a procedure is more tedious. Signed-off-by: Kang-Che Sung <[email protected]>
|
This PR contains an error, using assignment But also that the behavior is intentional ! As a library for measuring strings for terminal width, NUL can be sent to a terminal, even used for timed delays in some cases, and so NUL is measured, as zero-width. We do wish to be able to measure strings that contain NUL,
I will duplicate this documented behavior in the docstring of |
Try to prevent PR's like #285 by duplicating documentation about it, and making it shorter and more direct
A C string can terminate before the specified string size (
n). By terminating the decode operation at the NUL byte, this function can be more useful for encoding and decoding strings in C.This change affects function behavior.
The client code can enclose the wcwidth_decode_u32() call within a loop to retain the old behavior. On the other hand, without this behavior change, the client code will have to call strlen() (or strnlen()) to ensure it doesn't over-specify the length of the string. Such a procedure is more tedious.