-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added implementation of NSString init(contentsOfFile:usedEncoding:) #1059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cb7dfb1
to
632a837
Compare
if String._conditionallyBridgeFromObjectiveC(cf._nsObject, result: &str) { | ||
self.init(str!) | ||
} else { | ||
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.fileReadUnknownStringEncoding.rawValue, userInfo: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems more like a fatal error than an NSError here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one, the bridging? I was going by other code that handled the same thing- I can convert to a fatal error if that's preferred.
@swift-ci please test |
Looks pretty good, thanks for taking this one. |
|
I forgot to add |
632a837
to
c5463dc
Compare
Reworked implementation of NSString init(contentsOf:usedEncoding:) to use same BOM detection code
Ok, looks like the module map for Glibc doesn't include sys/xattr.h, so I've enabled the xattr check only for MacOS for now. I will add the include to the modulemap in the Swift project and do a PR over there to get it included, then I will make a separate PR here to re-enable this functionality under Linux. I believe this PR should be ready to go here, in any case :) Would it be possible to re-test this PR? |
Hi @andybest did you open a PR against the Glibc modulemap? Just wondering where we're up to with this PR 😃 |
@swift-ci please test |
@ianpartridge Apologies, I've been away and haven't had the chance- I will sort this out today :) EDIT: I have now submitted the PR against the Glibc modulemap :) |
By the way, this PR can be merged as-is, since there is an '#if os(' block around the missing functionality which can removed later |
@swift-ci please test |
There were test failures on this run:
Did those files get added correctly? |
Do the tests in the PR pass in Xcode? I noticed the tests for the UTF16 LE/BE were failing the other day and I was wondering if this fixes them as well? |
This pull request has gone stale, closing. Please rebase and reopen if desired. See also #928 |
I have added an implementation for init(contentsOfFile:usedEncoding:)
After discussion on the mailing list, it was determined that the original implementation:
I also noticed that the init(contentsOf:usedEncoding:) initializer only looked for UTF16 BOMs, so I have updated the implementation for that too.
I have added some tests for the BOM detection, and updated the status document accordingly.