-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support command line Othello program
- Loading branch information
ysnrkdm
committed
Nov 9, 2016
1 parent
0ffa783
commit e7852b6
Showing
6 changed files
with
155 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Regex.swift | ||
// Graphite | ||
// | ||
// Created by KodamaYoshinori on 2016/11/06. | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
class Regexp { | ||
let internalRegexp: NSRegularExpression | ||
let pattern: String | ||
|
||
init(_ pattern: String) { | ||
self.pattern = pattern | ||
self.internalRegexp = try! NSRegularExpression( pattern: pattern, options: NSRegularExpression.Options.caseInsensitive) | ||
} | ||
|
||
func isMatch(input: String) -> Bool { | ||
let matches = self.internalRegexp.matches(in: input, options: [], range:NSMakeRange(0, input.characters.count)) | ||
return matches.count > 0 | ||
} | ||
|
||
func matches(input: String) -> [String]? { | ||
if self.isMatch(input: input) { | ||
let nsString = input as NSString | ||
if let matches = self.internalRegexp.firstMatch(in: input, options: [], range: NSMakeRange(0, nsString.length)) { | ||
var results: [String] = [] | ||
for i in 0 ..< matches.numberOfRanges { | ||
results.append((input as NSString).substring(with: matches.rangeAt(i))) | ||
} | ||
return results | ||
} | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters