Skip to content

Conversation

parkera
Copy link
Contributor

@parkera parkera commented Mar 19, 2025

Add an upcall to swift-corelibs-foundation for converting String encodings that swift-foundation does not implement.

Partially resolves #1216.

@parkera parkera requested a review from jmschonfeld March 19, 2025 16:49
@parkera
Copy link
Contributor Author

parkera commented Mar 19, 2025

@swift-ci test

@parkera
Copy link
Contributor Author

parkera commented Mar 19, 2025

Will, of course, need a follow up in swift-corelibs-foundation to replace the function with one that calls into NSString's conversion function.

@@ -91,6 +91,14 @@ extension UInt16 {

// These provides concrete implementations for String and Substring, enhancing performance over generic StringProtocol.

#if !FOUNDATION_FRAMEWORK
@_spi(SwiftCorelibsFoundation)
dynamic public func _cfStringEncodingConvert(string: String, using encoding: UInt, allowLossyConversion: Bool) -> Data? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a similar up-call for the bytes --> String direction so that we support decoding as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done.

@parkera
Copy link
Contributor Author

parkera commented Mar 19, 2025

@swift-ci test

@parkera
Copy link
Contributor Author

parkera commented Mar 21, 2025

@swift-ci test

@parkera parkera merged commit ee467a1 into swiftlang:main Mar 24, 2025
3 checks passed
YOCKOW added a commit to YOCKOW/swift-foundation that referenced this pull request Jun 17, 2025
YOCKOW added a commit to YOCKOW/swift-foundation that referenced this pull request Aug 18, 2025
itingliu pushed a commit that referenced this pull request Sep 4, 2025
* [Proposal] Add "String Encoding Names" proposal.

This proposal allows `String.Encoding` to be converted to and from various names.

For example:

```swift
print(String.Encoding.utf8.ianaName!) // Prints "UTF-8"
print(String.Encoding(ianaName: "ISO_646.irv:1991") == .ascii) // Prints "true"
```

* Change the link to implementation.

* Remove description about #1015 since it is resolved.

Links:
- Issue: #1015
- Resolvers:
  * #1217
  * swiftlang/swift-corelibs-foundation#5194

* Add a description about already-available ICU string converter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

swift 6 cannot open correctly a windowsCP1252 file in linux (worked on swift 5 and macos)
2 participants