Skip to content

Commit 48c0301

Browse files
committed
数字を含む場合のパターンを考慮
aa1BbbCcc => aa1_bbb_ccc
1 parent 598f726 commit 48c0301

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/main/java/org/seasar/doma/internal/util/StringUtil.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
/**
2121
* {@link String} のユーティリティクラスです。
22-
*
22+
*
2323
* @author taedium
24-
*
24+
*
2525
*/
2626
public final class StringUtil {
2727

2828
/**
2929
* 先頭の文字を大文字に変換します。
30-
*
30+
*
3131
* @param text
3232
* 文字列
3333
* @return 変換された文字列。 ただし、{@code text} が {@code null} の場合は {@code null}、
@@ -44,7 +44,7 @@ public static String capitalize(String text) {
4444

4545
/**
4646
* 先頭の文字を小文字に変換します。
47-
*
47+
*
4848
* @param text
4949
* 文字列
5050
* @return 変換された文字列。 ただし、{@code text} が {@code null} の場合は {@code null}、
@@ -61,7 +61,7 @@ public static String decapitalize(String text) {
6161

6262
/**
6363
* アンダースコア区切りの文字列をキャメルケースの文字列に変換します。
64-
*
64+
*
6565
* @param text
6666
* 文字列
6767
* @return 変換された文字列。 ただし、{@code text} が {@code null} の場合は {@code null}、
@@ -86,7 +86,7 @@ public static String fromSnakeCaseToCamelCase(String text) {
8686

8787
/**
8888
* キャメルケースをアンダースコア区切りの大文字に変換します。
89-
*
89+
*
9090
* @param text
9191
* 文字列
9292
* @return 変換された文字列。 ただし、{@code text} が {@code null} の場合は {@code null}、
@@ -104,7 +104,7 @@ public static String fromCamelCaseToSnakeCase(String text) {
104104
buf.mark();
105105
if (buf.hasRemaining()) {
106106
char c2 = buf.get();
107-
if (Character.isLowerCase(c) && Character.isUpperCase(c2)) {
107+
if ((Character.isLowerCase(c) || Character.isDigit(c)) && Character.isUpperCase(c2)) {
108108
result.append("_");
109109
}
110110
buf.reset();
@@ -115,7 +115,7 @@ public static String fromCamelCaseToSnakeCase(String text) {
115115

116116
/**
117117
* 文字列が空白文字だけからなるかどうかを返します。
118-
*
118+
*
119119
* @param text
120120
* 文字列
121121
* @return 文字列が空白文字のみを含む場合 {@code true}

src/test/java/org/seasar/doma/internal/util/StringUtilTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/**
2121
* @author taedium
22-
*
22+
*
2323
*/
2424
public class StringUtilTest extends TestCase {
2525

@@ -44,6 +44,7 @@ public void testFromCamelCaseToSnakeCase() throws Exception {
4444
assertEquals("aaa_bbb_ccc",
4545
StringUtil.fromCamelCaseToSnakeCase("aaaBbbCcc"));
4646
assertEquals("abc", StringUtil.fromCamelCaseToSnakeCase("abc"));
47+
assertEquals("aa1_bbb_ccc", StringUtil.fromCamelCaseToSnakeCase("aa1BbbCcc"));
4748
}
4849

4950
public void testIsWhitespace() throws Exception {

0 commit comments

Comments
 (0)