> On Feb 10, 2017, at 12:38 PM, Hooman Mehr via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> 
>> On Feb 9, 2017, at 6:50 PM, Shawn Erickson <shaw...@gmail.com 
>> <mailto:shaw...@gmail.com>> wrote:
>> 
>> 
>> 
>> On Thu, Feb 9, 2017 at 3:45 PM Hooman Mehr <hoo...@mac.com 
>> <mailto:hoo...@mac.com>> wrote:
>>> On Feb 9, 2017, at 3:11 PM, Dave Abrahams <dabrah...@apple.com 
>>> <mailto:dabrah...@apple.com>> 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.

On that last topic, NSAttributedString has always seemed like a strange design 
— a class with a bunch of attribute methods with a property that lets you 
interrogate the String behind it all. 

It always seemed to me that there was a false distinction. Strings should have 
optional properties, the way GameplayKit does GKEntities and GKComponents.

Simple Strings would return nil if you asked them for their attributes.

Attributed Strings would return attributes.

I think it would be a lot more intuitive how to parse an attributed string in 
blocks and then refer back to the attributes of each chunk, for one thing.

Is there a reason why composition was chosen to be the way it is in 
NSAttributedString, instead?

- Ron
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to