本文整理匯總了Java中org.apache.commons.lang.StringUtils.chomp方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.chomp方法的具體用法?Java StringUtils.chomp怎麽用?Java StringUtils.chomp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.StringUtils
的用法示例。
在下文中一共展示了StringUtils.chomp方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: valueOf
import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
@Override
public MutableList<String> valueOf(String inputString) {
inputString += "\n"; // add sentinel to facilitate line split
MutableList<SqlToken> sqlTokens = this.tokenParser.parseTokens(inputString);
sqlTokens = this.collapseWhiteSpaceAndTokens(sqlTokens);
MutableList<String> finalSplitStrings = Lists.mutable.empty();
String currentSql = "";
for (SqlToken sqlToken : sqlTokens) {
if (sqlToken.getTokenType() == SqlTokenType.COMMENT || sqlToken.getTokenType() == SqlTokenType.STRING) {
currentSql += sqlToken.getText();
} else {
String pattern = splitOnWholeLine ? "(?i)^" + this.splitToken + "$" : this.splitToken;
MutableList<String> splitStrings =
Lists.mutable.with(Pattern.compile(pattern, Pattern.MULTILINE).split(sqlToken.getText()));
if (splitStrings.isEmpty()) {
// means that we exactly match
finalSplitStrings.add(currentSql);
currentSql = "";
} else if (splitStrings.size() == 1) {
currentSql += sqlToken.getText();
} else {
splitStrings.set(0, currentSql + splitStrings.get(0));
if (splitOnWholeLine) {
if (splitStrings.size() > 1) {
splitStrings.set(0, StringUtils.chomp(splitStrings.get(0)));
for (int i = 1; i < splitStrings.size(); i++) {
String newSql = splitStrings.get(i);
if (newSql.startsWith("\n")) {
newSql = newSql.replaceFirst("^\n", "");
} else if (newSql.startsWith("\r\n")) {
newSql = newSql.replaceFirst("^\r\n", "");
}
// Chomping the end of each sql due to the split of the GO statement
if (i < splitStrings.size() - 1) {
newSql = StringUtils.chomp(newSql);
}
splitStrings.set(i, newSql);
}
}
}
finalSplitStrings.addAll(splitStrings.subList(0, splitStrings.size() - 1));
currentSql = splitStrings.getLast();
}
}
}
if (!currentSql.isEmpty()) {
finalSplitStrings.add(currentSql);
}
// accounting for the sentinel
if (finalSplitStrings.getLast().isEmpty()) {
finalSplitStrings.remove(finalSplitStrings.size() - 1);
} else {
finalSplitStrings.set(finalSplitStrings.size() - 1, StringUtils.chomp(finalSplitStrings.getLast()));
}
return finalSplitStrings;
}