Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

对JSONResponse.java中的formatHyphen方法的优化 #217

Merged
merged 1 commit into from
Apr 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions APIJSONORM/src/main/java/apijson/JSONResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
Expand Down Expand Up @@ -502,23 +503,17 @@ public static String formatColon(@NotNull String key) {
* @return
*/
public static String formatHyphen(@NotNull String key, boolean firstCase) {
boolean first = true;
int index;

String name = "";
String part;
do {
index = key.indexOf("-");
part = index < 0 ? key : key.substring(0, index);

name += firstCase && first == false ? StringUtil.firstCase(part, true) : part;
key = key.substring(index + 1);

first = false;
}
while (index >= 0);
StringTokenizer parts = new StringTokenizer(key, "-");
name += parts.nextToken();
while(parts.hasMoreTokens())
{
String part = parts.nextToken();
name += firstCase ? StringUtil.firstCase(part, true) : part;
}

return name;
return name;
}


Expand Down