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
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor.php;
14 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.swt.graphics.Point;
21 * Detects HTML words in documents.
23 public class HTMLWordExtractor {
26 * Find the location of the word at offset in document.
28 * @returns Point - x is the start position, y is the end position. Return
29 * null if it is not found.
31 * the document being searched.
33 * the position to start searching from.
35 public static Point findWord(IDocument document, int offset) {
42 int position = offset;
45 while (position >= 0) {
46 character = document.getChar(position);
47 if (!Scanner.isPHPIdentifierPart(character))
51 if ((position > 0) && (character == '<')) {
54 if ((position > 1) && (character == '/')) {
55 character = document.getChar(position - 1);
56 if (character == '<') {
61 if (position == offset) {
68 int length = document.getLength();
71 while (position < length) {
72 character = document.getChar(position);
73 if (!Scanner.isPHPIdentifierPart(character))
77 if ((position < length) && (character == '>')) {
84 return new Point(start, end - start);
86 } catch (BadLocationException x) {