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

implement NSString.boolValue #51

Merged
merged 1 commit into from Dec 8, 2015
Merged

Conversation

jpsim
Copy link
Contributor

@jpsim jpsim commented Dec 6, 2015

Gives same output as Standard Foundation for the same test values.

@@ -34,6 +35,17 @@ class TestNSString : XCTestCase {
("test_FromMalformedNullTerminatedCStringInUTF8", test_FromMalformedNullTerminatedCStringInUTF8 ),
]
}

func test_boolValue() {
let trueStrings: [NSString] = ["t", "true", "TRUE", "tRuE", "yes", "YES", "1"]
Copy link
Member

Choose a reason for hiding this comment

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

the value "+000009" should map to true

@harlanhaskins
Copy link
Collaborator

The NSString documentation says:

This property is YES on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters. This property is NO if the receiver doesn’t begin with a valid decimal text representation of a number.

The property assumes a decimal representation and skips whitespace at the beginning of the string. It also skips initial whitespace characters, or optional -/+ sign followed by zeroes.

It looks like, instead of checking the prefix for each character, it walks the string and checks if any of the characters match the predicates.
But it should also skip + or - and any number of 0's.

@jpsim
Copy link
Contributor Author

jpsim commented Dec 8, 2015

Thanks for the tip @harlanhaskins! This one's on me, I should have referred to the documentation.

@jpsim
Copy link
Contributor Author

jpsim commented Dec 8, 2015

I have an implementation in place, but I also had to implement NSScanner.rangeOfCharacterFromSet (...) which I'll package up in another PR.

@jpsim
Copy link
Contributor Author

jpsim commented Dec 8, 2015

This has been updated to address @phausler's feedback and abide by the documentation referred to by @harlanhaskins. This depends on #75.

@harlanhaskins
Copy link
Collaborator

Looks great! 👍

@jpsim
Copy link
Contributor Author

jpsim commented Dec 8, 2015

Now that #75 has been merged, I've dropped that commit from this branch, so now this just has the NSString.boolValue commit.

parkera added a commit that referenced this pull request Dec 8, 2015
@parkera parkera merged commit 590551f into apple:master Dec 8, 2015
@parkera
Copy link
Member

parkera commented Dec 8, 2015

Thanks!

@jpsim jpsim deleted the NSString.boolValue branch December 8, 2015 21:22
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
[readme] Describe where toolchains are usually found on macOS/linux
kateinoigakukun pushed a commit to kateinoigakukun/swift-corelibs-foundation that referenced this pull request Oct 11, 2023
[pull] swiftwasm from master
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.

None yet

4 participants