Skip to content

Update build for iOS 13 / Swift 5 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SwiftOrg"
name: "SwiftOrg",
products: [
.library(
name: "SwiftOrg",
targets: ["SwiftOrg"])
],
targets: [
.target(
name: "SwiftOrg",
path: "Sources",
sources: [
"Regex.swift",
"Tokens.swift",
"String.swift",
"Timestamp.swift",
"Table.swift",
"SwiftOrg.h",
"Section.swift",
"Queue.swift",
"Paragraph.swift",
"OrgParser.swift",
"OrgFileWriter.swift",
"OrgDocument.swift",
"Node.swift",
"List.swift",
"Lexer.swift",
"Inline.swift",
"HorizontalRule.swift",
"Footnote.swift",
"Drawer.swift",
"Data.swift",
"ConvertToJSON.swift",
"Constants.swift",
"Comment.swift",
"Block.swift",
],
resources: [
.copy("Info-iOS.plist"),
.copy("Info-macOS.plist"),
]
),
.testTarget(
name: "SwiftOrgTests",
dependencies: ["SwiftOrg"]),
]
)
24 changes: 12 additions & 12 deletions Sources/Regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import Foundation

#if !os(Linux)
typealias RegularExpression = NSRegularExpression
typealias TextCheckingResult = NSTextCheckingResult
public typealias RegularExpression = NSRegularExpression
public typealias TextCheckingResult = NSTextCheckingResult
#else
extension TextCheckingResult {
func rangeAt(_ idx: Int) -> NSRange {
Expand Down Expand Up @@ -47,7 +47,7 @@ public extension String {
return []
case let n where n > 0:
for i in 0..<n {
let r = match.rangeAt(i)
let r = match.range(at: i)
matches.append(r.length > 0 ? NSString(string: self).substring(with: r) : nil)
}
default:
Expand All @@ -56,7 +56,7 @@ public extension String {
return matches
}

public func match(_ regex: String, options: RegularExpression.Options = []) -> [String?]? {
func match(_ regex: String, options: RegularExpression.Options = []) -> [String?]? {
let expression = self.getExpression(regex, options: options)

if let match = expression.firstMatch(in: self, options: [], range: NSMakeRange(0, self.utf16.count)) {
Expand All @@ -65,25 +65,25 @@ public extension String {
return nil
}

public func matchSplit(_ regex: String, options: RegularExpression.Options) -> [String] {
func matchSplit(_ regex: String, options: RegularExpression.Options) -> [String] {
let expression = self.getExpression(regex, options: options)
let matches = expression.matches(in: self, options: [], range: NSMakeRange(0, self.utf16.count))
var splitted = [String]()
var cursor = 0
for m in matches {
if m.range.location > cursor {
splitted.append(self.substring(with: self.characters.index(self.startIndex, offsetBy: cursor)..<self.characters.index(self.startIndex, offsetBy: m.range.location)))
splitted.append(self.substring(with: self.index(self.startIndex, offsetBy: cursor)..<self.index(self.startIndex, offsetBy: m.range.location)))
}
splitted.append(NSString(string: self).substring(with: m.range))
cursor = (m.range.toRange()?.upperBound)! + 1
}
if cursor <= self.characters.count {
splitted.append(self.substring(with: self.characters.index(self.startIndex, offsetBy: cursor)..<self.endIndex))
if cursor <= self.count {
splitted.append(self.substring(with: self.index(self.startIndex, offsetBy: cursor)..<self.endIndex))
}
return splitted
}

public func tryMatch(_ regex: String,
func tryMatch(_ regex: String,
options: RegularExpression.Options = [],
match: ([String?]) -> Void,
or: (String) -> Void) {
Expand All @@ -92,13 +92,13 @@ public extension String {
var cursor = 0
for m in matches {
if m.range.location > cursor {
or(self.substring(with: self.characters.index(self.startIndex, offsetBy: cursor)..<self.characters.index(self.startIndex, offsetBy: m.range.location)))
or(self.substring(with: self.index(self.startIndex, offsetBy: cursor)..<self.index(self.startIndex, offsetBy: m.range.location)))
}
match(getMatches(m))
cursor = (m.range.toRange()?.upperBound)!
}
if cursor < self.characters.count {
or(self.substring(with: self.characters.index(self.startIndex, offsetBy: cursor)..<self.endIndex))
if cursor < self.count {
or(self.substring(with: self.index(self.startIndex, offsetBy: cursor)..<self.endIndex))
}
}
}
2 changes: 1 addition & 1 deletion Sources/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ extension String {
}

func length(_ text: String?) -> Int {
return (text ?? "").characters.count
return (text ?? "").count
}
4 changes: 2 additions & 2 deletions Sources/Tokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func defineTokens() {
.setting(key: matches[1]!, value: matches[2]) }

define("^(\\*+)\\s+(.*)$") { matches in
.headline(stars: matches[1]!.characters.count, text: matches[2]) }
.headline(stars: matches[1]!.count, text: matches[2]) }

define("^\\s*(\(PlanningKeyword.all.joined(separator: "|"))):\\s+(.+)$") { matches in
let timestamp = Timestamp.from(string: matches[2]!)
Expand All @@ -84,7 +84,7 @@ func defineTokens() {
{ matches in
var params: [String]?
if let m3 = matches[3] {
params = m3.characters.split{$0 == " "}.map(String.init)
params = m3.split{$0 == " "}.map(String.init)
}
return .blockBegin(name: matches[2]!, params: params)
}
Expand Down
27 changes: 15 additions & 12 deletions SwiftOrg.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 03F9E6921D6041190080E872;
Expand Down Expand Up @@ -633,7 +634,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -649,7 +650,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.huxiaoxing.SwiftOrgTests-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -674,7 +675,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -698,7 +699,7 @@
PRODUCT_NAME = SwiftOrg;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -714,13 +715,13 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Sources/Info-iOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.huxiaoxing.SwiftOrg-iOS";
PRODUCT_NAME = SwiftOrg;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -736,12 +737,12 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Sources/Info-iOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.huxiaoxing.SwiftOrg-iOS";
PRODUCT_NAME = SwiftOrg;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -785,12 +786,13 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -831,11 +833,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -851,7 +854,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.huxiaoxing.SwiftOrgTests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -863,7 +866,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.huxiaoxing.SwiftOrgTests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down