X-Git-Url: http://secure.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssWordFinder.java b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssWordFinder.java new file mode 100644 index 0000000..ca30fd0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.css.ui/src/net/sourceforge/phpeclipse/css/ui/internal/text/CssWordFinder.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Widespace, OU and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Igor Malinin - initial implementation + * + * $Id: CssWordFinder.java,v 1.1 2004-09-02 18:11:48 jsurfer Exp $ + */ +package net.sourceforge.phpeclipse.css.ui.internal.text; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; + + +/** + * + * + * @author Igor Malinin + */ +public class CssWordFinder { + public static IRegion findWord(IDocument document, int offset) { + int length = document.getLength(); + + try { + int pos = offset; + + while (pos >= 0) { + if (!Character.isUnicodeIdentifierPart(document.getChar(pos))) { + break; + } + --pos; + } + + int start = pos; + + pos = offset; + + while (pos < length) { + if (!Character.isUnicodeIdentifierPart(document.getChar(pos))) { + break; + } + ++pos; + } + + int end = pos; + + if (start == offset) { + return new Region(start, end - start); + } + + return new Region(start + 1, end - start - 1); + } catch (BadLocationException x) { + return null; + } + } +}