List of usage examples for org.apache.commons.lang3 CharUtils CR
char CR
To view the source code for org.apache.commons.lang3 CharUtils CR.
Click Source Link
From source file:ch.cyberduck.core.AbstractHostCollection.java
/** * @param h Bookmark// w ww . j a v a 2 s . co m * @return User comment for bookmark or null */ public String getComment(final Host h) { if (StringUtils.isNotBlank(h.getComment())) { return StringUtils.remove(StringUtils.remove(h.getComment(), CharUtils.LF), CharUtils.CR); } return null; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Removes one newline from end of a String if it's there, * otherwise leave it alone. A newline is "{@code \n}", * "{@code \r}", or "{@code \r\n}".</p> * * <p>NOTE: This method changed in 2.0. * It now more closely matches Perl chomp.</p> * * <pre>/*from w w w.jav a 2 s.co m*/ * 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") = "" * </pre> * * @param str the String to chomp a newline from, may be null * @return String without newline, {@code null} if null String input */ public static String chomp(String str) { if (isEmpty(str)) { return str; } if (str.length() == 1) { char ch = str.charAt(0); if (ch == CharUtils.CR || ch == CharUtils.LF) { return EMPTY; } return str; } int lastIdx = str.length() - 1; char last = str.charAt(lastIdx); if (last == CharUtils.LF) { if (str.charAt(lastIdx - 1) == CharUtils.CR) { lastIdx--; } } else if (last != CharUtils.CR) { lastIdx++; } return str.substring(0, lastIdx); }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Remove the last character from a String.</p> * * <p>If the String ends in {@code \r\n}, then remove both * of them.</p>/*from www .j a v a 2 s . c om*/ * * <pre> * StringUtils.chop(null) = null * StringUtils.chop("") = "" * StringUtils.chop("abc \r") = "abc " * StringUtils.chop("abc\n") = "abc" * StringUtils.chop("abc\r\n") = "abc" * StringUtils.chop("abc") = "ab" * StringUtils.chop("abc\nabc") = "abc\nab" * StringUtils.chop("a") = "" * StringUtils.chop("\r") = "" * StringUtils.chop("\n") = "" * StringUtils.chop("\r\n") = "" * </pre> * * @param str the String to chop last character from, may be null * @return String without last character, {@code null} if null String input */ public static String chop(String str) { if (str == null) { return null; } int strLen = str.length(); if (strLen < 2) { return EMPTY; } int lastIdx = strLen - 1; String ret = str.substring(0, lastIdx); char last = str.charAt(lastIdx); if (last == CharUtils.LF && ret.charAt(lastIdx - 1) == CharUtils.CR) { return ret.substring(0, lastIdx - 1); } return ret; }
From source file:bfile.util.StringUtils.java
/** * <p>Removes one newline from end of a String if it's there, * otherwise leave it alone. A newline is "{@code \n}", * "{@code \r}", or "{@code \r\n}".</p> * * <p>NOTE: This method changed in 2.0. * It now more closely matches Perl chomp.</p> * * <pre>// ww w . j av a 2 s. c o m * 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") = "" * </pre> * * @param str the String to chomp a newline from, may be null * @return String without newline, {@code null} if null String input */ public static String chomp(final String str) { if (isEmpty(str)) { return str; } if (str.length() == 1) { final char ch = str.charAt(0); if (ch == CharUtils.CR || ch == CharUtils.LF) { return EMPTY; } return str; } int lastIdx = str.length() - 1; final char last = str.charAt(lastIdx); if (last == CharUtils.LF) { if (str.charAt(lastIdx - 1) == CharUtils.CR) { lastIdx--; } } else if (last != CharUtils.CR) { lastIdx++; } return str.substring(0, lastIdx); }
From source file:bfile.util.StringUtils.java
/** * <p>Remove the last character from a String.</p> * * <p>If the String ends in {@code \r\n}, then remove both * of them.</p>/*from www. ja v a 2s .c om*/ * * <pre> * StringUtils.chop(null) = null * StringUtils.chop("") = "" * StringUtils.chop("abc \r") = "abc " * StringUtils.chop("abc\n") = "abc" * StringUtils.chop("abc\r\n") = "abc" * StringUtils.chop("abc") = "ab" * StringUtils.chop("abc\nabc") = "abc\nab" * StringUtils.chop("a") = "" * StringUtils.chop("\r") = "" * StringUtils.chop("\n") = "" * StringUtils.chop("\r\n") = "" * </pre> * * @param str the String to chop last character from, may be null * @return String without last character, {@code null} if null String input */ public static String chop(final String str) { if (str == null) { return null; } final int strLen = str.length(); if (strLen < 2) { return EMPTY; } final int lastIdx = strLen - 1; final String ret = str.substring(0, lastIdx); final char last = str.charAt(lastIdx); if (last == CharUtils.LF && ret.charAt(lastIdx - 1) == CharUtils.CR) { return ret.substring(0, lastIdx - 1); } return ret; }
From source file:org.apache.jmeter.report.core.CsvSampleWriter.java
@Override public long write(Sample sample) { Validate.validState(writer != null, "No writer set! Call setWriter() first!"); StringBuilder row = new StringBuilder(); char[] specials = new char[] { separator, CSVSaveService.QUOTING_CHAR, CharUtils.CR, CharUtils.LF }; for (int i = 0; i < columnCount; i++) { String data = sample.getData(i); row.append(CSVSaveService.quoteDelimiters(data, specials)).append(separator); }//from w ww . j a v a 2 s .c o m row.setLength(row.length() - 1); writer.println(row.toString()); sampleCount++; return sampleCount; }