org.apache.commons.lang3.StringUtils.chomp()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.apache.commons.lang3.StringUtils.chomp()方法的一些代码示例,展示了StringUtils.chomp()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.chomp()方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:chomp

StringUtils.chomp介绍

[英]Removes one newline from end of a String if it's there, otherwise leave it alone. A newline is " \n", " \r", or " \r\n".

NOTE: This method changed in 2.0. It now more closely matches Perl chomp.

StringUtils.chomp(null)          = null 
StringUtils.chomp("")            = "" 
StringUtils.chomp("abc \r")      = "abc " 
StringUtils.chomp("abc\n")       = "abc" 
StringUtils.chomp("abc\r\n")     = "abc" 
StringUtils.chomp("abc\r\n\r\n") = "abc\r\n" 
StringUtils.chomp("abc\n\r")     = "abc\n" 
StringUtils.chomp("abc\n\rabc")  = "abc\n\rabc" 
StringUtils.chomp("\r")          = "" 
StringUtils.chomp("\n")          = "" 
StringUtils.chomp("\r\n")        = ""

[中]从字符串的末尾删除一个换行符(若有),否则将其保留。换行符是“\n”、“\r”或“\r\n”。
注:此方法在2.0中更改。现在它与Perl chomp更为接近。

StringUtils.chomp(null)          = null 
StringUtils.chomp("")            = "" 
StringUtils.chomp("abc \r")      = "abc " 
StringUtils.chomp("abc\n")       = "abc" 
StringUtils.chomp("abc\r\n")     = "abc" 
StringUtils.chomp("abc\r\n\r\n") = "abc\r\n" 
StringUtils.chomp("abc\n\r")     = "abc\n" 
StringUtils.chomp("abc\n\rabc")  = "abc\n\rabc" 
StringUtils.chomp("\r")          = "" 
StringUtils.chomp("\n")          = "" 
StringUtils.chomp("\r\n")        = ""

代码示例

代码示例来源:origin: pmd/pmd

public static String getRuleSetFilename(String rulesetFileName) {
  return FilenameUtils.getBaseName(StringUtils.chomp(rulesetFileName));
}

代码示例来源:origin: pmd/pmd

public static String getRuleSetClasspath(RuleSet ruleset) {
  final String RESOURCES_PATH = "/resources/";
  String filename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName()), true);
  int startIndex = filename.lastIndexOf(RESOURCES_PATH);
  if (startIndex > -1) {
    return filename.substring(startIndex + RESOURCES_PATH.length());
  } else {
    return filename;
  }
}

代码示例来源:origin: pmd/pmd

final String rulesetFilename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName()));
final List<Path> foundPathResult = new LinkedList<>();
return StringUtils.chomp(ruleset.getFileName());

代码示例来源:origin: org.apache.commons/commons-lang3

final String expectedResult = chompCase[1];
  assertEquals("chomp(String) failed",
      expectedResult, StringUtils.chomp(original));
    "foo", StringUtils.chomp("foobar", "bar"));
assertEquals("chomp(String, String) failed",
    "foobar", StringUtils.chomp("foobar", "baz"));
assertEquals("chomp(String, String) failed",
    "foo", StringUtils.chomp("foo", "foooo"));
assertEquals("chomp(String, String) failed",
    "foobar", StringUtils.chomp("foobar", ""));
assertEquals("chomp(String, String) failed",
    "foobar", StringUtils.chomp("foobar", null));
assertEquals("chomp(String, String) failed",
    "", StringUtils.chomp("", "foo"));
assertEquals("chomp(String, String) failed",
    "", StringUtils.chomp("", null));
assertEquals("chomp(String, String) failed",
    "", StringUtils.chomp("", ""));
assertEquals("chomp(String, String) failed",
    null, StringUtils.chomp(null, "foo"));
assertEquals("chomp(String, String) failed",
    null, StringUtils.chomp(null, null));
assertEquals("chomp(String, String) failed",
    null, StringUtils.chomp(null, ""));
assertEquals("chomp(String, String) failed",
    "", StringUtils.chomp("foo", "foo"));
assertEquals("chomp(String, String) failed",
    " ", StringUtils.chomp(" foo", "foo"));

代码示例来源:origin: apache/metron

@Override
 public Object apply(List<Object> strings) {
  if(strings == null || strings.size() == 0 ) {
   throw new IllegalArgumentException("[CHOMP] missing argument: string to be chopped");
  }
  String var = strings.get(0) == null?null: (String) strings.get(0);
  if(var == null) {
   return null;
  }
  else if(var.length() == 0) {
   return var;
  }
  else {
   return StringUtils.chomp(var);
  }
 }
}

代码示例来源:origin: mulesoft/mule

strippedComments = StringUtils.chomp(strippedComments);

代码示例来源:origin: info.magnolia/magnolia-core

public PartialBootstrapTask(String name, String description, String resource, String itemPath, int importUUIDBehavior) {
  super(name, description);
  this.importUUIDBehavior = importUUIDBehavior;
  this.resource = resource;
  this.itemPath = StringUtils.chomp(itemPath, "/").replace(".", "..");
  this.itemName = StringUtils.substringAfterLast(itemPath, "/");
}

