From 71886eb0226af1caec7c951b86d47852948c4779 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 16 Sep 2015 13:55:08 -0400 Subject: [PATCH] lib: Changes in the way ascii is coded and its semantics. Old ascii method is replaced by code_point, which returns the Unicode code-point value of a Char ascii now returns a byte and requires a <= 127 code_point to work properly Signed-off-by: Lucas Bajolet --- lib/core/kernel.nit | 32 ++++++++++++++++++++++++-------- src/compiler/abstract_compiler.nit | 24 ------------------------ 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/lib/core/kernel.nit b/lib/core/kernel.nit index b2ac524..a8ec1c5 100644 --- a/lib/core/kernel.nit +++ b/lib/core/kernel.nit @@ -797,11 +797,12 @@ universal Int end end - # The character whose ASCII value is `self`. + # The character which code point (unicode-wise) is `self` # - # assert 65.ascii == 'A' - # assert 10.ascii == '\n' - fun ascii: Char is intern + # assert 65.code_point == 'A' + # assert 10.code_point == '\n' + # assert 0x220B.code_point == '∋' + fun code_point: Char `{ return (uint32_t)self; `} # Number of digits of an integer in base `b` (plus one if negative) # @@ -942,11 +943,26 @@ universal Char end end - # the ascii value of self + # The ascii value of `self` # - # assert 'a'.ascii == 97 - # assert '\n'.ascii == 10 - fun ascii: Int is intern + # assert 'a'.ascii == 97u8 + # assert '\n'.ascii == 10u8 + # + # REQUIRE: `is_ascii` + fun ascii: Byte do return code_point.to_b + + # The unicode code point value of `self` + # + # assert 'A'.code_point == 65 + # assert '\n'.code_point == 10 + # assert '∋'.code_point == 0x220B + fun code_point: Int `{ return (long)self; `} + + # Is `self` an ASCII character ? + # + # assert 'x'.is_ascii + # assert not 'ま'.is_ascii + fun is_ascii: Bool do return code_point <= 127 # Return the lower case version of self. # If self is not a letter, then return self diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 2f83449..d60ebb9 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -2243,9 +2243,6 @@ redef class AMethPropdef else if pname == "to_b" then v.ret(v.new_expr("(unsigned char){arguments[0]}", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("(uint32_t){arguments[0]}", ret.as(not null))) - return true end else if cname == "Char" then if pname == "object_id" then @@ -2279,9 +2276,6 @@ redef class AMethPropdef else if pname == "to_i" then v.ret(v.new_expr("{arguments[0]}-'0'", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("(long){arguments[0]}", ret.as(not null))) - return true end else if cname == "Byte" then if pname == "output" then @@ -2351,9 +2345,6 @@ redef class AMethPropdef else if pname == "to_u32" then v.ret(v.new_expr("(uint32_t){arguments[0]}", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("{arguments[0]}", ret.as(not null))) - return true end else if cname == "Bool" then if pname == "output" then @@ -2539,9 +2530,6 @@ redef class AMethPropdef else if pname == "to_f" then v.ret(v.new_expr("(double){arguments[0]}", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("{arguments[0]}", ret.as(not null))) - return true else if pname == "&" then v.ret(v.new_expr("{arguments[0]} & {arguments[1]}", ret.as(not null))) return true @@ -2641,9 +2629,6 @@ redef class AMethPropdef else if pname == "unary ~" then v.ret(v.new_expr("~{arguments[0]}", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("{arguments[0]}", ret.as(not null))) - return true end else if cname == "UInt16" then if pname == "output" then @@ -2731,9 +2716,6 @@ redef class AMethPropdef else if pname == "unary ~" then v.ret(v.new_expr("~{arguments[0]}", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("{arguments[0]}", ret.as(not null))) - return true end else if cname == "Int32" then if pname == "output" then @@ -2821,9 +2803,6 @@ redef class AMethPropdef else if pname == "unary ~" then v.ret(v.new_expr("~{arguments[0]}", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("{arguments[0]}", ret.as(not null))) - return true end else if cname == "UInt32" then if pname == "output" then @@ -2911,9 +2890,6 @@ redef class AMethPropdef else if pname == "unary ~" then v.ret(v.new_expr("~{arguments[0]}", ret.as(not null))) return true - else if pname == "ascii" then - v.ret(v.new_expr("{arguments[0]}", ret.as(not null))) - return true end end if pname == "exit" then -- 1.7.9.5