lib/core: Added surrogate detection methods to `Char`
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 6 May 2016 15:42:39 +0000 (11:42 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 6 May 2016 15:42:39 +0000 (11:42 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/core/text/abstract_text.nit

index c15901e..6c2acd4 100644 (file)
@@ -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