work in progress | character

Class CHARACTER

SmallEiffel -0.77


expanded class interface CHARACTER

   -- 
   --  Note: An Eiffel CHARACTER is mapped as a C char or as a Java Byte.
   -- 

feature(s) from HASHABLE

   hash_code: INTEGER
      --  The hash-code value of Current.
      ensure
         good_hash_value: Result >= 0

feature(s) from COMPARABLE

   infix "<" (other: CHARACTER): BOOLEAN
      --  Comparison using code. 
      require
         other_exists: other /= Void
      ensure
         asymmetric: Result implies not (other < Current)

   infix "<=" (other: CHARACTER): BOOLEAN
      --  Comparison using code. 
      require
         other_exists: other /= Void
      ensure
         definition: Result = (Current < other or is_equal(other))

   infix ">" (other: CHARACTER): BOOLEAN
      --  Comparison using code. 
      require
         other_exists: other /= Void
      ensure
         definition: Result = (other < Current)

   infix ">=" (other: CHARACTER): BOOLEAN
      --  Comparison using code. 
      require
         other_exists: other /= Void
      ensure
         definition: Result = (other <= Current)

   in_range (lower, upper: like Current): BOOLEAN
      --  Return true if Current is in range [lower..upper]
      ensure
         Result = (Current >= lower and Current <= upper)

   compare (other: like Current): INTEGER
      --  If current object equal to other, 0;
      --  if smaller,  -1; if greater, 1.
      require
         other_exists: other /= Void
      ensure
         equal_zero: Result = 0 = is_equal(other);
         smaller_negative: Result = - 1 = Current < other;
         greater_positive: Result = 1 = Current > other

   three_way_comparison (other: like Current): INTEGER
      --  If current object equal to other, 0;
      --  if smaller,  -1; if greater, 1.
      require
         other_exists: other /= Void
      ensure
         equal_zero: Result = 0 = is_equal(other);
         smaller_negative: Result = - 1 = Current < other;
         greater_positive: Result = 1 = Current > other

   min (other: like Current): like Current
      --  Minimum of Current and other.
      require
         other /= Void
      ensure
         Result <= Current and then Result <= other;
         compare(Result) = 0 or else other.compare(Result) = 0

   max (other: like Current): like Current
      --  Maximum of Current and other.
      require
         other /= Void
      ensure
         Result >= Current and then Result >= other;
         compare(Result) = 0 or else other.compare(Result) = 0

feature(s) from CHARACTER_REF

   item: CHARACTER

feature(s) from CHARACTER_REF

   set_item (value: like item)

   code: INTEGER
      --  ASCII code of Current.
      --  No Sign-extended conversion.
      ensure
         Result.in_range(Minimum_character_code,Maximum_character_code)

   to_upper: CHARACTER
      --  Conversion to the corresponding upper case.

   to_lower: CHARACTER
      --  Conversion to the corresponding lower case.

feature(s) from CHARACTER_REF

   --  Object Printing :

   out_in_tagged_out_memory
      --  Append terse printable represention of current object
      --  in tagged_out_memory.

feature(s) from CHARACTER_REF

   --  Object Printing :

   fill_tagged_out_memory
      --  Append terse printable represention of current object
      --  in tagged_out_memory.

feature(s) from CHARACTER

   to_integer: INTEGER
      --  Sign-extended conversion.
      ensure
         Result.in_range(- 2 ^ Character_bits - 1,2 ^ (Character_bits - 1) - 1)

   value: INTEGER
      --  Gives the value of a decimal digit.
      require
         is_digit
      ensure
         Result.in_range(0,9)

   decimal_value: INTEGER
      --  Gives the value of a decimal digit.
      require
         is_digit
      ensure
         Result.in_range(0,9)

   binary_value: INTEGER
      --  Gives the value of a binary digit.
      require
         is_binary_digit
      ensure
         Result.in_range(0,1)

   octal_value: INTEGER
      --  Gives the value of an octal digit.
      require
         is_octal_digit
      ensure
         Result.in_range(0,7)

   hexadecimal_value: INTEGER
      --  Gives the value of an hexadecimal digit.
      require
         is_hexadecimal_digit
      ensure
         Result.in_range(0,15)

   same_as (other: CHARACTER): BOOLEAN
      --  Case insensitive comparison.
      --  No difference between upper/lower case letters.
      ensure
         Result implies to_lower = other or to_upper = other

   is_letter: BOOLEAN
      --  Is it a letter ?
      ensure
         Result = in_range('A','Z') or in_range('a','z')

   is_digit: BOOLEAN
      --  Belongs to '0'..'9'.
      ensure
         Result = in_range('0','9')

   is_decimal_digit: BOOLEAN
      --  Belongs to '0'..'9'.
      ensure
         Result = in_range('0','9')

   is_binary_digit: BOOLEAN
      --  Belongs to '0'..'1'.
      ensure
         Result = in_range('0','1')

   is_octal_digit: BOOLEAN
      --  Belongs to '0'..'7'.
      ensure
         Result = in_range('0','7')

   is_hexadecimal_digit: BOOLEAN
      --  Is it one character of "0123456789abcdefABCDEF" ?
      ensure
         Result = ("0123456789abcdefABCDEF").has(Current)

   is_lower: BOOLEAN
      --  Is item lowercase?

   is_upper: BOOLEAN
      --  Is item uppercase?

   is_separator: BOOLEAN
      --  True when character is a separator.

   is_letter_or_digit: BOOLEAN
      --  Is character a letter or digit ?
      ensure
         valid: Result = (is_letter or is_digit)

   is_ascii: BOOLEAN
      --  Is character a 8-bit ASCII character?

   is_bit: BOOLEAN
      --  True for 0 and 1.

   next: CHARACTER
      --  Give the next character (the following code);

   previous: CHARACTER
      --  Give the next character (the following code);
      require
         code > 0

feature(s) from CHARACTER

   --  Conversions :

   to_bit: BIT_N Character_bits

   to_hexadecimal: STRING
      --  Create a new STRING giving the code in hexadecimal.
      --  For example :
      --     (255).to_character.to_hexadecimal gives "FF".
      --  Note: see to_hexadecimal_in to save memory.
      ensure
         Result.count = 2

   to_hexadecimal_in (str: STRING)
      --  Append the equivalent of to_hexadecimal at the end of 
      --  str. Thus you can save memory because no other
      --  STRING is allocate for the job.
      ensure
         str.count = 2 + old str.count

end of expanded CHARACTER