Loading ...
Sorry, an error occurred while loading the content.

Making STRING features safe in descendants

Expand Messages
  • Roger Browne
    Here are the proposed changes to make STRING features typesafe in descendants. There is no change from what was previously discussed - but I had not yet
    Message 1 of 2 , Jun 4, 2001
    • 0 Attachment
      Here are the proposed changes to make STRING features typesafe in
      descendants.

      There is no change from what was previously discussed - but I had not yet
      previously posted the complete revised specifications.

      4 JUNE 2001 VERSIONS

      > substring_index
      > change 'is_equal' to 'same_string'

      substring_index (other: STRING; start_index: INTEGER): INTEGER
      -- Index of first occurrence of `other' at or after `start_index';
      -- 0 if none.
      require
      other_not_void: other /= void
      valid_start_index:
      start_index >= 1 and start_index <= count + 1
      ensure
      valid_result: Result = 0 or else
      (start_index <= Result and Result <= count - other.count + 1)
      zero_if_absent: (Result = 0) =
      not substring (start_index, count).has_substring (other)
      at_this_index: Result >= start_index implies
      other.same_string (substring (Result, Result + other.count -
      1))
      none_before: Result > start_index implies
      not substring (start_index, Result + other.count - 2)
      .has_substring (other)

      > has_substring
      > change 'is_equal' to 'same_string'

      has_substring (other: STRING): BOOLEAN
      -- Does 'current' contain 'other'?
      require
      other_not_void: other /= Void
      ensure
      false_if_too_small: count < other.count implies not Result
      true_if_initial: (count >= other.count and then
      other.same_string (substring (1, other.count))) implies
      Result
      recurse: (count >= other.count and then
      not other.same_string (substring (1, other.count))) implies
      (Result = substring (2, count).has_substring (other))

      > as_lower
      > change result type from STRING to "like current"

      as_lower: like current
      -- New string with all letters in lower case.
      ensure
      length: Result.count = count
      anchor: count > 0 implies Result.item(1) = item(1).as_lower
      recurse: count > 1 implies Result.substring(2, count)
      .is_equal(substring(2, count).as_lower)

      > as_upper
      > change result type from STRING to "like current"

      as_upper: like current
      -- New string with all letters in upper case.
      ensure
      length: Result.count = count
      anchor: count > 0 implies Result.item(1) = item(1).as_upper
      recurse: count > 1 implies Result.substring(2, count)
      .is_equal(substring(2, count).as_upper)

      > is_boolean
      > change 'is_equal' to 'same_string'

      is_boolean: BOOLEAN
      -- Does 'current' represent a BOOLEAN?
      ensure
      is_boolean: result = (same_string("true")
      or same_string("false"))

      > to_boolean
      > change 'is_equal' to 'same_string'

      to_boolean: BOOLEAN
      -- Boolean value;
      -- "true" yields true, "false" yields false
      require
      represents_a_boolean: is_boolean
      ensure
      to_boolean: result = same_string("true")

      > infix "+"
      > in the "final" assertion only, change 'is_equal'
      > to 'same_string'

      infix "+" (other: STRING): like Current
      -- Create a new object which is the concatenation of Current and
      other.
      require
      other_exists: other /= Void
      ensure
      result_not_void: Result /= Void
      result_count: Result.count = count + other.count
      initial: Result.substring (1, count).is_equal (Current)
      final: Result.substring (count + 1, count + other.count)
      .same_string (other)

      If no new issues arise, I'll run the vote in a day or so.

      Regards,
      Roger
      --
      Roger Browne - roger@... - Everything Eiffel
      19 Eden Park Lancaster LA1 4SJ UK - Phone +44 1524 32428
    • Eric Bezault
      ... I don t remember whether we already had a discussion about the semantics of `is_boolean . What is the semantics currently supported by the different Eiffel
      Message 2 of 2 , Jun 4, 2001
      • 0 Attachment
        Roger Browne wrote:
        >
        > is_boolean: BOOLEAN
        > -- Does 'current' represent a BOOLEAN?
        > ensure
        > is_boolean: result = (same_string("true")
        > or same_string("false"))

        I don't remember whether we already had a discussion about
        the semantics of `is_boolean'. What is the semantics currently
        supported by the different Eiffel compilers? I'm pretty sure
        that some of them (if not all) have the following semantics:

        ensure
        is_boolean: Result = (as_lower.same_string ("true")
        or as_lower.same_string ("false"))

        --
        Eric Bezault
        mailto:ericb@...
        http://www.gobosoft.com
      Your message has been successfully submitted and would be delivered to recipients shortly.