2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: CssTextUtils.java,v 1.1 2004-09-02 18:07:13 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.core.internal.text;
16 import java.io.IOException;
18 import net.sourceforge.phpeclipse.css.core.CssCore;
20 import org.eclipse.jface.text.IDocument;
23 * Various utility methods for handling CSS source.
25 * TODO Probably refactor so this class isn't needed
27 public final class CssTextUtils {
29 // Constructors ------------------------------------------------------------
34 private CssTextUtils() {
38 // Public Methods ----------------------------------------------------------
40 public static int findMatchingClosingPeer(IDocument document, int offset,
43 CssCodeReader reader = new CssCodeReader(document, offset,
44 document.getLength(), CssCodeReader.FORWARD);
45 char closingChar = getPeerCharacter(openingPeer);
47 int c = reader.read();
49 if ((c == openingPeer) && (c != closingChar)) {
51 } else if (c == closingChar) {
55 return reader.getOffset();
59 } catch (IOException e) {
61 "Failed to find matching closing peer for '" + //$NON-NLS-1$
62 openingPeer + '\'', e);
67 public static int findMatchingOpeningPeer(IDocument document, int offset,
70 CssCodeReader reader = new CssCodeReader(document, offset + 1,
71 document.getLength(), CssCodeReader.BACKWARD);
72 char openingChar = getPeerCharacter(closingPeer);
74 int c = reader.read();
76 if ((c == closingPeer) && (c != openingChar)) {
78 } else if (c == openingChar) {
82 return reader.getOffset();
86 } catch (IOException e) {
88 "Failed to find matching opening peer for '" + //$NON-NLS-1$
89 closingPeer + '\'', e);
94 public static char getPeerCharacter(char c) {
100 case '(': return ')';
101 case ')': return '(';
102 case '"': return '"';
103 case '\'': return '\'';
108 public static boolean isCssIdentifierPart(char c) {
109 return ((c == '_') || Character.isLetterOrDigit(c) || (c == '-'));
112 public static boolean isCssIdentifierStart(char c) {
113 return ((c == '_') || Character.isLetter(c));
116 public static boolean isCssNumberPart(char c) {
117 return ((c == '.') || Character.isDigit(c));
120 public static boolean isCssNumberStart(char c) {
121 return ((c == '-') || (c == '.') || Character.isDigit(c));
124 public static boolean isCssWhitespace(char c) {
125 return Character.isWhitespace(c);