@Test public void testToUnderlineCase() { Assert.assertNull(StrKit.toUnderlineCase(null)); Assert.assertEquals("1", StrKit.toUnderlineCase("1")); Assert.assertEquals("foo", StrKit.toUnderlineCase("foo")); Assert.assertEquals("bar", StrKit.toUnderlineCase("Bar")); Assert.assertEquals("baz", StrKit.toUnderlineCase("BAZ")); Assert.assertEquals("a1_b2_c3", StrKit.toUnderlineCase("A1B2C3")); }
public static String toUnderlineCase(String camelCaseStr) { if (camelCaseStr == null) { return null; } final int length = camelCaseStr.length(); StringBuilder sb = new StringBuilder(); char c; boolean isPreUpperCase = false; for (int i = 0; i < length; i++) { c = camelCaseStr.charAt(i); boolean isNextUpperCase = true; if (i < (length - 1)) { isNextUpperCase = Character.isUpperCase(camelCaseStr.charAt(i + 1)); } if (Character.isUpperCase(c)) { if (!isPreUpperCase || !isNextUpperCase) { if (i > 0){ sb.append(UNDERLINE);} } isPreUpperCase = true; } else { isPreUpperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); }
StrKit { public static String toUnderlineCase(String camelCaseStr) { if (camelCaseStr == null) { return null; } final int length = camelCaseStr.length(); StringBuilder sb = new StringBuilder(); char c; boolean isPreUpperCase = false; for (int i = 0; i < length; i++) { c = camelCaseStr.charAt(i); boolean isNextUpperCase = true; if (i < (length - 1)) { isNextUpperCase = Character.isUpperCase(camelCaseStr.charAt(i + 1)); } if (Character.isUpperCase(c)) { if (!isPreUpperCase || !isNextUpperCase) { if (i > 0){ sb.append(UNDERLINE);} } isPreUpperCase = true; } else { isPreUpperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); } }
StrKit { public static String toUnderlineCase(String camelCaseStr) { if (camelCaseStr == null) { return null; } final int length = camelCaseStr.length(); StringBuilder sb = new StringBuilder(); char c; boolean isPreUpperCase = false; for (int i = 0; i < length; i++) { c = camelCaseStr.charAt(i); boolean isNextUpperCase = true; if (i < (length - 1)) { isNextUpperCase = Character.isUpperCase(camelCaseStr.charAt(i + 1)); } if (Character.isUpperCase(c)) { if (!isPreUpperCase || !isNextUpperCase) { if (i > 0){ sb.append(UNDERLINE);} } isPreUpperCase = true; } else { isPreUpperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); }  }
StrKit { public static String toUnderlineCase(String camelCaseStr) { if (camelCaseStr == null) { return null; } final int length = camelCaseStr.length(); StringBuilder sb = new StringBuilder(); char c; boolean isPreUpperCase = false; for (int i = 0; i < length; i++) { c = camelCaseStr.charAt(i); boolean isNextUpperCase = true; if (i < (length - 1)) { isNextUpperCase = Character.isUpperCase(camelCaseStr.charAt(i + 1)); } if (Character.isUpperCase(c)) { if (!isPreUpperCase || !isNextUpperCase) { if (i > 0){ sb.append(UNDERLINE);} } isPreUpperCase = true; } else { isPreUpperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); }  static String firstCharToLowerCase(String str); static String firstCharToUpperCase(String str); static boolean isEmpty(String str); static boolean isNotEmpty(String str); static String nullToEmpty(String str); static String nullToDefault(String str, String defaultStr); static String toUnderlineCase(String camelCaseStr); static String toCamelCase(String name); }
StrKit { public static String toUnderlineCase(String camelCaseStr) { if (camelCaseStr == null) { return null; } final int length = camelCaseStr.length(); StringBuilder sb = new StringBuilder(); char c; boolean isPreUpperCase = false; for (int i = 0; i < length; i++) { c = camelCaseStr.charAt(i); boolean isNextUpperCase = true; if (i < (length - 1)) { isNextUpperCase = Character.isUpperCase(camelCaseStr.charAt(i + 1)); } if (Character.isUpperCase(c)) { if (!isPreUpperCase || !isNextUpperCase) { if (i > 0){ sb.append(UNDERLINE);} } isPreUpperCase = true; } else { isPreUpperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); }  static String firstCharToLowerCase(String str); static String firstCharToUpperCase(String str); static boolean isEmpty(String str); static boolean isNotEmpty(String str); static String nullToEmpty(String str); static String nullToDefault(String str, String defaultStr); static String toUnderlineCase(String camelCaseStr); static String toCamelCase(String name); static final String SPACE; static final String DOT; static final String SLASH; static final String BACKSLASH; static final String EMPTY; static final String CRLF; static final String NEWLINE; static final String UNDERLINE; static final String COMMA; static final String HTML_NBSP; static final String HTML_AMP; static final String HTML_QUOTE; static final String HTML_LT; static final String HTML_GT; static final String EMPTY_JSON; }