本文整理了Java中org.apache.commons.lang.StringEscapeUtils.escapeCsv()
方法的一些代码示例,展示了StringEscapeUtils.escapeCsv()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeCsv()
方法的具体详情如下:
包路径:org.apache.commons.lang.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeCsv
[英]Writes a String
value for a CSV column enclosed in double quotes, if required.
If the value contains a comma, newline or double quote, then the String value is written enclosed in double quotes.
Any double quote characters in the value are escaped with another double quote.
If the value does not contain a comma, newline or double quote, then the String value is written unchanged (null values are ignored).
see Wikipedia and RFC 4180.
[中]如果需要,为用双引号括起来的CSV列写入String
值。
如果该值包含逗号、换行符或双引号,则字符串值用双引号括起来。
值中的任何双引号字符都用另一个双引号转义。
如果该值不包含逗号、换行符或双引号,则字符串值的写入将保持不变(忽略空值)。
见Wikipedia和{$1$}。
代码示例来源:origin: SonarSource/sonarqube
private static String valuesToCsv(String... values) {
StringBuilder sb = new StringBuilder();
for (String value : values) {
sb.append(StringEscapeUtils.escapeCsv(value));
sb.append(OPTION_SEPARATOR);
}
return sb.toString();
}
代码示例来源:origin: SonarSource/sonarqube
private RuleParamType(String type, boolean multiple, String... values) {
this.type = type;
this.values = asList(values);
StringBuilder sb = new StringBuilder();
sb.append(type);
if (multiple) {
sb.append(OPTION_SEPARATOR);
sb.append(MULTIPLE_PARAM + PARAMETER_SEPARATOR);
sb.append(Boolean.toString(multiple));
}
if (values.length > 0) {
sb.append(OPTION_SEPARATOR);
sb.append(VALUES_PARAM + PARAMETER_SEPARATOR);
sb.append(StringEscapeUtils.escapeCsv(valuesToCsv(values)));
}
this.key = sb.toString();
this.multiple = multiple;
}
代码示例来源:origin: commons-lang/commons-lang
escapeCsv(writer, str);
return writer.toString();
} catch (IOException ioe) {
代码示例来源:origin: SonarSource/sonarqube
public CsvWriter values(String... values) {
for (int index = 0; index < values.length; index++) {
if (index > 0) {
write(VALUE_SEPARATOR);
}
String value = values[index];
if (value != null) {
write(StringEscapeUtils.escapeCsv(value));
}
if (index == values.length - 1) {
write(LINE_SEPARATOR);
}
}
return this;
}
代码示例来源:origin: de.smartics.properties/smartics-properties-transfer-templatestream
@Override
public String escape(final String value)
{
return StringEscapeUtils.escapeCsv(value);
}
});
代码示例来源:origin: org.owasp.jbrofuzz/jbrofuzz
private static String encodeEscCsv(final String encodeText) {
return StringEscapeUtils.escapeCsv(encodeText);
}
代码示例来源:origin: perfectsense/dari
public static String escapeCsv(String string) {
return string == null ? null : StringEscapeUtils.escapeCsv(string);
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
@Override
public String format(Template template, Object value) {
if (value != null) {
return StringEscapeUtils.escapeCsv(value.toString());
}
return "";
}
}
代码示例来源:origin: vmware/hillview
private String quote(String message) {
message = message.replace("\n", "\\n");
return StringEscapeUtils.escapeCsv(message);
}
代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api
private String valuesToCsv(String... values) {
StringBuilder sb = new StringBuilder();
for (String value : values) {
sb.append(StringEscapeUtils.escapeCsv(value));
sb.append(OPTION_SEPARATOR);
}
return sb.toString();
}
代码示例来源:origin: BriData/DBus
/**
* Converts connection properties to a String to be passed to the mappers.
* @param properties JDBC connection parameters
* @return String to be passed to configuration
*/
protected static String propertiesToString(Properties properties) {
List<String> propertiesList = new ArrayList<String>(properties.size());
for(Entry<Object, Object> property : properties.entrySet()) {
String key = StringEscapeUtils.escapeCsv(property.getKey().toString());
if (key.equals(property.getKey().toString()) && key.contains("=")) {
key = "\"" + key + "\"";
}
String val = StringEscapeUtils.escapeCsv(property.getValue().toString());
if (val.equals(property.getValue().toString()) && val.contains("=")) {
val = "\"" + val + "\"";
}
propertiesList.add(StringEscapeUtils.escapeCsv(key + "=" + val));
}
return StringUtils.join(propertiesList, ',');
}
代码示例来源:origin: tflobbe/solrmeter
@Override
protected String getSelectedValue() {
Map<String, String> properties = this.table.getProperties();
List<String> propList = new ArrayList<String>(properties.size());
for(String prop: this.table.getPropertiesNames()){
String newProp = prop + "=" + (properties.get(prop)!=null?properties.get(prop):"");
newProp = StringEscapeUtils.escapeCsv(newProp);
propList.add(newProp);
}
return StringUtils.join(propList, ',');
}
代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api
private RuleParamType(String type, boolean multiple, String... values) {
this.type = type;
this.values = newArrayList(values);
StringBuilder sb = new StringBuilder();
sb.append(type);
if (multiple) {
sb.append(OPTION_SEPARATOR);
sb.append(MULTIPLE_PARAM + PARAMETER_SEPARATOR);
sb.append(Boolean.toString(multiple));
}
if (values.length > 0) {
sb.append(OPTION_SEPARATOR);
sb.append(VALUES_PARAM + PARAMETER_SEPARATOR);
sb.append(StringEscapeUtils.escapeCsv(valuesToCsv(values)));
}
this.key = sb.toString();
this.multiple = multiple;
}
代码示例来源:origin: baishui2004/common_gui_tools
/**
* 转义字符.
*
* @param string 字符
* @param type 字符类型
*/
public static String escape(String string, String type) {
String unescape = "不支持对" + type + "字符的转义";
if (type.equals(LanguageUtils.CONST_HTML)) {
unescape = StringEscapeUtils.escapeHtml(string);
} else if (type.equals(LanguageUtils.CONST_XML)) {
unescape = StringEscapeUtils.escapeXml(string);
} else if (type.equals(LanguageUtils.CONST_SQL)) {
unescape = StringEscapeUtils.escapeSql(string);
} else if (type.equals(LanguageUtils.CONST_JAVA)) {
unescape = StringEscapeUtils.escapeJava(string);
} else if (type.equals(LanguageUtils.CONST_JavaScript)) {
unescape = StringEscapeUtils.escapeJavaScript(string);
} else if (type.equals(LanguageUtils.CONST_CSV)) {
unescape = StringEscapeUtils.escapeCsv(string);
}
return unescape;
}
代码示例来源:origin: googleads/googleads-java-lib
validateSetValueEntryForSet(csvValue, csvValues);
if (csvValue instanceof String) {
csvValue = StringEscapeUtils.escapeCsv((String) csvValue);
代码示例来源:origin: googleads/googleads-java-lib
validateSetValueEntryForSet(csvValue, csvValues);
if (csvValue instanceof String) {
csvValue = StringEscapeUtils.escapeCsv((String) csvValue);
代码示例来源:origin: googleads/googleads-java-lib
validateSetValueEntryForSet(csvValue, csvValues);
if (csvValue instanceof String) {
csvValue = StringEscapeUtils.escapeCsv((String) csvValue);
代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api
public CsvWriter values(String... values) {
for (int index = 0; index < values.length; index++) {
if (index > 0) {
write(VALUE_SEPARATOR);
}
String value = values[index];
if (value != null) {
write(StringEscapeUtils.escapeCsv(value));
}
if (index == values.length - 1) {
write(LINE_SEPARATOR);
}
}
return this;
}
代码示例来源:origin: org.apache.lens/lens-query-lib
/**
* Inits the column fields.
*
* @param metadata the metadata
*/
private void initColumnFields(LensResultSetMetadata metadata) {
StringBuilder typesSb = new StringBuilder();
StringBuilder headerTypes = new StringBuilder();
if ((metadata != null) && (metadata.getColumns() != null) && (!metadata.getColumns().isEmpty())) {
for (int pos = 0; pos < metadata.getColumns().size(); pos++) {
if (pos != 0) {
typesSb.append(",");
headerTypes.append(",");
}
String name = metadata.getColumns().get(pos).getName();
String type = LensResultSetMetadata.getQualifiedTypeName(metadata.getColumns().get(pos).getTypeDescriptor());
typesSb.append(type);
columnNames.add(name);
escapedColumnNames.add(StringEscapeUtils.escapeCsv(name));
TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(type);
columnTypes.add(typeInfo);
columnOIs.add(TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo));
columnHeaderOIs.add(TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(TypeInfoUtils
.getTypeInfoFromTypeString(HEADER_TYPE)));
headerTypes.append(HEADER_TYPE);
}
}
types = typesSb.toString();
htypes = headerTypes.toString();
}
代码示例来源:origin: apache/lens
/**
* Inits the column fields.
*
* @param metadata the metadata
*/
private void initColumnFields(LensResultSetMetadata metadata) {
StringBuilder typesSb = new StringBuilder();
StringBuilder headerTypes = new StringBuilder();
if ((metadata != null) && (metadata.getColumns() != null) && (!metadata.getColumns().isEmpty())) {
for (int pos = 0; pos < metadata.getColumns().size(); pos++) {
if (pos != 0) {
typesSb.append(",");
headerTypes.append(",");
}
String name = metadata.getColumns().get(pos).getName();
String type = LensResultSetMetadata.getQualifiedTypeName(metadata.getColumns().get(pos).getTypeDescriptor());
typesSb.append(type);
columnNames.add(name);
escapedColumnNames.add(StringEscapeUtils.escapeCsv(name));
TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(type);
columnTypes.add(typeInfo);
columnOIs.add(TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo));
columnHeaderOIs.add(TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(TypeInfoUtils
.getTypeInfoFromTypeString(HEADER_TYPE)));
headerTypes.append(HEADER_TYPE);
}
}
types = typesSb.toString();
htypes = headerTypes.toString();
}
内容来源于网络,如有侵权,请联系作者删除!