FIXED: char_type/2 for unbound first argument.
Surrogate pairs form a gap in valid character codes, see:
https://github.com/mthom/scryer-prolog/issues/2326#issuecomment-1937864665
Many thanks to @Skgland for the pointer, and to @librarianmage for the
question that spawned this!
This addresses #2326.
This commit is contained in:
@@ -143,22 +143,17 @@ char_type(Char, Type) :-
|
|||||||
ctype(Type),
|
ctype(Type),
|
||||||
'$char_type'(Char, Type)
|
'$char_type'(Char, Type)
|
||||||
; ground(Type) ->
|
; ground(Type) ->
|
||||||
max_char_code(Max),
|
ccode(Code),
|
||||||
between(0, Max, Code),
|
|
||||||
char_code(Char, Code),
|
char_code(Char, Code),
|
||||||
'$char_type'(Char, Type)
|
'$char_type'(Char, Type)
|
||||||
; must_be(character, Char)
|
; must_be(character, Char)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
|
||||||
max_char_code(Max) :-
|
% 0xD800 to 0xDFFF are surrogate code points used by UTF-16.
|
||||||
catch((length(_, Code),
|
|
||||||
catch(char_code(_Char, Code),
|
ccode(Code) :- between(0, 0xD7FF, Code).
|
||||||
error(representation_error(_),_),
|
ccode(Code) :- between(0xE000, 0x10FFFF, Code).
|
||||||
throw(max_char_code(Code))),
|
|
||||||
false),
|
|
||||||
max_char_code(Code),
|
|
||||||
Max is Code - 1).
|
|
||||||
|
|
||||||
ctype(alnum).
|
ctype(alnum).
|
||||||
ctype(alpha).
|
ctype(alpha).
|
||||||
|
|||||||
Reference in New Issue
Block a user