-
Notifications
You must be signed in to change notification settings - Fork 1.2k
NSString(contentsOfFile:usedEncoding:) fixes. #1225
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
NSString(contentsOfFile:usedEncoding:) fixes. #1225
Conversation
dplanitzer
commented
Sep 18, 2017
- passing nil to the usedEncoding: parameter no longer causes the NSString(contentsOf:usedEncoding:) to terminate with an error.
- implemented NSString(contentsOfFile:usedEncoding:)
- String(contentsOfFile:) now works too
@swift-ci please test |
Foundation/NSString.swift
Outdated
guard let enc = enc, let cf = CFStringCreateWithBytes(kCFAllocatorDefault, bytePtr + offset, readResult.length - offset, | ||
CFStringConvertNSStringEncodingToEncoding(enc.pointee), true) else { | ||
guard let cf = CFStringCreateWithBytes(kCFAllocatorDefault, bytePtr + offset, readResult.length - offset, | ||
CFStringConvertNSStringEncodingToEncoding(encoding), true) else { |
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.
Drive-by nit: Please align this line with the parenthesis of the previous line, as was originally done.
Foundation/NSString.swift
Outdated
} | ||
} | ||
|
||
enc?.pointee = encoding |
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.
Previously the code set enc?.pointee
even if the CFStringCreateWithBytes()
call failed and the function threw. Now it doesn't. Did you check what the behaviour of Darwin is in this regard?
- passing nil to the usedEncoding: parameter no longer causes the NSString(contentsOf:usedEncoding:) to terminate with an error. - implemented NSString(contentsOfFile:usedEncoding:) - String(contentsOfFile:) now works too
@xwu: formatting is fixed now @ianpartridge: I didn't cross check with the Darwin implementation. However, I've changed the code such that we now set the encoding out parameter before we call the CFStringCreate() function. |
this is on-par with the way the objc version does it @swift-ci please test and merge |
@swift-ci please test and merge |
Transient failure for the GitHub API requesting merge - the build succeeded. |
@swift-ci please test and merge |
Used to terminate on Linux but was fixed in swiftlang/swift-corelibs-foundation#1225
Used to terminate on Linux but was fixed in swiftlang/swift-corelibs-foundation#1225