Skip to content

Commit 85be0e6

Browse files
committed
Changed String.init(count:repeatedValue:) with init(repeating:count:) and added String.utf8CString for CLR and ISLAND
1 parent 46ac54f commit 85be0e6

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

Source/String.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if JAVA
1+
#if JAVA
22
public typealias NativeString = java.lang.String
33
public typealias NativeStringBuilder = java.lang.StringBuilder
44
#elseif CLR
@@ -24,7 +24,7 @@ public struct SwiftString /*: Streamable*/ {
2424
nativeStringValue = ""
2525
}
2626

27-
public init(count: Int, repeatedValue c: Char) {
27+
public init(repeating c: Char, count: Int) {
2828

2929
#if JAVA || ISLAND
3030
var chars = Char[](count)
@@ -40,7 +40,7 @@ public struct SwiftString /*: Streamable*/ {
4040
}
4141

4242
public convenience init(_ c: Char) {
43-
init(count: 1, repeatedValue: c)
43+
init(repeating: c, count: 1)
4444
}
4545

4646
public init(_ s: NativeString) {
@@ -232,16 +232,20 @@ public struct SwiftString /*: Streamable*/ {
232232
return SwiftString.UTF8View(string: nativeStringValue)
233233
}
234234

235-
#if COCOA
236-
public var utf8CString: UTF8Char[] {
235+
public var utf8CString: [UTF8Char] {
236+
#if CLR
237+
let result = System.Text.Encoding.UTF8.GetBytes(nativeStringValue)
238+
#elseif ISLAND
239+
let result = RemObjects.Elements.System.Encoding.UTF8.GetBytes(nativeStringValue, false)
240+
#elseif COCOA
237241
let utf8 = nativeStringValue.cStringUsingEncoding(.UTF8StringEncoding)
238-
let len = strlen(utf8)+1
239-
let result = UTF8Char[](len)
242+
let len = strlen(utf8) + 1
243+
let result = [UTF8Char](len)
240244
memcpy(result, utf8, len)
241-
return result
245+
#endif
246+
return result
242247
}
243-
#endif
244-
248+
245249
public var utf16: SwiftString.UTF16View {
246250
return SwiftString.UTF16View(string: nativeStringValue)
247251
}
@@ -430,4 +434,4 @@ public struct SwiftString /*: Streamable*/ {
430434
return nil
431435
#endif
432436
}
433-
}
437+
}

Source/String_Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
public extension NativeString : Streamable {
1+
public extension NativeString : Streamable {
22

33
typealias Index = Int
44

5-
public init(count: Int, repeatedValue c: Char) {
5+
public init(repeating c: Char, count: Int) {
66

77
#if JAVA || ISLAND
88
var chars = Char[](count)
@@ -18,7 +18,7 @@
1818
}
1919

2020
public init(_ c: Char) {
21-
return NativeString(count: 1, repeatedValue: c)
21+
return NativeString(repeating: c, count: 1)
2222
}
2323

2424
public init(_ object: Object) {
@@ -333,4 +333,4 @@
333333
return nil
334334
#endif
335335
}
336-
}
336+
}

0 commit comments

Comments
 (0)