From: Lucas Bajolet Date: Fri, 6 May 2016 15:42:39 +0000 (-0400) Subject: lib/core: Added surrogate detection methods to `Char` X-Git-Url: http://nitlanguage.org lib/core: Added surrogate detection methods to `Char` Signed-off-by: Lucas Bajolet --- diff --git a/lib/core/text/abstract_text.nit b/lib/core/text/abstract_text.nit index c15901e..6c2acd4 100644 --- a/lib/core/text/abstract_text.nit +++ b/lib/core/text/abstract_text.nit @@ -1755,6 +1755,18 @@ redef class Char return cp >= 0xD800 and cp <= 0xDFFF end + # Is `self` a UTF-16 high surrogate ? + fun is_hi_surrogate: Bool do + var cp = code_point + return cp >= 0xD800 and cp <= 0xDBFF + end + + # Is `self` a UTF-16 low surrogate ? + fun is_lo_surrogate: Bool do + var cp = code_point + return cp >= 0xDC00 and cp <= 0xDFFF + end + # Length of `self` in a UTF-8 String fun u8char_len: Int do var c = self.code_point