Moved unStudlyName() into StringUtil from where other deserving callers
can make use of it. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1532 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -683,31 +683,6 @@ public class Table {
|
||||
", primaryKeys=" + StringUtil.toString(primaryKeys) + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a name like <code>weAreSoCool</code> to a column name of
|
||||
* the form <code>we_are_so_cool</code>.
|
||||
*/
|
||||
public static String unStudlyName (String name)
|
||||
{
|
||||
boolean seenLower = false;
|
||||
StringBuffer nname = new StringBuffer();
|
||||
int nlen = name.length();
|
||||
for (int i = 0; i < nlen; i++) {
|
||||
char c = name.charAt(i);
|
||||
// if we see an upper case character and we've seen a lower
|
||||
// case character since the last time we did so, slip in an _
|
||||
if (Character.isUpperCase(c)) {
|
||||
nname.append("_");
|
||||
seenLower = false;
|
||||
nname.append(c);
|
||||
} else {
|
||||
seenLower = true;
|
||||
nname.append(Character.toUpperCase(c));
|
||||
}
|
||||
}
|
||||
return nname.toString();
|
||||
}
|
||||
|
||||
/** Spearator of name components of compound field. For example, if Java
|
||||
* class constains component "location" of Point class, which
|
||||
* has two components "x" and "y", then database table should
|
||||
@@ -882,7 +857,7 @@ public class Table {
|
||||
private final String convertName (String name)
|
||||
{
|
||||
if (mixedCaseConvert) {
|
||||
return unStudlyName(name);
|
||||
return StringUtil.unStudlyName(name);
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -1194,6 +1194,31 @@ public class StringUtil
|
||||
return name.substring(didx+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a name of the form <code>weAreSoCool</code> to a name of
|
||||
* the form <code>we_are_so_cool</code>.
|
||||
*/
|
||||
public static String unStudlyName (String name)
|
||||
{
|
||||
boolean seenLower = false;
|
||||
StringBuffer nname = new StringBuffer();
|
||||
int nlen = name.length();
|
||||
for (int i = 0; i < nlen; i++) {
|
||||
char c = name.charAt(i);
|
||||
// if we see an upper case character and we've seen a lower
|
||||
// case character since the last time we did so, slip in an _
|
||||
if (Character.isUpperCase(c)) {
|
||||
nname.append("_");
|
||||
seenLower = false;
|
||||
nname.append(c);
|
||||
} else {
|
||||
seenLower = true;
|
||||
nname.append(Character.toUpperCase(c));
|
||||
}
|
||||
}
|
||||
return nname.toString();
|
||||
}
|
||||
|
||||
private final static String XLATE = "0123456789abcdef";
|
||||
|
||||
/** Used to easily format floats with sensible defaults. */
|
||||
|
||||
Reference in New Issue
Block a user