/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/syntax/SyntaxUtilities.java
Java | 65 lines | 26 code | 2 blank | 37 comment | 5 complexity | a7b5d3d519dffb2fbdee46f8d6c17a91 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * SyntaxUtilities.java - Utility functions
- * :tabSize=8:indentSize=8:noTabs=false:
- * :folding=explicit:collapseFolds=1:
- *
- * Copyright (C) 2003 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- package org.gjt.sp.jedit.syntax;
- import javax.swing.text.Segment;
- /**
- * Contains utility functions used by the syntax highlighting code.
- * @since jEdit 4.2pre1
- * @version $Id: SyntaxUtilities.java 4651 2003-04-28 01:35:29Z spestov $
- * @author Slava Pestov
- */
- public class SyntaxUtilities
- {
- //{{{ regionMatches() method
- /**
- * Checks if a subregion of a <code>Segment</code> is equal to a
- * character array.
- * @param ignoreCase True if case should be ignored, false otherwise
- * @param text The segment
- * @param offset The offset into the segment
- * @param match The character array to match
- * @since jEdit 4.2pre1
- */
- public static boolean regionMatches(boolean ignoreCase, Segment text,
- int offset, char[] match)
- {
- int length = offset + match.length;
- if(length > text.offset + text.count)
- return false;
- char[] textArray = text.array;
- for(int i = offset, j = 0; i < length; i++, j++)
- {
- char c1 = textArray[i];
- char c2 = match[j];
- if(ignoreCase)
- {
- c1 = Character.toUpperCase(c1);
- c2 = Character.toUpperCase(c2);
- }
- if(c1 != c2)
- return false;
- }
- return true;
- } //}}}
- }