Skip to content

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

Merged
merged 1 commit into from
Oct 6, 2017
Merged

NSString(contentsOfFile:usedEncoding:) fixes. #1225

merged 1 commit into from
Oct 6, 2017

Conversation

dplanitzer
Copy link
Contributor

  • 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

@spevans
Copy link
Contributor

spevans commented Sep 18, 2017

@swift-ci please test

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 {
Copy link
Contributor

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.

}
}

enc?.pointee = encoding
Copy link
Contributor

@ianpartridge ianpartridge Sep 19, 2017

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
@dplanitzer
Copy link
Contributor Author

@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.

@phausler
Copy link
Contributor

this is on-par with the way the objc version does it

@swift-ci please test and merge

@alblue
Copy link
Contributor

alblue commented Oct 5, 2017

@swift-ci please test and merge

@alblue
Copy link
Contributor

alblue commented Oct 6, 2017

Transient failure for the GitHub API requesting merge - the build succeeded.

@alblue
Copy link
Contributor

alblue commented Oct 6, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit 1099962 into swiftlang:master Oct 6, 2017
jpsim added a commit to realm/SwiftLint that referenced this pull request Dec 23, 2018
sjavora pushed a commit to sjavora/SwiftLint that referenced this pull request Mar 9, 2019
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.

7 participants