01: /*
02: * SyntaxUtilities.java - Utility functions
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2003 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: */
22: package org.gjt.sp.jedit.syntax;
23:
24: import javax.swing.text.Segment;
25:
26: /**
27: * Contains utility functions used by the syntax highlighting code.
28: * @since jEdit 4.2pre1
29: * @version $Id: SyntaxUtilities.java 4651 2003-04-28 01:35:29Z spestov $
30: * @author Slava Pestov
31: */
32: public class SyntaxUtilities {
33: //{{{ regionMatches() method
34: /**
35: * Checks if a subregion of a <code>Segment</code> is equal to a
36: * character array.
37: * @param ignoreCase True if case should be ignored, false otherwise
38: * @param text The segment
39: * @param offset The offset into the segment
40: * @param match The character array to match
41: * @since jEdit 4.2pre1
42: */
43: public static boolean regionMatches(boolean ignoreCase,
44: Segment text, int offset, char[] match) {
45: int length = offset + match.length;
46: if (length > text.offset + text.count)
47: return false;
48: char[] textArray = text.array;
49: for (int i = offset, j = 0; i < length; i++, j++) {
50: char c1 = textArray[i];
51: char c2 = match[j];
52: if (ignoreCase) {
53: c1 = Character.toUpperCase(c1);
54: c2 = Character.toUpperCase(c2);
55: }
56: if (c1 != c2)
57: return false;
58: }
59: return true;
60: } //}}}
61: }
|