Merge: Extends chars, string and stream with some whitespace-related function
authorJean Privat <jean@pryen.org>
Sat, 7 Mar 2015 05:17:01 +0000 (12:17 +0700)
committerJean Privat <jean@pryen.org>
Sat, 7 Mar 2015 05:17:01 +0000 (12:17 +0700)
While thinking about the remaining task of #466 (simple parsing), I though that there useful functions where missing in order to have a sane `Reader::read_word` method

Pull-Request: #1179
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

1  2 
lib/standard/kernel.nit
tests/sav/nituml_args3.res
tests/sav/nituml_args4.res

diff --combined lib/standard/kernel.nit
@@@ -226,25 -226,6 +226,25 @@@ interface Discret
        end
  end
  
 +# Something that can be cloned
 +#
 +# This interface introduces the `clone` method used to duplicate an instance
 +# Its specific semantic is let to the subclasses.
 +interface Cloneable
 +      # Duplicate `self`
 +      #
 +      # The specific semantic of this method is let to the subclasses;
 +      # Especially, if (and how) attributes are cloned (depth vs. shallow).
 +      #
 +      # As a rule of thumb, the principle of least astonishment should
 +      # be used to guide the semantic.
 +      #
 +      # Note that as the returned clone depends on the semantic,
 +      # the `==` method, if redefined, should ensure the equality
 +      # between an object and its clone.
 +      fun clone: SELF is abstract
 +end
 +
  # A numeric value supporting mathematical operations
  interface Numeric
        super Comparable
@@@ -718,6 -699,22 +718,22 @@@ universal Cha
        do
                return is_lower or is_upper
        end
+       # Is self a whitespace character?
+       #
+       # These correspond to the "Other" and "Separator" groups of the Unicode.
+       #
+       # In the ASCII encoding, this is those <= to space (0x20) plus delete (0x7F).
+       #
+       #     assert 'A'.is_whitespace  == false
+       #     assert ','.is_whitespace  == false
+       #     assert ' '.is_whitespace  == true
+       #     assert '\t'.is_whitespace == true
+       fun is_whitespace: Bool
+       do
+               var i = ascii
+               return i <= 0x20 or i == 0x7F
+       end
  end
  
  # Pointer classes are used to manipulate extern C structures.
@@@ -30,11 -30,6 +30,11 @@@ Discrete 
  ]
  Comparable -> Discrete [dir=back arrowtail=open style=dashed];
  
 +Cloneable [
 + label = "{interface\nCloneable||+ clone(): SELF\l}"
 +]
 +Object -> Cloneable [dir=back arrowtail=open style=dashed];
 +
  Numeric [
   label = "{interface\nNumeric||+ +(i: OTHER): OTHER\l+ -(i: OTHER): OTHER\l+ unary -(): OTHER\l+ *(i: OTHER): OTHER\l+ /(i: OTHER): OTHER\l+ to_i(): Int\l+ to_f(): Float\l+ is_zero(): Bool\l+ zero(): OTHER\l+ value_of(val: Numeric): OTHER\l}"
  ]
@@@ -57,7 -52,7 +57,7 @@@ Discrete -> Int [dir=back arrowtail=ope
  Numeric -> Int [dir=back arrowtail=open style=dashed];
  
  Char [
-  label = "{Char||+ to_i(): Int\l+ ascii(): Int\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l}"
+  label = "{Char||+ to_i(): Int\l+ ascii(): Int\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}"
  ]
  Discrete -> Char [dir=back arrowtail=open style=dashed];
  
@@@ -30,11 -30,6 +30,11 @@@ Discrete 
  ]
  Comparable -> Discrete [dir=back arrowtail=open style=dashed];
  
 +Cloneable [
 + label = "{interface\nCloneable||+ clone(): SELF\l}"
 +]
 +Object -> Cloneable [dir=back arrowtail=open style=dashed];
 +
  Numeric [
   label = "{interface\nNumeric||+ +(i: OTHER): OTHER\l+ -(i: OTHER): OTHER\l+ unary -(): OTHER\l+ *(i: OTHER): OTHER\l+ /(i: OTHER): OTHER\l+ to_i(): Int\l+ to_f(): Float\l+ is_zero(): Bool\l+ zero(): OTHER\l+ value_of(val: Numeric): OTHER\l}"
  ]
@@@ -57,7 -52,7 +57,7 @@@ Discrete -> Int [dir=back arrowtail=ope
  Numeric -> Int [dir=back arrowtail=open style=dashed];
  
  Char [
-  label = "{Char||+ to_i(): Int\l+ ascii(): Int\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l}"
+  label = "{Char||+ to_i(): Int\l+ ascii(): Int\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}"
  ]
  Discrete -> Char [dir=back arrowtail=open style=dashed];