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

String.CharacterView does not shift endIndex correctly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Invalid
    • Component/s: Standard Library
    • Labels:
      None
    • Environment:

      Swift 3.0 GM
      Swift 08e796342126cf5690ba9c1a6dc8eb7c70078fc9

      Description

      See the following snippet. This kind of shifting produces the expected result (referencing the same character) for every index except the pre-prepending endIndex:

      var characters = "This is a test".characters
      assert(characters.count == 14)
      
      let endBeforePrepending = characters.endIndex
      
      let insertedCharacters = "[PREPENDED]".characters
      assert(insertedCharacters.count == 11)
      
      characters.replaceSubrange(characters.startIndex..<characters.startIndex, with: insertedCharacters)
      
      let endAfterPrepending = characters.index(endBeforePrepending, offsetBy: insertedCharacters.count)
      assert(endAfterPrepending == characters.endIndex) // Fails. 24 != 25
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            kawa Karl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: