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 {
189189 }
190190 }
191191 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
192203 #endif
193204 default :
194205#if FOUNDATION_FRAMEWORK
@@ -207,14 +218,8 @@ extension String {
207218 return nil
208219 }
209220#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) } ) ) {
218223 self = string
219224 } else {
220225 return nil
Original file line number Diff line number Diff line change @@ -254,18 +254,19 @@ extension String {
254254 buffer. appendElement ( value)
255255 }
256256 }
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)
257262#endif
258263 default :
259264#if FOUNDATION_FRAMEWORK
260265 // Other encodings, defer to the CoreFoundation implementation
261266 return _ns. data ( using: encoding. rawValue, allowLossyConversion: allowLossyConversion)
262267#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)
269270#endif
270271 }
271272 }
You can’t perform that action at this time.
0 commit comments