> On Feb 9, 2017, at 6:50 PM, Shawn Erickson <[email protected]> wrote:
> 
> 
> 
> On Thu, Feb 9, 2017 at 3:45 PM Hooman Mehr <[email protected] 
> <mailto:[email protected]>> wrote:
>> On Feb 9, 2017, at 3:11 PM, Dave Abrahams <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> 
>> on Thu Feb 09 2017, "Ted F.A. van Gaalen" <tedvgiosdev-AT-gmail.com 
>> <http://tedvgiosdev-at-gmail.com/>> wrote:
>> 
>>> Hello Shawn
>>> Just google with any programming language name and “string manipulation”
>>> and you have enough reading for a week or so :o)
>>> TedvG
>> 
>> That truly doesn't answer the question.  It's not, “why do people index
>> strings with integers when that's the only tool they are given for
>> decomposing strings?”  It's, “what do you have to do with strings that's
>> hard in Swift *because* you can't index them with integers?”
> 
> I have done some string processing. I have not encountered any algorithm 
> where an integer index is absolutely needed, but sometimes it might be the 
> most convenient. 
> 
> For example, there are valid reasons to keep side tables that hold indexes 
> into a string. (such as maintaining attributes that apply to a substring or 
> things like pre-computed positions of soft line breaks). It does not require 
> the index to be integer, but maintaining validity of those indexes after the 
> string is mutated requires being able to offset them back or forth from some 
> position on. These operations could be less verbose and easier if the index 
> happens to be integer or (efficiently) supports + - operators. Also, I know 
> there are other methods to deal with such things and mutating a large string 
> generally is a bad idea, but sometimes it is the easiest and most convenient 
> solution to the problem at hand.
> 
>  The end goal of this string is for human consumption right? So such 
> manipulation would need need to unicode aware in the modern world? ..or is it 
> for some other reason?
> 
> -Shawn

For an example of what I mean, see the source code of 
NS(Mutable)AttributedString 
<https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSAttributedString.swift>
 and note how most of the mutating methods of Mutable variant are not 
implemented yet...

So, a good example of where such indexing would be convenient, could be writing 
a swift-native AttributedString backed by Swift native String.


_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to