本文整理汇总了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;
}