nitcorn/file_server: extract answer_file method
[nit.git] / lib / core / fixed_ints.nit
index daad211..f2f3890 100644 (file)
@@ -158,6 +158,9 @@ universal Int8
        redef fun to_i32 is intern
        redef fun to_u32 is intern
 
+       # Returns `self` as a Char according to its ASCII value.
+       fun ascii: Char `{ return (uint32_t)self; `}
+
        redef fun distance(i) do return (self - i).to_i
 
        redef fun <=>(other)
@@ -271,6 +274,9 @@ universal Int16
        redef fun *(i) is intern
        redef fun /(i) is intern
 
+       # Returns `self` as a Char according to its ASCII value.
+       fun ascii: Char `{ return (uint32_t)self; `}
+
        # Modulo of `self` with `i`.
        #
        # Returns the remainder of division of `self` by `i`.
@@ -425,6 +431,9 @@ universal UInt16
        redef fun zero do return 0.to_u16
        redef fun value_of(val) do return val.to_u16
 
+       # Returns `self` as a Char according to its ASCII value.
+       fun ascii: Char `{ return (uint32_t)self; `}
+
        # `i` bits shift to the left
        #
        #     assert 5u16 << 1    == 10u16
@@ -558,6 +567,9 @@ universal Int32
        redef fun *(i) is intern
        redef fun /(i) is intern
 
+       # Returns `self` as a Char according to its ASCII value.
+       fun ascii: Char `{ return (uint32_t)self; `}
+
        # Modulo of `self` with `i`.
        #
        # Returns the remainder of division of `self` by `i`.
@@ -701,6 +713,9 @@ universal UInt32
        redef fun *(i) is intern
        redef fun /(i) is intern
 
+       # Returns `self` as a Char according to its ASCII value.
+       fun ascii: Char `{ return (uint32_t)self; `}
+
        # Modulo of `self` with `i`.
        #
        # Returns the remainder of division of `self` by `i`.
@@ -818,7 +833,7 @@ redef class Text
 
        # Removes the numeric head of `self` if present
        #
-       #     intrude import standard::fixed_ints
+       #     intrude import core::fixed_ints
        #     assert "0xFFEF".strip_numhead  == "FFEF"
        #     assert "0o7364".strip_numhead  == "7364"
        #     assert "0b01001".strip_numhead == "01001"
@@ -831,7 +846,7 @@ redef class Text
        # Gets the numeric head of `self` if present
        # Returns "" otherwise
        #
-       #     intrude import standard::fixed_ints
+       #     intrude import core::fixed_ints
        #     assert "0xFEFF".get_numhead  == "0x"
        #     assert "0b01001".get_numhead == "0b"
        #     assert "0o872".get_numhead   == "0o"
@@ -848,7 +863,7 @@ redef class Text
 
        # Removes the numeric extension if present
        #
-       #     intrude import standard::fixed_ints
+       #     intrude import core::fixed_ints
        #     assert "0xFEFFu8".strip_numext  == "0xFEFF"
        #     assert "0b01001u8".strip_numext == "0b01001"
        #     assert "0o872u8".strip_numext   == "0o872"
@@ -862,7 +877,7 @@ redef class Text
        # Gets the numeric extension (i/u 8/16/32) in `self` is present
        # Returns "" otherwise
        #
-       #     intrude import standard::fixed_ints
+       #     intrude import core::fixed_ints
        #     assert "0xFEFFu8".get_numext  == "u8"
        #     assert "0b01001u8".get_numext == "u8"
        #     assert "0o872u8".get_numext   == "u8"
@@ -884,11 +899,14 @@ redef class Text
        #     assert not "0x_".is_int
        #     assert not "0xGE".is_int
        #     assert not "".is_int
+       #     assert not "Not an Int".is_int
+       #     assert not "-".is_int
        fun is_int: Bool do
                if bytelen == 0 then return false
                var s = remove_all('_')
                var pos = 0
-               while s[pos] == '-' do
+               var len = s.length
+               while pos < len and s[pos] == '-' do
                        pos += 1
                end
                s = s.substring_from(pos)
@@ -898,7 +916,7 @@ redef class Text
                if hd == "0x" or hd == "0X" then return rets.is_hex
                if hd == "0b" or hd == "0B" then return rets.is_bin
                if hd == "0o" or hd == "0O" then return rets.is_oct
-               return hd.is_dec
+               return rets.is_dec
        end
 
        redef fun to_i