src/share/jaxws_classes/com/sun/xml/internal/ws/util/StringUtils.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
equal deleted inserted replaced
-1:000000000000 0:373ffda63c9a
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.util;
27
28 /**
29 *
30 * @author WS Development Team
31 */
32 public class StringUtils {
33
34 /**
35 * Utility method to take a string and convert it to normal Java variable
36 * name capitalization. This normally means converting the first
37 * character from upper case to lower case, but in the (unusual) special
38 * case when there is more than one character and both the first and
39 * second characters are upper case, we leave it alone.
40 * <p>
41 * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays
42 * as "URL".
43 *
44 * @param name The string to be decapitalized.
45 * @return The decapitalized version of the string.
46 */
47 public static String decapitalize(String name) {
48 if (name == null || name.length() == 0) {
49 return name;
50 }
51 if (name.length() > 1 &&
52 Character.isUpperCase(name.charAt(1)) &&
53 Character.isUpperCase(name.charAt(0))) {
54
55 return name;
56 }
57 char chars[] = name.toCharArray();
58 chars[0] = Character.toLowerCase(chars[0]);
59 return new String(chars);
60 }
61
62 /**
63 * Utility method to take a string and convert it to normal a string
64 * with the first character in upper case.
65 * <p>
66 * Thus "fooBah" becomes "FooBah" and "x" becomes "X".\
67 *
68 * @param name The string to be capitalized.
69 * @return The capitalized version of the string.
70 */
71 public static String capitalize(String name) {
72 if (name == null || name.length() == 0) {
73 return name;
74 }
75 char chars[] = name.toCharArray();
76 chars[0] = Character.toUpperCase(chars[0]);
77 return new String(chars);
78 }
79 }

mercurial