> On Jan 6, 2016, at 10:30 AM, Don Wills <don.wi...@portablesoftware.com> wrote:
>
> 1. The lack a Character type that are the constituent elements of a String
> 2. Missing methods (Java names used): valueOf, charAt, trim(), length(),
No offense, but it sounds like you haven’t read the justifications in the Swift
book or on the web. The short form: Unicode is complicated, necessarily so
because human writing is complicated. Even the notion of a “character” is
problematic. To quote from objc.io's (prerelease) Advanced Swift book: "But
even when encoded using 32-bit code units, what a user might consider 'a single
character' — as displayed on the screen — might require multiple code points
composed together. Most string manipulation code exhibits a certain level of
denial about Unicode’s variable-width nature. This can lead to some unpleasant
bugs.”
charAt isn’t available because a String is not just a simple “array of
characters” as in older / more simplistic languages. Ditto with length.
valueOf IIRC is for converting to/from integers — there are methods on the
integer types for that.
trim is one of those methods that is supplied in the Foundation framework,
which hasn’t been ported to a Swift-native version yet so isn’t available
outside Apple platforms.
> getBytes(), toUpperCase(), toLowerCase()
getBytes is basically a UTF-8 view.
Upper/lowercase conversions are again part of Foundation.
> 3. The lack of the + operator for appending
You can add this in a couple of lines of code if it’s important to you.
> 4. The lack of a StringBuilder (Java again) class
Apples and oranges. Java needs StringBuilder/StringBuffer because its String is
always immutable. In Swift mutability is an aspect of the variable containing
the String, so the String class itself contains mutating methods.
—Jens
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users