示例#1
0
		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;
		}
示例#2
0
        // 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;
        }
示例#3
0
        private bool DoLineStartsWith(int offset, NSString text)
        {
            bool match = false;

            NSString buffer =  m_textView.Value.textStorage().string_();
            if (offset + text.length() <= buffer.length())
            {
                int result = buffer.compare_options_range(text, 0, new NSRange(offset, (int) text.length()));
                match = result == Enums.NSOrderedSame;
            //				Console.WriteLine("'{0}...' == '{1}' = {2}", buffer.ToString().Substring(offset, 12).EscapeAll(), text.ToString(), match);
            }

            return match;
        }
示例#4
0
        private bool DoMatchesWord(NSString text, int location, int length, Regex word)
        {
            bool matches = false;

            if (location >= 0 && location + length <= text.length())
            {
                string str;
                text.getCharacters_range(new NSRange(location, length), out str);
                Match match = word.Match(str);
                matches = match.Success && match.Length == str.Length;
            }

            return matches;
        }
示例#5
0
        private int DoGetLineStartFromSpaceOrTab(NSString text, int index)
        {
            bool within = false;

            if (index < text.length() && (text[index] == ' ' || text[index] == '\t'))
            {
                while (index > 0 && (text[index] == ' ' || text[index] == '\t'))
                    --index;

                if (index >= 0 && (text[index] == '\n' || text[index] == '\r'))
                    within = true;
            }

            return within ? index + 1 : -1;
        }
示例#6
0
 // Returns a new index >= 0 and <= text.length()
 // and <= than the original index, unless a negative value was passed in.
 // Returns the same index if the previous character is a newline.
 private int DoGetLineStart(NSString text, int index)
 {
     int len = (int)text.length();
     if (len == 0) return 0;
     if (index > len) index = len - 1;
     else if (index < 0) index = 0;
     if (index > 0 && text[index-1] == '\n') return index;
     while (index > 0 && text[index-1] != '\n') --index;
     if (index < 0) index = 0;
     return index;
 }
示例#7
0
 private int DoGetLeadingTabCount(NSString text, int i)
 {
     Contract.Requires(text != null && !text.IsNil());
     Contract.Requires(i >= 0);
     Contract.Requires(i == 0 || text[i-1] == '\n');
     var textLen = text.length();
     var j = i;
     while (j < textLen && text[j] == '\t') j++;
     return j - i;
 }
示例#8
0
        // 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;
        }