tasty-imitation-keyboard
tasty-imitation-keyboard copied to clipboard
Punctuation check improvements
(I probably could have done this as a pull request, but figured it warranted a discussion. And sometimes a simple text replace is easier than dealing with merges!)
You currently check for punctuation using something like this:
text == "!" || text == "."
However, there are native methods for that. I am uncertain if these deal with localization, but I assume they do--for instance, Japanese uses a different period than English " 。". This may not be what you need, but my version of checking for punctuation includes commas etc:
import UIKit
import Foundation
extension String {
func containsPunctuation() -> Bool {
//println(NSCharacterSet.punctuationCharacterSet())
if let r = self.rangeOfCharacterFromSet(NSCharacterSet.punctuationCharacterSet())
{
return true
}
return false
}
}
Thanks, I'll look into that later. There's some nuance in regards to punctuation: end-of-sentence punctuation like "!", "?", and "." get auto-caps after them, apostrophes automatically go back to the letter screen once inserted, and there are probably some other ones that I missed. So I'm not sure if a catch-all approach like that would work. But it's a good point that my code doesn't handle a lot of punctuation in foreign languages.
Maybe it would be best to just specify the nature of a punctuation character directly in the model — Key.PunctuationType or something. That way, there's no concern about encompassing every language in the world. Implementers can just put it in themselves.