diff --git a/Source/Array.swift b/Source/Array.swift index 96940e8..dc53ff8 100755 --- a/Source/Array.swift +++ b/Source/Array.swift @@ -322,15 +322,15 @@ public struct Array // Subscrits // - func `prefix`(through: Int) -> [T] { + public func `prefix`(through: Int) -> [T] { return self[0...through] } - func `prefix`(upTo: Int) -> [T] { + public func `prefix`(upTo: Int) -> [T] { return self[0.. [T] { + public func suffix(from: Int) -> [T] { return self[from.. return nil } - func starts(with possiblePrefix: ISequence) -> Bool { + public func starts(with possiblePrefix: ISequence) -> Bool { var i = 0 for e in possiblePrefix { if !compareElements(e, self[i]) { @@ -417,7 +417,7 @@ public struct Array return true } - func starts(with possiblePrefix: [T]) -> Bool { + public func starts(with possiblePrefix: [T]) -> Bool { return starts(with: possiblePrefix.GetSequence()) } @@ -614,7 +614,7 @@ public struct Array return result } - func joined(separator: String) -> String { + public func joined(separator: String) -> String { #if JAVA | CLR | ISLAND let result = NativeStringBuilder() for i in 0.. } return result.ToString()! #elseif COCOA - return list.componentsJoinedByString(separator) + //return (list.componentsJoinedByString(separator) as NativeString) as! String // E129 Cannot cast from "NSString" to "String" + return String(list.componentsJoinedByString(separator)) #endif } @@ -704,7 +705,7 @@ public struct Array } @ToString - public override func description() -> String { + public override func description() -> NativeString { return list.description } } diff --git a/Source/Char_Extensions.swift b/Source/Char_Extensions.swift index dff1c25..344b314 100644 --- a/Source/Char_Extensions.swift +++ b/Source/Char_Extensions.swift @@ -50,14 +50,14 @@ public extension UnicodeScalar : Streamable { #if JAVA //workaround for 75341: Silver: Cooper: adding any interface to a struct via extension requires implementing `equals` and `hashCode`. - func equals(_ arg1: Object!) -> Boolean { + public func equals(_ arg1: Object!) -> Boolean { if let v = arg1 as? UnicodeScalar { return v == self } return false } - func hashCode() -> Integer { + public func hashCode() -> Integer { return value } #endif diff --git a/Source/Character.swift b/Source/Character.swift index 0d6c26d..2430a67 100644 --- a/Source/Character.swift +++ b/Source/Character.swift @@ -11,7 +11,7 @@ return UInt32(nativeStringValue[0]).toHexString(length: 4) } else if length(nativeStringValue) > 1 { var result = "" - var currentSurrogate: Char = "\0" + var currentSurrogate: Char = chr(0) for i in 0 ..< length(nativeStringValue) { let c = nativeStringValue[i] @@ -33,14 +33,14 @@ code += (surrogate & 0x03FF) << 10; code += (c & 0x03FF); newChar = UInt32(code).toHexString(length: 6) - currentSurrogate = "\0" + currentSurrogate = chr(0) } else { throw Exception("Invalid surrogate pair at index \(i)") } } if let newChar = newChar { - if length(result) > 0 { + if !result.isEmpty { result += "-" } result += newChar diff --git a/Source/Commandline.swift b/Source/Commandline.swift index ca855b2..cd22544 100644 --- a/Source/Commandline.swift +++ b/Source/Commandline.swift @@ -23,8 +23,8 @@ public func __stringArrayToCStringArray(_ arcv: [NativeString]) -> (UnsafePointe } #endif -public enum CommandLine { - public static var argc: Int32 { return __C_ARGC } - // public static var unsafeArgv: UnsafeMutablePointer?> - public static var arguments: [String] { return __C_ARGV } +public struct CommandLine { + public static var argc: Int32 { return __C_ARGC } + // public static var unsafeArgv: UnsafeMutablePointer?> + public static lazy let arguments: [String] = __C_ARGV.map({ $0 as! String }).ToList() } \ No newline at end of file diff --git a/Source/Dictionary.swift b/Source/Dictionary.swift index e73954e..7a9663a 100755 --- a/Source/Dictionary.swift +++ b/Source/Dictionary.swift @@ -380,7 +380,7 @@ public struct Dictionary /*: INSFastEnumeration*/ } @ToString - public override func description() -> String { + public override func description() -> NativeString { return dictionary.description } } diff --git a/Source/Dispatch.swift b/Source/Dispatch.swift index adee9db..9ee8ac4 100644 --- a/Source/Dispatch.swift +++ b/Source/Dispatch.swift @@ -101,7 +101,7 @@ public class DispatchQueue : DispatchObject { internal convenience init(__label: String, attr: dispatch_queue_attr_t?, queue: DispatchQueue?) { var raw: dispatch_queue_t if #defined(COCOA) { - raw = dispatch_queue_create_with_target(__label.UTF8String, attr, queue?.queue) + raw = dispatch_queue_create_with_target(__label.utf8CString, attr, queue?.queue) } else if #defined(DARWIN) { let array = Encoding.UTF8.GetBytes(__label+"\0") raw = dispatch_queue_create_with_target((&array[0]) as! UnsafePointer, attr, queue?.queue) @@ -123,7 +123,7 @@ public class DispatchQueue : DispatchObject { public var label: String { if #defined(COCOA) { - return NSString.stringWithUTF8String(dispatch_queue_get_label(queue)) + return String(utf8String: dispatch_queue_get_label(queue)) } else if #defined(DARWIN) { let label = dispatch_queue_get_label(queue) let len = strlen(label) @@ -197,7 +197,7 @@ public class DispatchQueue : DispatchObject { /*func getSpecific(key: DispatchSpecificKey) -> T? { //return dispatch_queue_get_specific(rawValue, key) } - func setSpecific(key: DispatchSpecificKey, value: T) { + public func setSpecific(key: DispatchSpecificKey, value: T) { //return dispatch_queue_set_specific(rawValue, key, value) }*/ } @@ -227,11 +227,11 @@ public class DispatchWorkItem { //return dispatch_wait(group.group, timeout.rawValue) } - func wait(timeout: DispatchWallTime) -> Int { + public func wait(timeout: DispatchWallTime) -> Int { //return dispatch_wait(group.group, timeout.rawValue) } - func notify(queue: DispatchQueue, execute notifyBlock: /*@convention(block)*/ () -> Void) { + public func notify(queue: DispatchQueue, execute notifyBlock: /*@convention(block)*/ () -> Void) { //dispatch_notify(group.group, queue.object, notifyBlock) }*/ @@ -259,11 +259,11 @@ public struct DispatchWorkItemFlags /*: OptionSet, RawRepresentable*/ { /*class DispatchSemaphore : DispatchObject { public init(value: Int) { } - func wait(timeout: DispatchTime /*= default*/) -> Int { + public func wait(timeout: DispatchTime /*= default*/) -> Int { } - func wait(walltime timeout: DispatchWallTime) -> Int { + public func wait(walltime timeout: DispatchWallTime) -> Int { } - func signal() -> Int { + public func signal() -> Int { } }*/ diff --git a/Source/Functions.swift b/Source/Functions.swift index e0164d3..27955f0 100644 --- a/Source/Functions.swift +++ b/Source/Functions.swift @@ -67,20 +67,20 @@ public func debugPrint(_ objects: Object?..., separator: String = " ", terminato return value } -public func fatalError(_ message: @autoclosure () -> String, file: String = #file, line: UInt32 = #line) -> Never { +public func fatalError(_ message: @autoclosure () -> String, file: NativeString = #file, line: UInt32 = #line) -> Never { if let message = message { __throw Exception(message()+", file "+file+", line "+line) } else { __throw Exception("Fatal Error, file "+file+", line "+line) } } -@Conditional("DEBUG") public func precondition(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String, file: String = #file, line: UWord = #line) { +@Conditional("DEBUG") public func precondition(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String, file: NativeString = #file, line: UWord = #line) { if (!condition()) { fatalError(message, file: file, line: line) } } -@Conditional("DEBUG") public func preconditionFailure(_ message: @autoclosure () -> String, file: String = #file, line: UWord = #line) -> Never { +@Conditional("DEBUG") public func preconditionFailure(_ message: @autoclosure () -> String, file: NativeString = #file, line: UWord = #line) -> Never { fatalError(message, file: file, line: line) } diff --git a/Source/Number_Constructors.swift b/Source/Number_Constructors.swift index ea3d30b..665bf66 100644 --- a/Source/Number_Constructors.swift +++ b/Source/Number_Constructors.swift @@ -6,8 +6,8 @@ fileprivate static func parseNumber(_ value: String) -> NSNumber? { let formatter = NSNumberFormatter() formatter.numberStyle = .decimalStyle formatter.locale = nil - if value.hasPrefix("+") && value.range(of: "-").location == NSNotFound { // NSNumberFormatter doesn't like +, strip it; - value = value.substring(fromIndex: 1) + if value.hasPrefix("+") && !value.contains("-") { // NSNumberFormatter doesn't like +, strip it; + value = value.suffix(from: 1) } return formatter.numberFromString(value) } diff --git a/Source/Sequence_Extensions.swift b/Source/Sequence_Extensions.swift index 5a527dc..71e1df2 100644 --- a/Source/Sequence_Extensions.swift +++ b/Source/Sequence_Extensions.swift @@ -79,7 +79,7 @@ public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silve return self.FirstOrDefault() } - func flatMap(@noescape _ transform: (T) throws -> T?) rethrows -> ISequence { + public func flatMap(@noescape _ transform: (T) throws -> T?) rethrows -> ISequence { for e in self { if let e = try! transform(e) { __yield e diff --git a/Source/Set.swift b/Source/Set.swift index 50dd292..350557b 100644 --- a/Source/Set.swift +++ b/Source/Set.swift @@ -206,7 +206,7 @@ public struct Set //: /// Returns the `Index` of a given member, or `nil` if the member is not /// present in the set. - func indexOf(member: T) -> /*SetIndex*/Int? { + public func indexOf(member: T) -> /*SetIndex*/Int? { #if JAVA if _set.contains(member) { return _set.indexOf(member) @@ -365,40 +365,40 @@ public struct Set //: /// Returns true if the set is a subset of a finite sequence as a `Set` /// but not equal. - func isStrictSubsetOf(sequence: S) -> Bool + public func isStrictSubsetOf(sequence: S) -> Bool /// Returns true if the set is a superset of a finite sequence as a `Set`. - func isSupersetOf(sequence: S) -> Bool + public func isSupersetOf(sequence: S) -> Bool /// Returns true if the set is a superset of a finite sequence as a `Set` /// but not equal. - func isStrictSupersetOf(sequence: S) -> Bool + public func isStrictSupersetOf(sequence: S) -> Bool /// Returns true if no members in the set are in a finite sequence as a `Set`. - func isDisjointWith(sequence: S) -> Bool + public func isDisjointWith(sequence: S) -> Bool /// Return a new `Set` with items in both this set and a finite sequence. - func union(sequence: S) -> Set + public func union(sequence: S) -> Set /// Insert elements of a finite sequence into this `Set`. mutating func unionInPlace(sequence: S) /// Return a new set with elements in this set that do not occur /// in a finite sequence. - func subtract(sequence: S) -> Set + public func subtract(sequence: S) -> Set /// Remove all members in the set that occur in a finite sequence. mutating func subtractInPlace(sequence: S) /// Return a new set with elements common to this set and a finite sequence. - func intersect(sequence: S) -> Set + public func intersect(sequence: S) -> Set /// Remove any members of this set that aren't also in a finite sequence. mutating func intersectInPlace(sequence: S) /// Return a new set with elements that are either in the set or a finite /// sequence but do not occur in both. - func exclusiveOr(sequence: S) -> Set + public func exclusiveOr(sequence: S) -> Set /// For each element of a finite sequence, remove it from the set if it is a /// common element, otherwise add it to the set. Repeated elements of the @@ -475,7 +475,7 @@ public struct Set //: //var hashValue: Int { get } /// A textual representation of `self`. - @ToString public func description() -> String { + @ToString public func description() -> NativeString { #if JAVA return _set.toString() #elseif CLR || ISLAND diff --git a/Source/String.Encoding.swift b/Source/String.Encoding.swift index 50a314d..e53acc4 100644 --- a/Source/String.Encoding.swift +++ b/Source/String.Encoding.swift @@ -66,7 +66,7 @@ public extension SwiftString { case "UTF32BE","UTF-32BE": return NSStringEncoding.UTF32BigEndianStringEncoding case "US-ASCII", "ASCII","UTF-ASCII": return NSStringEncoding.ASCIIStringEncoding default: - let encoding = CFStringConvertIANACharSetNameToEncoding(bridge(name)) + let encoding = CFStringConvertIANACharSetNameToEncoding(bridge(name.nativeStringValue)) if encoding != kCFStringEncodingInvalidId { return CFStringConvertEncodingToNSStringEncoding(encoding) as! NSStringEncoding } diff --git a/Source/String.Views.swift b/Source/String.Views.swift index 0839783..e631ac3 100644 --- a/Source/String.Views.swift +++ b/Source/String.Views.swift @@ -111,15 +111,15 @@ public extension SwiftString { var first: Character? { return count > 0 ? self[0] : nil } #endif - func `prefix`(through: Index) -> CharacterView { + public func `prefix`(through: Index) -> CharacterView { return CharacterView(stringData: stringData[0...through]) } - func `prefix`(upTo: Index) -> CharacterView { + public func `prefix`(upTo: Index) -> CharacterView { return CharacterView(stringData: stringData[0.. CharacterView { + public func suffix(from: Index) -> CharacterView { return CharacterView(stringData: stringData[from.. 0 ? self[0] : nil as? UTF16Char } - func `prefix`(through: Index) -> UTF16View { + public func `prefix`(through: Index) -> UTF16View { return UTF16View(string: stringData.__substring(range: 0...through)) } - func `prefix`(upTo: Index) -> UTF16View { + public func `prefix`(upTo: Index) -> UTF16View { return UTF16View(string: stringData.__substring(range: 0.. UTF16View { + public func suffix(from: Index) -> UTF16View { return UTF16View(string: stringData.__substring(range: from.. UTF32View { + public func `prefix`(upTo: Index) -> UTF32View { return UTF32View(stringData: stringData[0.. UTF32View { + public func suffix(from: Index) -> UTF32View { return UTF32View(stringData: stringData[from.. UTF8View { + public func `prefix`(upTo: Index) -> UTF8View { return UTF8View(stringData: stringData[0.. UTF8View { + public func suffix(from: Index) -> UTF8View { return UTF8View(stringData: stringData[from.. SwiftString { - if let string = string { - return SwiftString(string) - } else { - return SwiftString() - } - } - public static class func __implicit(_ string: SwiftString) -> NativeString { return string.nativeStringValue } - public static class func __explicit(_ string: SwiftString) -> NativeString { - return string.nativeStringValue + public class func == (_ stringA: SwiftString, _ stringB: SwiftString) -> Bool { + return stringA.nativeStringValue == stringB.nativeStringValue } public class func + (_ stringA: SwiftString, _ stringB: SwiftString) -> NativeString { return stringA.nativeStringValue+stringB.nativeStringValue } + public class func + (_ stringA: SwiftString, _ stringB: NativeString) -> NativeString { + return stringA.nativeStringValue+stringB + } + + public class func + (_ stringA: NativeString, _ stringB: SwiftString) -> NativeString { + return stringA+stringB.nativeStringValue + } + // // Properties // @@ -284,7 +286,6 @@ public struct SwiftString /*: Streamable*/ { return index(of: s) != nil } - #if !COCOA public func hasPrefix(_ `prefix`: SwiftString) -> Bool { #if JAVA return nativeStringValue.startsWith(`prefix`.nativeStringValue) @@ -301,10 +302,9 @@ public struct SwiftString /*: Streamable*/ { #elseif CLR || ISLAND return nativeStringValue.EndsWith(suffix.nativeStringValue) #elseif COCOA - return nativeStringValue.hasSuffix(`prefix`.nativeStringValue) + return nativeStringValue.hasSuffix(suffix.nativeStringValue) #endif } - #endif public func index(of s: SwiftString) -> Int? { #if JAVA @@ -338,6 +338,10 @@ public struct SwiftString /*: Streamable*/ { //public subscript(range: SwiftString.Index) -> Character // implicitly provided by the compiler, already + public subscript(index: Int) -> Char { + return nativeStringValue[index] + } + public subscript(range: Range/**/) -> SwiftString { if range.upperBound != nil { #if JAVA @@ -364,8 +368,20 @@ public struct SwiftString /*: Streamable*/ { } } + public func `prefix`(through: Index) -> NativeString { + return self[...through] // E119 Cannot use the unary operator "..." on type "extension String.Index" + } + + public func `prefix`(upTo: Index) -> NativeString { + return self[.. NativeString { + return self[from...] + } + // Streamable - func writeTo(_ target: OutputStreamType) { + public func writeTo(_ target: OutputStreamType) { //target.write(nativeStringValue) } @@ -373,7 +389,7 @@ public struct SwiftString /*: Streamable*/ { // // - func split(_ separator: String) -> [String] { + public func split(_ separator: String) -> [String] { return nativeStringValue.components(separatedBy: separator) } @@ -388,7 +404,7 @@ public struct SwiftString /*: Streamable*/ { //76157: Silver: Internal Error in SBL /* - func + (_ value1: AnyObject?, _ value2: AnyObject?) -> SwiftString { + public func + (_ value1: AnyObject?, _ value2: AnyObject?) -> SwiftString { return SwiftString(__toNativeString(value1) + value2?.nativeStringValue) }*/ diff --git a/Source/String_Extensions.swift b/Source/String_Extensions.swift index 66a903e..3041abd 100644 --- a/Source/String_Extensions.swift +++ b/Source/String_Extensions.swift @@ -13,7 +13,7 @@ #elseif CLR return NativeString(c, count) #elseif COCOA - return "".stringByPaddingToLength(count, withString: NSString.stringWithFormat("%c", c), startingAtIndex: 0) + return SwiftString.empty.nativeStringValue.stringByPaddingToLength(count, withString: NSString.stringWithFormat("%c", c), startingAtIndex: 0) #endif } @@ -141,7 +141,7 @@ //func components(separatedBy separator: CharacterSet) -> [String] { //} - func components(separatedBy separator: String) -> [String] { + public func components(separatedBy separator: String) -> [String] { let separatorLength = separator.length() if separatorLength == 0 { return [self] @@ -249,15 +249,15 @@ // Subscripts // - func `prefix`(through: Index) -> NativeString { + public func `prefix`(through: Index) -> NativeString { return self[...through] // E119 Cannot use the unary operator "..." on type "extension String.Index" } - func `prefix`(upTo: Index) -> NativeString { + public func `prefix`(upTo: Index) -> NativeString { return self[.. NativeString { + public func suffix(from: Index) -> NativeString { return self[from...] } @@ -295,7 +295,7 @@ } // Streamable - func writeTo(_ target: OutputStreamType) { + public func writeTo(_ target: OutputStreamType) { //target.write(self) }