KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > lexer > gen > util > LexerGenUtilities


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.lexer.gen.util;
21
22 /**
23  * Utility methods.
24  *
25  * @author Miloslav Metelka
26  * @version 1.00
27  */

28
29 public class LexerGenUtilities {
30
31     /**
32      * Append given number of spaces to the given string buffer.
33      */

34     public static void appendSpaces(StringBuffer JavaDoc sb, int spaceCount) {
35         while (--spaceCount >= 0) {
36             sb.append(' ');
37         }
38     }
39
40     /** Split class full name into package name and class name.
41      * @param full name of the class
42      * @return array containing package name and the class name.
43      */

44     public static String JavaDoc[] splitClassName(String JavaDoc classFullName) {
45         int lastDotIndex = classFullName.lastIndexOf('.');
46         return new String JavaDoc[] {
47             (lastDotIndex >= 0) ? classFullName.substring(0, lastDotIndex) : "", // pkg name
48
classFullName.substring(lastDotIndex + 1) // class name
49
};
50     }
51     
52     /** @return original string converted to uppercase with
53      * hyphens converted to underscores.
54      * @param s original string.
55      */

56     public static String JavaDoc idToUpperCase(String JavaDoc s) {
57         return s.toUpperCase().replace('-', '_');
58     }
59     
60     /** @return original string converted to lowercase with
61      * underscores converted to hyphens.
62      * @param s original string.
63      */

64     public static String JavaDoc idToLowerCase(String JavaDoc s) {
65         return s.toLowerCase().replace('_', '-');
66     }
67
68     /** Convert string from the shape as it appears
69      * in the source file into regular java string.
70      */

71     public static String JavaDoc fromSource(String JavaDoc s) {
72         return LexerGenUtilitiesImpl.fromSource(s);
73     }
74
75     /**
76      * Escape passed string as XML element content (<code>&lt;</code>,
77      * <code>&amp;</code> and <code>><code> in <code>]]></code> sequences).
78      * @param text non-null string to be escaped
79      * @return escaped text for xml
80      */

81     public static String JavaDoc toElementContent(String JavaDoc text) {
82         return LexerGenUtilitiesImpl.toElementContent(text);
83     }
84
85 }
86
Popular Tags