Skip to content

Commit e9131e5

Browse files
authored
Merge pull request #217 from 403f/tmpapijson
对JSONResponse.java中的formatHyphen方法的优化
2 parents 7d6226b + f4d8775 commit e9131e5

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

APIJSONORM/src/main/java/apijson/JSONResponse.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.List;
99
import java.util.Set;
10+
import java.util.StringTokenizer;
1011

1112
import com.alibaba.fastjson.JSONArray;
1213
import com.alibaba.fastjson.JSONObject;
@@ -502,23 +503,17 @@ public static String formatColon(@NotNull String key) {
502503
* @return
503504
*/
504505
public static String formatHyphen(@NotNull String key, boolean firstCase) {
505-
boolean first = true;
506-
int index;
507-
508506
String name = "";
509-
String part;
510-
do {
511-
index = key.indexOf("-");
512-
part = index < 0 ? key : key.substring(0, index);
513-
514-
name += firstCase && first == false ? StringUtil.firstCase(part, true) : part;
515-
key = key.substring(index + 1);
516507

517-
first = false;
518-
}
519-
while (index >= 0);
508+
StringTokenizer parts = new StringTokenizer(key, "-");
509+
name += parts.nextToken();
510+
while(parts.hasMoreTokens())
511+
{
512+
String part = parts.nextToken();
513+
name += firstCase ? StringUtil.firstCase(part, true) : part;
514+
}
520515

521-
return name;
516+
return name;
522517
}
523518

524519

0 commit comments

Comments
 (0)