Uploaded image for project: 'Swift'
  1. Swift
  2. SR-2131

The empty string is not a prefix/suffix of itself (or any string)

    XMLWordPrintable

    Details

      Description

      Inspired by https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160718/024896.html.

      Currently, the empty string has unique prefix/suffix behavior compared to other strings:

      let E = ""
      let a = "a"  // any non-empty string
      let b = "b"  // any non-empty string
      
      a == a  // true
      a.hasPrefix(a)  // true
      a.hasSuffix(a)  // true
      (a+b).hasSuffix(b)  // true
      (b+a).hasPrefix(b)  // true
      
      E == E  // true
      E.hasPrefix(E)  // false
      E.hasSuffix(E)  // false
      (a+E).hasSuffix(E)  // false
      (E+a).hasPrefix(E)  // false
      

      This is consistent with NSString and Foundation but conflicts with other languages and with concatenation - for all non-empty strings a and b, (a+b) has a prefix of a and a suffix of b.

        Attachments

          Activity

            People

            Assignee:
            abl Alexander Lash
            Reporter:
            abl Alexander Lash
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: