Skip to content
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

Added code to detect UTF32 files for NSString contentsOfURL:usedEncoding #928

Merged
merged 1 commit into from
Jul 31, 2017

Conversation

mohitathwani
Copy link
Contributor

This pull request is in continuation to PR #893

@alblue
Copy link
Contributor

alblue commented Apr 3, 2017

Please can you squash the history of this, so that we don't get noisy messages like "Resolved merge conflicts"? and instead of having "Merge remote-tracking branch X" messages, you can do a git pull --rebase (which will replay your commits on top of the latest, instead of trying to do a merge commit). At the very least, please rebase this all on the top of master, and then squash all commits with 'Resolved' or 'Merge' in the title.

You can also configure the 'rebase' to be the default by doing git config --global pull.rebase true so that you don't have the same problems in future.

@phausler
Copy link
Contributor

phausler commented Apr 3, 2017

@alblue usually any merges we accept are squash merged anyhow as a default rule so that isn't too bad.

@@ -462,6 +462,8 @@
'TestFoundation/Resources/NSStringTestData.txt',
'TestFoundation/Resources/NSString-UTF16-BE-data.txt',
'TestFoundation/Resources/NSString-UTF16-LE-data.txt',
'TestFoundation/Resources/NSString-UTF32-BE-data.txt',
Copy link
Contributor

Choose a reason for hiding this comment

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

are these files missing from the commit? I don't see them currently on master

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're actually there. Because these files have BOM in them, Github is detecting them to be binary files. If you go ahead and click on "Files Changed" above, you would see them listed as binary files..

XCTFail("Unable to init NSString from contentOf:usedEncoding:")
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do these pass on macOS using the system Foundation?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mohitathwani can you double check on this part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parkera @phausler I just tested this on MacOS... The tests are passing...

@@ -1301,12 +1301,18 @@ extension NSString {
let readResult = try NSData(contentsOf: url, options:[])

let bytePtr = readResult.bytes.bindMemory(to: UInt8.self, capacity:readResult.length)
if readResult.length >= 2 && bytePtr[0] == 254 && bytePtr[1] == 255 {
if readResult.length >= 4 && bytePtr[0] == 255 && bytePtr[1] == 254 && bytePtr[2] == 0 && bytePtr[3] == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

might be good to use the hex values for these since most sources of the unicode standards refer to 0xFF and 0xFE etc. (this is just a style nit not a functionality commentary)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated my code with hex values

enc?.pointee = String.Encoding.utf16BigEndian.rawValue
}
else if readResult.length >= 2 && bytePtr[0] == 255 && bytePtr[1] == 254 {
enc?.pointee = String.Encoding.utf16LittleEndian.rawValue
}
else if readResult.length >= 4 && bytePtr[0] == 0 && bytePtr[1] == 0 && bytePtr[2] == 254 && bytePtr[3] == 255 {
enc?.pointee = String.Encoding.utf32BigEndian.rawValue
}
Copy link

@pushkarnk pushkarnk Apr 5, 2017

Choose a reason for hiding this comment

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

nit: We seem to be using some Int literals. Will it make sense to replace them with constants so that their contextual meaning is clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What kind of naming conventions do you suggest for these literals?

…L:usedEncoding:

This pull request is in continuation to PR swiftlang#893
@alblue
Copy link
Contributor

alblue commented Jul 20, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Jul 31, 2017

This looks good to me - @phausler WDYT?

@phausler
Copy link
Contributor

looks good to me

@swift-ci please test and merge

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.

6 participants