1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. 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 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor.php;
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.jface.text.BadLocationException;
16 import org.eclipse.jface.text.IDocument;
19 * Detects PHP words in documents.
21 public class PHPWordDetector {
24 * Find the location of the word at offset in document.
25 * @returns Point - x is the start position, y is the end position.
26 * Return null if it is not found.
27 * @param document the document being searched.
28 * @param offset - the position to start searching from.
30 public static Point findWord(IDocument document, int offset) {
37 int position = offset;
40 while (position >= 0) {
41 character = document.getChar(position);
42 if (!Character.isJavaIdentifierPart(character) && (character != '$'))
50 int length = document.getLength();
52 while (position < length) {
53 character = document.getChar(position);
54 if (!Character.isJavaIdentifierPart(character) && (character != '$'))
62 return new Point(start, end - start);
64 } catch (BadLocationException x) {