File tree Expand file tree Collapse file tree 2 files changed +20
-14
lines changed
Sources/FoundationEssentials/String Expand file tree Collapse file tree 2 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,17 @@ extension String {
189
189
}
190
190
}
191
191
self = bytes. withContiguousStorageIfAvailable ( buildString) ?? Array ( bytes) . withUnsafeBufferPointer ( buildString)
192
+ case . japaneseEUC:
193
+ // Here we catch encodings that are supported by Foundation Framework
194
+ // but are not supported by corelibs-foundation.
195
+ // We delegate conversion to ICU.
196
+ guard let string = (
197
+ bytes. withContiguousStorageIfAvailable ( { _icuMakeStringFromBytes ( $0, encoding: encoding) } ) ??
198
+ Array ( bytes) . withUnsafeBufferPointer ( { _icuMakeStringFromBytes ( $0, encoding: encoding) } )
199
+ ) else {
200
+ return nil
201
+ }
202
+ self = string
192
203
#endif
193
204
default :
194
205
#if FOUNDATION_FRAMEWORK
@@ -207,14 +218,8 @@ extension String {
207
218
return nil
208
219
}
209
220
#else
210
- func makeString( from bytes: UnsafeBufferPointer < UInt8 > ) -> String ? {
211
- return (
212
- _cfMakeStringFromBytes ( bytes, encoding: encoding. rawValue) ??
213
- _icuMakeStringFromBytes ( bytes, encoding: encoding)
214
- )
215
- }
216
- if let string = ( bytes. withContiguousStorageIfAvailable ( { makeString ( from: $0) } ) ??
217
- Array ( bytes) . withUnsafeBufferPointer ( { makeString ( from: $0) } ) ) {
221
+ if let string = ( bytes. withContiguousStorageIfAvailable ( { _cfMakeStringFromBytes ( $0, encoding: encoding. rawValue) } ) ??
222
+ Array ( bytes) . withUnsafeBufferPointer ( { _cfMakeStringFromBytes ( $0, encoding: encoding. rawValue) } ) ) {
218
223
self = string
219
224
} else {
220
225
return nil
Original file line number Diff line number Diff line change @@ -254,18 +254,19 @@ extension String {
254
254
buffer. appendElement ( value)
255
255
}
256
256
}
257
+ case . japaneseEUC:
258
+ // Here we catch encodings that are supported by Foundation Framework
259
+ // but are not supported by corelibs-foundation.
260
+ // We delegate conversion to ICU.
261
+ return _icuStringEncodingConvert ( string: self , using: encoding, allowLossyConversion: allowLossyConversion)
257
262
#endif
258
263
default :
259
264
#if FOUNDATION_FRAMEWORK
260
265
// Other encodings, defer to the CoreFoundation implementation
261
266
return _ns. data ( using: encoding. rawValue, allowLossyConversion: allowLossyConversion)
262
267
#else
263
- return (
264
- // Attempt an up-call into swift-corelibs-foundation, which can defer to the CoreFoundation implementation
265
- _cfStringEncodingConvert ( string: self , using: encoding. rawValue, allowLossyConversion: allowLossyConversion) ??
266
- // Or attempt an up-call into ICU via FoundationInternationalization
267
- _icuStringEncodingConvert ( string: self , using: encoding, allowLossyConversion: allowLossyConversion)
268
- )
268
+ // Attempt an up-call into swift-corelibs-foundation, which can defer to the CoreFoundation implementation
269
+ return _cfStringEncodingConvert ( string: self , using: encoding. rawValue, allowLossyConversion: allowLossyConversion)
269
270
#endif
270
271
}
271
272
}
You can’t perform that action at this time.
0 commit comments