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.


#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.
itingliu pushed a commit that referenced this pull request Sep 16, 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.

* SF-0033: Add `@available` attributes to sample code.

In response to: https://forums.swift.org/t/review-sf-0033-string-encoding-names/81965/7

* SF-0033: Clarify which "case-insensitivity" is used.

In response to: https://forums.swift.org/t/review-sf-0033-string-encoding-names/81965/8

* SF-0033: Change FoundationPreview version to 6.3.

In response to: #1502 (comment)
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