1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation 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 API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text;
13 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
15 import org.eclipse.jface.text.BadLocationException;
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.jface.text.IRegion;
18 import org.eclipse.jface.text.Region;
20 public class JavaWordFinder {
22 public static IRegion findWord(IDocument document, int offset) {
33 c = document.getChar(pos);
38 if (!Scanner.isPHPIdentifierPart(c))
47 int length = document.getLength();
49 while (pos < length) {
50 c = document.getChar(pos);
51 if (!Scanner.isPHPIdentifierPart(c))
58 } catch (BadLocationException x) {
61 if (start > -1 && end > -1) {
62 if (start == offset && end == offset)
63 return new Region(offset, 0);
64 else if (start == offset)
65 return new Region(start, end - start);
67 return new Region(start + 1, end - start - 1);