本文整理汇总了Java中com.google.common.escape.Escapers类的典型用法代码示例。如果您正苦于以下问题:Java Escapers类的具体用法?Java Escapers怎么用?Java Escapers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Escapers类属于com.google.common.escape包,在下文中一共展示了Escapers类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportDatabaseAsTable
import com.google.common.escape.Escapers; //导入依赖的package包/类
/** Export as table for statistical software (R, pandas, ...) */
public void exportDatabaseAsTable() throws IOException {
List<FeedArticle> articles = getAllArticles();
BufferedWriter table = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("table.txt"), "UTF-8"));
char delimit = '\t';
// to make it readable for pandas read_table, quote strings and remove newlines
Function<String,String> strProcess = new Function<String,String>() {
private Escaper rmquote = Escapers.builder().addEscape('"', "").build();
private Escaper rmnewline = Escapers.builder().addEscape('\n', "").build();
@Override public String apply(String s) {
if (s == null) s = "";
s = rmquote.escape(s);
return new StringBuilder(s.length()+2).append('"').append(s).append('"').toString();
}
};
table.append(tableHeader(delimit)).append("\n");
for (FeedArticle art : articles) {
table.append(toTableRow(art, delimit, strProcess)).append("\n");
}
table.close();
}
示例2: testEscaping
import com.google.common.escape.Escapers; //导入依赖的package包/类
private static void testEscaping() {
char delimit = '\t';
String text = "who can\tescape the tab\tmonster";
Escaper e = Escapers.builder().addEscape(delimit, "\\"+delimit).build();
System.out.println(text);
System.out.println(e.escape(text));
}
示例3: escapeShellArgument
import com.google.common.escape.Escapers; //导入依赖的package包/类
public static String escapeShellArgument(String argument) {
final Escapers.Builder builder = Escapers.builder();
builder.addEscape('\'', "'\"'\"'");
Escaper escaper = builder.build();
return String.format("'%s'", escaper.escape(argument));
}