001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.api.lexer;
043:
044: import org.netbeans.lib.editor.util.CharSequenceUtilities;
045:
046: /**
047: * Various utility methods related to token text.
048: *
049: * @author Miloslav Metelka
050: * @version 1.00
051: */
052:
053: public final class TokenUtilities {
054:
055: private TokenUtilities() {
056: // no instances
057: }
058:
059: /**
060: * Test whether the given character sequences represent
061: * the same text content.
062: *
063: * @param text1 non-null text to be compared to the other text parameter.
064: * @param text2 non-null text to be compared to the previous text parameter.
065: * @return <code>true</code> if the given character sequences represent
066: * the same text content.
067: */
068: public static boolean textEquals(CharSequence text1,
069: CharSequence text2) {
070: return CharSequenceUtilities.textEquals(text1, text2);
071: }
072:
073: /**
074: * Compare character sequence to another object.
075: * The match is successful if the second object is a character sequence as well
076: * and both character sequences contain the same characters (or if both objects are null).
077: *
078: * @param text character sequence being compared to the given object.
079: * It may be <code>null</code>.
080: * @param o object to be compared to the character sequence.
081: * It may be <code>null</code>.
082: * @return true if both parameters are null or both are non-null
083: * and they contain the same text.
084: */
085: public static boolean equals(CharSequence text, Object o) {
086: return CharSequenceUtilities.equals(text, o);
087: }
088:
089: /**
090: * Implementation of {@link String#indexOf(int)} for character sequences.
091: */
092: public static int indexOf(CharSequence text, int ch) {
093: return CharSequenceUtilities.indexOf(text, ch);
094: }
095:
096: /**
097: * Implementation of {@link String#indexOf(int,int)} for character sequences.
098: */
099: public static int indexOf(CharSequence text, int ch, int fromIndex) {
100: return CharSequenceUtilities.indexOf(text, ch, fromIndex);
101: }
102:
103: /**
104: * Implementation of {@link String#indexOf(String)} for character sequences.
105: */
106: public static int indexOf(CharSequence text, CharSequence seq) {
107: return CharSequenceUtilities.indexOf(text, seq);
108: }
109:
110: /**
111: * Implementation of {@link String#indexOf(String,int)} for character sequences.
112: */
113: public static int indexOf(CharSequence text, CharSequence seq,
114: int fromIndex) {
115: return CharSequenceUtilities.indexOf(text, seq, fromIndex);
116: }
117:
118: /**
119: * Implementation of {@link String#lastIndexOf(String)} for character sequences.
120: */
121: public static int lastIndexOf(CharSequence text, CharSequence seq) {
122: return CharSequenceUtilities.lastIndexOf(text, seq);
123: }
124:
125: /**
126: * Implementation of {@link String#lastIndexOf(String,int)} for character sequences.
127: */
128: public static int lastIndexOf(CharSequence text, CharSequence seq,
129: int fromIndex) {
130: return CharSequenceUtilities.lastIndexOf(text, seq, fromIndex);
131: }
132:
133: /**
134: * Implementation of {@link String#lastIndexOf(int)} for character sequences.
135: */
136: public static int lastIndexOf(CharSequence text, int ch) {
137: return CharSequenceUtilities.lastIndexOf(text, ch);
138: }
139:
140: /**
141: * Implementation of {@link String#lastIndexOf(int,int)} for character sequences.
142: */
143: public static int lastIndexOf(CharSequence text, int ch,
144: int fromIndex) {
145: return CharSequenceUtilities.lastIndexOf(text, ch, fromIndex);
146: }
147:
148: /**
149: * Implementation of {@link String#startsWith(String)} for character sequences.
150: */
151: public static boolean startsWith(CharSequence text,
152: CharSequence prefix) {
153: return CharSequenceUtilities.startsWith(text, prefix);
154: }
155:
156: /**
157: * Implementation of {@link String#endsWith(String)} for character sequences.
158: */
159: public static boolean endsWith(CharSequence text,
160: CharSequence suffix) {
161: return CharSequenceUtilities.endsWith(text, suffix);
162: }
163:
164: /**
165: * Implementation of {@link String#trim()} for character sequences.
166: */
167: public static CharSequence trim(CharSequence text) {
168: return CharSequenceUtilities.trim(text);
169: }
170:
171: /**
172: * Return the given text as String
173: * translating the special characters (and '\') into escape sequences.
174: *
175: * @param text non-null text to be debugged.
176: * @return non-null string containing the debug text.
177: */
178: public static String debugText(CharSequence text) {
179: return CharSequenceUtilities.debugText(text);
180: }
181:
182: }
|