PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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. import javax.swing.text.Segment;
  24. /**
  25. * Contains utility functions used by the syntax highlighting code.
  26. * @since jEdit 4.2pre1
  27. * @version $Id: SyntaxUtilities.java 4651 2003-04-28 01:35:29Z spestov $
  28. * @author Slava Pestov
  29. */
  30. public class SyntaxUtilities
  31. {
  32. //{{{ regionMatches() method
  33. /**
  34. * Checks if a subregion of a <code>Segment</code> is equal to a
  35. * character array.
  36. * @param ignoreCase True if case should be ignored, false otherwise
  37. * @param text The segment
  38. * @param offset The offset into the segment
  39. * @param match The character array to match
  40. * @since jEdit 4.2pre1
  41. */
  42. public static boolean regionMatches(boolean ignoreCase, Segment text,
  43. int offset, char[] match)
  44. {
  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. {
  51. char c1 = textArray[i];
  52. char c2 = match[j];
  53. if(ignoreCase)
  54. {
  55. c1 = Character.toUpperCase(c1);
  56. c2 = Character.toUpperCase(c2);
  57. }
  58. if(c1 != c2)
  59. return false;
  60. }
  61. return true;
  62. } //}}}
  63. }