Skip to content

Commit 8ebb92c

Browse files
committed
And Some String changes #12 was also incomplete for Java & failed to build :(
1 parent 3e4e711 commit 8ebb92c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Source/String.swift

Lines changed: 16 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
@@ -40,7 +40,7 @@ public struct SwiftString /*: Streamable*/ {
4040
}
4141

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

4646
public init(_ s: NativeString) {
@@ -233,19 +233,24 @@ public struct SwiftString /*: Streamable*/ {
233233
}
234234

235235
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
236+
#if JAVA
237+
let buffer = java.nio.charset.Charset.forName("UTF8").encode(self)
238+
let result = Byte[](buffer.remaining())
239+
buffer.get(result)
240+
return result
241+
#elseif CLR
242+
return System.Text.Encoding.UTF8.GetBytes(nativeStringValue)
243+
#elseif ISLAND
244+
return RemObjects.Elements.System.Encoding.UTF8.GetBytes(nativeStringValue, false)
245+
#elseif COCOA
241246
let utf8 = nativeStringValue.cStringUsingEncoding(.UTF8StringEncoding)
242247
let len = strlen(utf8) + 1
243248
let result = UTF8Char[](len)
244249
memcpy(result, utf8, len)
245-
#endif
246-
return result
250+
return result
251+
#endif
247252
}
248-
253+
249254
public var utf16: SwiftString.UTF16View {
250255
return SwiftString.UTF16View(string: nativeStringValue)
251256
}
@@ -434,4 +439,4 @@ public struct SwiftString /*: Streamable*/ {
434439
return nil
435440
#endif
436441
}
437-
}
442+
}

0 commit comments

Comments
 (0)