; [NSString lispString]: clarify unpaired surrogate behaviour

This commit is contained in:
Mattias Engdegård 2023-08-10 10:56:21 +02:00
parent 2026cba0c9
commit f48e47fb49

View file

@ -3797,7 +3797,7 @@ - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
}
/* Count the number of characters in STR, NBYTES long.
The string is valid UTF-8 except that it may contain unpaired surrogates. */
The string must be valid UTF-8. */
static ptrdiff_t
count_utf8_chars (const char *str, ptrdiff_t nbytes)
{
@ -3861,6 +3861,8 @@ handled fairly well by the NS libraries (displayed with distinct
/* Make a Lisp string from an NSString. */
- (Lisp_Object)lispString
{
/* If the input string includes unpaired surrogates, then the result
will be an empty string. */
const char *utf8 = [self UTF8String];
ptrdiff_t bytes = [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
return make_multibyte_string (utf8, count_utf8_chars (utf8, bytes), bytes);