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

Crash for certain strings #9

Open
richardpenner opened this issue Dec 3, 2012 · 1 comment
Open

Crash for certain strings #9

richardpenner opened this issue Dec 3, 2012 · 1 comment

Comments

@richardpenner
Copy link

The following string:

@"Image | Code"

causes the label to crash. Am testing a fix right now.

@richardpenner
Copy link
Author

It looks like you're scanning up to the symbol character set, and then assuming that the symbol part of the scanned string has at least 2 characters:
NSString *word=[read substringWithRange:NSMakeRange(idx, 2)];
I fixed this with the following code:
int charactersToRead = MIN( 2, read.length );
NSString *word=[read substringWithRange:NSMakeRange(idx, charactersToRead)];
But then I found a different bug, where a sentence with a symbol in the middle, like the example above, loses it's space. NSScanners by default have whitespace and newline characters set in charactersToBeSkipped. So in the example string above, after the crash fix, your code scans in "Image ", then "|", then in the second iteration ,the "scanUpToCharactersFromSet" will ignore the " " at the beginning of the remaining string (" Code"). This is all fixed by doing this:
NSScanner *s = [NSScanner scannerWithString:self.text];
[s setCharactersToBeSkipped: nil];
But now, there's a 3rd bug, where it assumes that "words" are separated by spaces. Hence, in a string like this:
@"This is a #test-||-with some symbols."
It is rendered as:
This is a #test- ||-with some symbols.
(Note the extra space between #test- and ||). I don't see an easy way to fix this without re-writing most of this code, so I'll leave it to you. Happy to do a pull request if you care.

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

No branches or pull requests

1 participant