Skip to content

Conversation

ewanmellor
Copy link
Contributor

Swift 4.0.2 brings a new deprecation warning for String.characters. These changes address the places where we were using the deprecated functions, and have otherwise fallen out of sync with the changes to the Swift String API.

In StringExtension, remove some functions that are no longer used, and update the rest to Swift 4's String API. lastIndexOf changes to lastIndex(of: ), matching the standard library naming conventions, and returns a String.Index? instead of an Int.

Add an implementation of Substring.hasPrefix for Linux; this is in the Apple standard library but not the Linux one. https://bugs.swift.org/browse/SR-5627

Add unit tests for StringExtension.

Rewrite ParseTreePatternMatcher to use standard library String functions and avoid our custom String extensions.

Bump the Swift download for the Travis Linux tests from 4.0 to 4.0.2. There is a bug in Substring.range(of:) in 4.0.0 (https://bugs.swift.org/browse/SR-5663) that we need to avoid.

Remove the toString implementations, in favor of CustomStringConvertible.description.

Remove the uses of StringBuilder where it is simply accumulating a String for us. In Swift we can use a var String for this; there is no need for a StringBuilder class like in Java. Change TokenStreamRewriter to use an inout String as the execute(buf:) parameter rather than StringBuilder. Remove StringBuilder entirely.

Rewrite RuntimeMetaData.getMajorMinorVersion to use standard library String functions and avoid our custom String extensions. Addtests for RuntimeMetaData.getMajorMinorVersion.

This PR depends on #2100 and #2101 due to merge conflicts.

The implementation here before just tried to make a UUID from the empty
string.

Remove the unused UUID.toUUID.  It was broken too.

Rename the file that this was in, since NSUUID and Foundation.UUID are not
the same thing.
Fix the parsing inside ParseTreePatternMatcher.split.  It was trivially
broken in a number of ways, with bugs that aren't in the Java version
that it was ported from, so it's obviously never been run before.

This adds unit tests for ParseTreePatternMatcher.split, and makes Chunk
implement Equatable, so that it we can compare Chunk instances in the
tests.

Tidy up the description implementations at the same time.
String functions and avoid our custom String extensions.
Remove the uses of StringBuilder where it is simply accumulating a String
for us.  In Swift we can use a var String for this; there is no need for
a StringBuilder class like in Java.
parameter rather than StringBuilder.

Tidy up the rest of the class on the way through.

This is the last use of StringBuilder, so we can remove that class entirely.
In Swift, we use description for the same thing.  All these just stubbed-over
or replicated the description implementation, except for PredicateTransition
which now implements CustomStringConvertible.
…ngs.

In Swift 4, Strings have a set of sequence operations that we can use, so
that we don't need our String extensions.  Tidy up a bunch of places where
the code has been converted from Java through Swift 3 and Swift 4, and
become a mess.
String functions and avoid our custom String extensions.
Remove some functions that are no longer used, and update the
rest to Swift 4's String API.  lastIndexOf changes to lastIndex(of: ),
matching the standard library naming conventions, and returns a
String.Index? instead of an Int.

Add an implementation of Substring.hasPrefix for Linux; this
is in the Apple standard library but not the Linux one.
https://bugs.swift.org/browse/SR-5627

Add unit tests for StringExtension.

Bump the Swift download for the Travis Linux tests from 4.0
to 4.0.2.  There is a bug in Substring.range(of:) in 4.0.0
(https://bugs.swift.org/browse/SR-5663) that we need to avoid.
@parrt parrt added this to the 4.7.1 milestone Nov 29, 2017
@parrt parrt merged commit 84e9a46 into antlr:master Nov 29, 2017
@ewanmellor ewanmellor deleted the swift-fix-deprecated-string-methods branch November 30, 2017 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants