KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > syntax > SyntaxUtilities


1 /*
2  * SyntaxUtilities.java - Utility functions
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2003 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * 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 JavaDoc;
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 {
34     //{{{ regionMatches() method
35
/**
36      * Checks if a subregion of a <code>Segment</code> is equal to a
37      * character array.
38      * @param ignoreCase True if case should be ignored, false otherwise
39      * @param text The segment
40      * @param offset The offset into the segment
41      * @param match The character array to match
42      * @since jEdit 4.2pre1
43      */

44     public static boolean regionMatches(boolean ignoreCase, Segment JavaDoc text,
45         int offset, char[] match)
46     {
47         int length = offset + match.length;
48         if(length > text.offset + text.count)
49             return false;
50         char[] textArray = text.array;
51         for(int i = offset, j = 0; i < length; i++, j++)
52         {
53             char c1 = textArray[i];
54             char c2 = match[j];
55             if(ignoreCase)
56             {
57                 c1 = Character.toUpperCase(c1);
58                 c2 = Character.toUpperCase(c2);
59             }
60             if(c1 != c2)
61                 return false;
62         }
63         return true;
64     } //}}}
65
}
66
Popular Tags