本文整理了Java中org.apache.commons.lang3.StringEscapeUtils.unescapeCsv()
方法的一些代码示例,展示了StringEscapeUtils.unescapeCsv()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.unescapeCsv()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringEscapeUtils
类名称:StringEscapeUtils
方法名:unescapeCsv
[英]Returns a String value for an unescaped CSV column.
If the value is enclosed in double quotes, and contains a comma, newline or double quote, then quotes are removed.
Any double quote escaped characters (a pair of double quotes) are unescaped to just one double quote.
If the value is not enclosed in double quotes, or is and does not contain a comma, newline or double quote, then the String value is returned unchanged.
see Wikipedia and RFC 4180.
[中]返回未转换的CSV列的字符串值。
如果该值用双引号括起来,并且包含逗号、换行符或双引号,则会删除引号。
任何双引号转义字符(一对双引号)都不会转换为一个双引号。
如果该值未包含在双引号中,或者不包含逗号、换行符或双引号,则返回的字符串值将保持不变。
见Wikipedia和{$1$}。
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeCsvString() throws Exception {
assertEquals("foo.bar", StringEscapeUtils.unescapeCsv("foo.bar"));
assertEquals("foo,bar", StringEscapeUtils.unescapeCsv("\"foo,bar\""));
assertEquals("foo\nbar", StringEscapeUtils.unescapeCsv("\"foo\nbar\""));
assertEquals("foo\rbar", StringEscapeUtils.unescapeCsv("\"foo\rbar\""));
assertEquals("foo\"bar", StringEscapeUtils.unescapeCsv("\"foo\"\"bar\""));
assertEquals("foo\uD84C\uDFB4bar", StringEscapeUtils.unescapeCsv("foo\uD84C\uDFB4bar"));
assertEquals("", StringEscapeUtils.unescapeCsv(""));
assertNull(StringEscapeUtils.unescapeCsv(null));
assertEquals("\"foo.bar\"", StringEscapeUtils.unescapeCsv("\"foo.bar\""));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeSurrogatePairs() throws Exception {
assertEquals("\uD83D\uDE30", StringEscapeUtils.unescapeCsv("\uD83D\uDE30"));
// Examples from https://en.wikipedia.org/wiki/UTF-16
assertEquals("\uD800\uDC00", StringEscapeUtils.unescapeCsv("\uD800\uDC00"));
assertEquals("\uD834\uDD1E", StringEscapeUtils.unescapeCsv("\uD834\uDD1E"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeCsv("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml3("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml4("\uDBFF\uDFFD"));
}
代码示例来源:origin: org.eclipse.dirigible/dirigible-api-facade-utils
/**
* Unescape CSV.
*
* @param input
* the input
* @return the unescaped input
*/
public static final String unescapeCsv(String input) {
return StringEscapeUtils.unescapeCsv(input);
}
代码示例来源:origin: com.github.dactiv/dactiv-common
/**
* Csv 解码.
*/
public static String unescapeCsv(String csvEscaped) {
return StringEscapeUtils.unescapeCsv(csvEscaped);
}
代码示例来源:origin: org.eclipse.dirigible/dirigible-api-utils
/**
* Unescape CSV.
*
* @param input
* the input
* @return the unescaped input
*/
public static final String unescapeCsv(String input) {
return StringEscapeUtils.unescapeCsv(input);
}
代码示例来源:origin: opendedup/sdfs
public static HashMap<String, String> deSerializeHashMap(byte[] b) {
ByteBuffer buf = ByteBuffer.wrap(b);
byte[] kb = new byte[buf.getInt()];
buf.get(kb);
byte[] vb = new byte[buf.getInt()];
buf.get(vb);
String[] keys = new String(kb).split(",");
String[] values = new String(vb).split(",");
HashMap<String, String> map = new HashMap<String, String>();
for (int i = 0; i < keys.length; i++) {
try {
map.put(StringEscapeUtils.unescapeCsv(keys[i]), StringEscapeUtils.unescapeCsv(values[i]));
} catch (Exception e) {
SDFSLogger.getLog().error("unable to get value for " + i + " " + keys[i] + " vl" +values.length,e);
}
}
return map;
}
代码示例来源:origin: uk.q3c.krail/krail
public <E> OptionList<E> convertToModel(@Nonnull OptionList<E> defaultValue, @Nonnull String value) {
checkNotNull(value);
checkNotNull(defaultValue);
Class<E> elementClass = defaultValue.getElementClass();
if (value.isEmpty()) {
return new OptionList<>(elementClass);
}
final List<String> strings = Splitter.on(separator)
.splitToList(value);
List<E> elementList = new ArrayList<>();
strings.forEach(s -> {
String unescaped = StringEscapeUtils.unescapeCsv(s);
elementList.add(converter.convertStringToValue(elementClass, unescaped));
});
return new OptionList<E>(elementList, elementClass);
}
}
代码示例来源:origin: org.xworker/xworker_core
public static String unescapeCsv(ActionContext actionContext){
Thing self = actionContext.getObject("self");
String str = (String) self.doAction("getStr", actionContext);
return StringEscapeUtils.unescapeCsv(str);
}
}
代码示例来源:origin: uk.q3c.krail/krail
/**
* Converts String representation, {@code value}, to model
*
* @param value the String to convert
* @return Comma separated String representation of the list contents
* @throws ConversionException if conversion fails
*/
public AnnotationOptionList convertToModel(@Nonnull String value) {
checkNotNull(value);
if (value.isEmpty()) {
return new AnnotationOptionList();
}
final List<String> strings = Splitter.on(separator)
.splitToList(value);
List<Class<? extends Annotation>> elementList = new ArrayList<>();
strings.forEach(s -> {
String unescaped = StringEscapeUtils.unescapeCsv(s);
Class<?> element = new ClassConverter().convertToModel(unescaped);
if (Annotation.class.isAssignableFrom(element)) {
//noinspection unchecked
elementList.add((Class<? extends Annotation>) element);
} else {
throw new ConversionException("Class " + element + " is not an Annotation");
}
});
return new AnnotationOptionList(elementList);
}
}
代码示例来源:origin: uk.q3c.util/q3c-util
/**
* Converts String representation, {@code value}, to model
*
* @param value the String to convert
* @return Comma separated String representation of the list contents
* @throws ConversionException if conversion fails
*/
public AnnotationList convertToModel(String value) {
checkNotNull(value);
if (value.isEmpty()) {
return new AnnotationList();
}
final List<String> strings = Splitter.on(separator)
.splitToList(value);
List<Class<? extends Annotation>> elementList = new ArrayList<>();
strings.forEach(s -> {
String unescaped = StringEscapeUtils.unescapeCsv(s);
Class<?> element = new ClassConverter().convertToModel(unescaped);
if (Annotation.class.isAssignableFrom(element)) {
//noinspection unchecked
elementList.add((Class<? extends Annotation>) element);
} else {
throw new ConversionException("Class " + element + " is not an Annotation");
}
});
return new AnnotationList(elementList);
}
}
内容来源于网络,如有侵权,请联系作者删除!