代码示例来源:origin: neoremind/fountain

@Override
public void parse(byte[] buf) {
  String value = new String(buf);
  value = StringUtils.chomp(value);
  groupId = new BigInteger(value);
}

代码示例来源:origin: org.apache.struts.xwork/xwork-core

private Set<String> convertPathsToPackages(Set<String> resources) {
  Set<String> packageNames = new HashSet<String>(resources.size());
  for(String resource : resources) {
    packageNames.add(StringUtils.chomp(StringUtils.replace(resource, "/", "."), "."));
  }
  return packageNames;
}

代码示例来源:origin: de.adorsys.multibanking/onlinebanking-hbci4java

private static String getUsage(List<String> lines) {
  StringBuilder sb = new StringBuilder();
  if (lines != null) {
    for (String line : lines) {
      if (line != null) {
        sb.append(StringUtils.chomp(line));
        sb.append(line.length() < 27 ? " " : "");
      }
    }
  }
  return WordUtils.capitalizeFully(sb.toString().trim(), ' ', '/');
}

代码示例来源:origin: de.agilecoders.wicket/wicket-bootstrap-core

/**
 * cleans the final markup
 *
 * @param content the markup to clean up
 * @return cleaned markup.
 */
protected String cleanContent(final String content) {
  return chomp(nullToEmpty(content)).replaceAll("\"", "\\\"");
}

代码示例来源:origin: neoremind/fountain

@Override
public void parse(byte[] buf) {
  String value = new String(buf);
  value = StringUtils.chomp(value);
  this.gtIdSet = GtIdSet.buildFromString(value);
}

代码示例来源:origin: com.haulmont.cuba/cuba-portal

/**
 * @param path path relative to the root of webapp
 * @return Full absolute path including protocol, domain and webapp prefix
 */
public String composeFullAbsolutePath(String path) {
  String webAppUrl = configuration.getConfig(GlobalConfig.class).getWebAppUrl();
  webAppUrl = StringUtils.chomp(webAppUrl, "/"); //remove last slash
  return path.startsWith("/") ? webAppUrl.concat(path) : webAppUrl.concat("/").concat(path);
}

代码示例来源:origin: neoremind/fountain

@Override
public void parse(byte[] buf) {
  String info = new String(buf);
  info = StringUtils.chomp(info);
  String[] array = info.split(";");
  for (String val : array) {
    MysqlSyncPoint pt = new MysqlSyncPoint();
    pt.fromString(val);
    syncPointGroup.add(pt);
  }
}

代码示例来源:origin: org.xworker/xworker_core

public static String chomp(ActionContext actionContext){
  Thing self = actionContext.getObject("self");
  String str  = (String) self.doAction("getStr", actionContext);
  return StringUtils.chomp(str);
}

代码示例来源:origin: iterate-ch/cyberduck

@Override
public void protocolReplyReceived(final ProtocolCommandEvent event) {
  this.log(Type.response, StringUtils.chomp(event.getMessage()));
}

代码示例来源:origin: stephenh/mirror

@Override
public void run() {
 String currentVersion = getVersion();
 System.out.println("Current Version: " + currentVersion);
 try {
  String latestVersion = chomp(Resources.asCharSource(new URL("http://repo.joist.ws/mirror-version"), Charsets.UTF_8).read());
  System.out.println("Latest Version: " + latestVersion);
  if (!currentVersion.equals(latestVersion)) {
   System.out.println("Comparison: https://github.com/stephenh/mirror/compare/" + toRef(currentVersion) + "..." + toRef(latestVersion));
  }
 } catch (Exception e) {
  log.error("Could not find latest version", e);
 }
}

代码示例来源:origin: iterate-ch/cyberduck

public BackgroundException map(final String message, final T failure) {
  final BackgroundException exception = this.map(failure);
  final StringBuilder m = new StringBuilder();
  this.append(m, StringUtils.chomp(LocaleFactory.localizedString(message, "Error")));
  exception.setMessage(m.toString());
  return exception;
}

代码示例来源:origin: iterate-ch/cyberduck

@Override
  public String getModificationTime(final String file) throws IOException {
    final String status = super.getModificationTime(file);
    if(null == status) {
      throw new FTPException(this.getReplyCode(), this.getReplyString());
    }
    return StringUtils.chomp(status.substring(3).trim());
  }
}

代码示例来源:origin: iterate-ch/cyberduck

@Override
public void protocolCommandSent(final ProtocolCommandEvent event) {
  final String message = StringUtils.chomp(event.getMessage());
  if(message.startsWith(FTPCmd.PASS.name())) {
    this.log(Type.request, String.format("%s %s", FTPCmd.PASS.name(),
        StringUtils.repeat("*", StringUtils.length(StringUtils.removeStart(message, FTPCmd.PASS.name())))));
  }
  else {
    this.log(Type.request, message);
  }
}

相关文章

StringUtils类方法