Skip to content

Conversation

@YOCKOW
Copy link
Member

@YOCKOW YOCKOW commented May 9, 2025

Implementation of the proposal: #1243 (SF-0033)

@YOCKOW

This comment was marked as outdated.

@YOCKOW YOCKOW added the API Change Any changes to Foundation's public API surface label May 13, 2025
@YOCKOW YOCKOW force-pushed the StringEncodingNames/implementation branch from dd0b16c to 1ae2a4c Compare June 17, 2025 01:25
@YOCKOW

This comment was marked as outdated.

@YOCKOW YOCKOW force-pushed the StringEncodingNames/implementation branch from 1ae2a4c to 4d87ed8 Compare September 21, 2025 02:59
@YOCKOW YOCKOW changed the title Implement String.Encoding.ianaName and String.Encoding(ianaName:). SF-0033: Implement String.Encoding.ianaName and String.Encoding(ianaName:). Sep 21, 2025
@YOCKOW

This comment was marked as outdated.

@YOCKOW YOCKOW force-pushed the StringEncodingNames/implementation branch 4 times, most recently from 217c46d to 9cd5c9a Compare October 12, 2025 08:16
@YOCKOW

This comment was marked as outdated.

1 similar comment
@YOCKOW

This comment was marked as outdated.

@YOCKOW YOCKOW marked this pull request as ready for review October 14, 2025 05:27
@YOCKOW YOCKOW marked this pull request as draft October 14, 2025 07:51
@YOCKOW YOCKOW force-pushed the StringEncodingNames/implementation branch from 9cd5c9a to 3e9aef4 Compare October 14, 2025 08:12
@YOCKOW YOCKOW force-pushed the StringEncodingNames/implementation branch from 3e9aef4 to ac42127 Compare October 16, 2025 06:04
@YOCKOW
Copy link
Member Author

YOCKOW commented Oct 16, 2025

@swift-ci Please test

@YOCKOW YOCKOW marked this pull request as ready for review October 16, 2025 06:55
@YOCKOW
Copy link
Member Author

YOCKOW commented Oct 16, 2025

@itingliu

I've made this PR ready for review.
I'm happy if you take a look at this. Thank you.

cc: Foundation Workgroup
@adam-fowler @iCharlesHu @Lukasa @designatednerd @jmschonfeld @lorentey @stephentyrone @itingliu @tomerd @parkera

@YOCKOW YOCKOW requested a review from itingliu October 16, 2025 06:55
@YOCKOW
Copy link
Member Author

YOCKOW commented Oct 19, 2025

@itingliu
Thank you for reviewing. I'm going to modify implementation reflecting your feedback.

YOCKOW added a commit to YOCKOW/swift-foundation that referenced this pull request Oct 19, 2025
@YOCKOW YOCKOW force-pushed the StringEncodingNames/implementation branch from 0045a48 to e674fa6 Compare October 19, 2025 08:55
YOCKOW added a commit to YOCKOW/swift-foundation that referenced this pull request Oct 22, 2025
@YOCKOW YOCKOW force-pushed the StringEncodingNames/implementation branch from b7702b3 to 8f84db7 Compare October 22, 2025 02:31
@YOCKOW
Copy link
Member Author

YOCKOW commented Oct 23, 2025

@swift-ci Please test

@parkera
Copy link
Contributor

parkera commented Oct 23, 2025

@swift-ci test

Copy link
Contributor

@parkera parkera left a comment

Choose a reason for hiding this comment

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

Looking good to me after the recent simplifications. Will also want @itingliu approval.

@YOCKOW
Copy link
Member Author

YOCKOW commented Oct 23, 2025

Thank you @parkera.
I'm going to wait for @itingliu.

Just in case, what's changed:

  • Rewrote util script in Swift
  • Simplified the logic to parse names
    • Use UInt8(UTF8.UnitCode)
    • Remove redundant tokenizers.

Copy link
Contributor

@itingliu itingliu left a comment

Choose a reason for hiding this comment

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

I also like this simplified version. Thank you! just had a few minor comments

/// to determine which encoding is suitable.
@available(FoundationPreview 6.3, *)
public init?(ianaName charsetName: String) {
let possibilities: [String.Encoding] = [
Copy link
Contributor

@itingliu itingliu Oct 23, 2025

Choose a reason for hiding this comment

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

Would it work if you write

let possibilities: [IANACharset] = {...

and below just do

         func __determineEncoding() -> String.Encoding? {
            for ianaCharset in possibilities {
                if ianaCharset.matches(charsetName) {
                    return encoding
                }
            }
            return nil
        }

Am I missing anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

Won't we lose encoding for return encoding in that implementation?

return nil
}

guard let encoding = __determineEncoding() else {
Copy link
Contributor

@itingliu itingliu Oct 23, 2025

Choose a reason for hiding this comment

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

And to simply this even further, it looks like this logic inside func __determineEncoding() doesn't even needed to be extracted in a function since it's only used once?

Copy link
Member Author

@YOCKOW YOCKOW Oct 24, 2025

Choose a reason for hiding this comment

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

The reason why nested function is used is just because of readability since self = nil; return is invalid in Swift.

Sorry, we can write self = encoding; return...
I'm fixing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've fixed String.Encoding(ianaName:).
I hope that this is in line with your intention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Change Any changes to Foundation's public API surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants