1- #if JAVA
1+ #if JAVA
22public typealias NativeString = java . lang . String
33public 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