Skip to content

Commit 57f25c4

Browse files
committed
Update Boyer Moore to Swift 4.2
1 parent 35dcda0 commit 57f25c4

File tree

8 files changed

+36
-25
lines changed

8 files changed

+36
-25
lines changed

Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
//: Playground - noun: a place where people can play
22

3-
// last checked with Xcode 9.0b4
4-
#if swift(>=4.0)
5-
print("Hello, Swift 4!")
6-
#endif
7-
83
/*
94
Boyer-Moore string search
105

@@ -16,13 +11,13 @@ extension String {
1611
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? {
1712
// Cache the length of the search pattern because we're going to
1813
// use it a few times and it's expensive to calculate.
19-
let patternLength = pattern.characters.count
20-
guard patternLength > 0, patternLength <= characters.count else { return nil }
14+
let patternLength = pattern.count
15+
guard patternLength > 0, patternLength <= count else { return nil }
2116

2217
// Make the skip table. This table determines how far we skip ahead
2318
// when a character from the pattern is found.
2419
var skipTable = [Character: Int]()
25-
for (i, c) in pattern.characters.enumerated() {
20+
for (i, c) in pattern.enumerated() {
2621
skipTable[c] = patternLength - i - 1
2722
}
2823

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Boyer-Moore-Horspool/BoyerMooreHorspool.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ extension String {
99
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? {
1010
// Cache the length of the search pattern because we're going to
1111
// use it a few times and it's expensive to calculate.
12-
let patternLength = pattern.characters.count
13-
guard patternLength > 0, patternLength <= characters.count else { return nil }
12+
let patternLength = pattern.count
13+
guard patternLength > 0, patternLength <= count else { return nil }
1414

1515
// Make the skip table. This table determines how far we skip ahead
1616
// when a character from the pattern is found.
1717
var skipTable = [Character: Int]()
18-
for (i, c) in pattern.characters.enumerated() {
18+
for (i, c) in pattern.enumerated() {
1919
skipTable[c] = patternLength - i - 1
2020
}
2121

Boyer-Moore-Horspool/Tests/BoyerMooreTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class BoyerMooreTest: XCTestCase {
2626
XCTAssertNotNil(index)
2727

2828
let startIndex = index!
29-
let endIndex = string.index(index!, offsetBy: pattern.characters.count)
30-
let match = string.substring(with: startIndex..<endIndex)
29+
let endIndex = string.index(index!, offsetBy: pattern.count)
30+
let match = String(string[startIndex..<endIndex])
3131
XCTAssertEqual(match, pattern)
3232
}
3333

Boyer-Moore-Horspool/Tests/Tests.xcodeproj/project.pbxproj

+8-6
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@
7878
isa = PBXProject;
7979
attributes = {
8080
LastSwiftUpdateCheck = 0720;
81-
LastUpgradeCheck = 0900;
81+
LastUpgradeCheck = 1000;
8282
ORGANIZATIONNAME = "Swift Algorithm Club";
8383
TargetAttributes = {
8484
7B2BBC7F1C779D720067B71D = {
8585
CreatedOnToolsVersion = 7.2;
86-
LastSwiftMigration = 0900;
86+
LastSwiftMigration = "";
8787
};
8888
};
8989
};
@@ -157,12 +157,14 @@
157157
CLANG_WARN_BOOL_CONVERSION = YES;
158158
CLANG_WARN_COMMA = YES;
159159
CLANG_WARN_CONSTANT_CONVERSION = YES;
160+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
160161
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
161162
CLANG_WARN_EMPTY_BODY = YES;
162163
CLANG_WARN_ENUM_CONVERSION = YES;
163164
CLANG_WARN_INFINITE_RECURSION = YES;
164165
CLANG_WARN_INT_CONVERSION = YES;
165166
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
167+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
166168
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
167169
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
168170
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -210,12 +212,14 @@
210212
CLANG_WARN_BOOL_CONVERSION = YES;
211213
CLANG_WARN_COMMA = YES;
212214
CLANG_WARN_CONSTANT_CONVERSION = YES;
215+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
213216
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
214217
CLANG_WARN_EMPTY_BODY = YES;
215218
CLANG_WARN_ENUM_CONVERSION = YES;
216219
CLANG_WARN_INFINITE_RECURSION = YES;
217220
CLANG_WARN_INT_CONVERSION = YES;
218221
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
222+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
219223
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
220224
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
221225
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -252,8 +256,7 @@
252256
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
253257
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
254258
PRODUCT_NAME = "$(TARGET_NAME)";
255-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
256-
SWIFT_VERSION = 4.0;
259+
SWIFT_VERSION = 4.2;
257260
};
258261
name = Debug;
259262
};
@@ -265,8 +268,7 @@
265268
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
266269
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
267270
PRODUCT_NAME = "$(TARGET_NAME)";
268-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
269-
SWIFT_VERSION = 4.0;
271+
SWIFT_VERSION = 4.2;
270272
};
271273
name = Release;
272274
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Boyer-Moore-Horspool/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "1000"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
<TestableReference
@@ -47,7 +46,6 @@
4746
buildConfiguration = "Debug"
4847
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4948
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
50-
language = ""
5149
launchStyle = "0"
5250
useCustomWorkingDirectory = "NO"
5351
ignoresPersistentStateOnLaunch = "NO"

swift-algorithm-club.xcworkspace/contents.xcworkspacedata

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)