private Dictionary<char, int> DoFindControlChars(NSString str) { var chars = new Dictionary<char, int>(); int len = (int) str.length(); NSRange range = new NSRange(0, len); while (true) { NSRange temp = str.rangeOfCharacterFromSet_options_range( NSCharacterSet.controlCharacterSet(), Enums.NSLiteralSearch, range); if (temp.length == 0) break; char ch = str.characterAtIndex((uint) temp.location); if (ch != '\r' && ch != '\n' && ch != '\t' && ch != Constants.BOM[0]) { if (chars.ContainsKey(ch)) chars[ch] = chars[ch] + 1; else chars[ch] = 1; } range = new NSRange(temp.location + 1, len - (temp.location + 1)); } return chars; }
// Return the number of space characters at index and before. private int DoGetSpaceCount(NSString text, int index) { int count = 0; while (index >= 0) { char ch = text.characterAtIndex((uint) index); if (ch != ' ') break; ++count; --index; } return count; }
// Note that Dictionary.app will fall back to wikipedia for phrases so we // want to allow spaces. public bool canLookupInDictionary(NSString text) { if (NSObject.IsNullOrNil(text)) return false; if (text.length() == 0) return false; if (!char.IsLetter(text.characterAtIndex(0))) return false; if (text.Any(c => c == '\t' || c == '\r' || c == '\n')) return false; return true; }
// If the line is blank then this will return the number of blank characters. private int DoGetBlankCount(NSString text, int index) { for (int i = index; i < text.length(); ++i) { char ch = text.characterAtIndex((uint) i); if (ch == '\n') return i - index; else if (ch != ' ' && ch != '\t') break; } return 0; }