       of: target,
       with: replacement,
       options: options,
-      range: _toNSRange(searchRange ?? self.characters.indices)
+      range: _toNSRange(
+        searchRange ?? self.characters.startIndex..<self.characters.endIndex
+      )
     )
     : _ns.replacingOccurrences(of: target, with: replacement)
   }

  ) -> Range<Index>? {
    return _optionalRange(
      _ns.rangeOfCharacter(
        from: aSet, options: mask,
        range: _toNSRange(aRange ?? self.characters.indices)))
  }

  // - (NSRange)rangeOfComposedCharacterSequenceAtIndex:(NSUInteger)anIndex

    // dispatching to the minimal selector for the supplied options.
    // So let's do that; the switch should compile away anyhow.
    return locale != nil ? _ns.compare(
      aString,
      options: mask,
      range: _toNSRange(
        range ?? self.characters.startIndex..<self.characters.endIndex
      ),
      locale: locale
    )

    : range != nil ? _ns.compare(
      aString,
      options: mask,
      range: _toNSRange(range!)
    )

    : !mask.isEmpty ? _ns.compare(aString, options: mask)

