lib: Added `is_surrogate` service to `Char`
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 14 Dec 2015 22:31:16 +0000 (17:31 -0500)
committerLucas Bajolet <r4pass@hotmail.com>
Thu, 17 Dec 2015 20:13:25 +0000 (15:13 -0500)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/core/text/abstract_text.nit

index 32628cd..17e4a23 100644 (file)
@@ -1600,6 +1600,12 @@ redef class Char
        #     assert 'ま'.bytes == [0xE3u8, 0x81u8, 0xBEu8]
        fun bytes: SequenceRead[Byte] do return to_s.bytes
 
+       # Is `self` an UTF-16 surrogate pair ?
+       fun is_surrogate: Bool do
+               var cp = code_point
+               return cp >= 0xD800 and cp <= 0xDFFF
+       end
+
        # Length of `self` in a UTF-8 String
        private fun u8char_len: Int do
                var c = self.code_point