diff --git a/Package.swift b/Package.swift index bff15bf..0302e99 100644 --- a/Package.swift +++ b/Package.swift @@ -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"]), + ] ) diff --git a/Sources/Regex.swift b/Sources/Regex.swift index 4a523f6..40a5d90 100644 --- a/Sources/Regex.swift +++ b/Sources/Regex.swift @@ -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 { @@ -47,7 +47,7 @@ public extension String { return [] case let n where n > 0: for i in 0.. 0 ? NSString(string: self).substring(with: r) : nil) } default: @@ -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)) { @@ -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).. Void, or: (String) -> Void) { @@ -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).. Int { - return (text ?? "").characters.count + return (text ?? "").count } diff --git a/Sources/Tokens.swift b/Sources/Tokens.swift index 6db4803..02cad7f 100644 --- a/Sources/Tokens.swift +++ b/Sources/Tokens.swift @@ -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]!) @@ -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) } diff --git a/SwiftOrg.xcodeproj/project.pbxproj b/SwiftOrg.xcodeproj/project.pbxproj index a6979ea..a4c4e88 100644 --- a/SwiftOrg.xcodeproj/project.pbxproj +++ b/SwiftOrg.xcodeproj/project.pbxproj @@ -431,6 +431,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 03F9E6921D6041190080E872; @@ -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; }; @@ -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; }; @@ -674,7 +675,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -698,7 +699,7 @@ PRODUCT_NAME = SwiftOrg; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -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; }; @@ -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; }; @@ -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 = ""; @@ -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"; @@ -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; }; @@ -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; };