Skip to content

Commit

Permalink
Merge pull request JohnSundell#28 from artemnovichkov/master
Browse files Browse the repository at this point in the history
Refactor with Swift 4 String API
  • Loading branch information
JohnSundell authored Oct 21, 2017
2 parents a7e350f + 5f63dab commit 47afbf7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
4.0
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
os: linux
language: generic
osx_image: xcode9
sudo: required
dist: trusty
install:
Expand Down
7 changes: 4 additions & 3 deletions Sources/Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public class FileSystem {
}

let endIndex = name.index(name.endIndex, offsetBy: -`extension`.characters.count - 1)
return name.substring(to: endIndex)
return String(name[..<endIndex])
}

/// Any extension that the item has
Expand Down Expand Up @@ -355,7 +355,8 @@ public class FileSystem {
}

do {
let name = path.substring(from: path.index(path.startIndex, offsetBy: parentPath.characters.count + 1))
let index = path.index(path.startIndex, offsetBy: parentPath.characters.count + 1)
let name = String(path[index...])
return try createFolder(at: parentPath).createFile(named: name, contents: contents)
} catch {
throw File.Error.writeFailed
Expand Down Expand Up @@ -1033,7 +1034,7 @@ private extension FileManager {
var filledIn = false

while let parentReferenceRange = path.range(of: "../") {
let currentFolderPath = path.substring(to: parentReferenceRange.lowerBound)
let currentFolderPath = String(path[..<parentReferenceRange.lowerBound])

guard let currentFolder = try? Folder(path: currentFolderPath) else {
throw FileSystem.Item.PathError.invalid(path)
Expand Down

0 comments on commit 47afbf7

Please sign in to comment.