本文整理了Java中org.apache.calcite.util.Util.replace()
方法的一些代码示例,展示了Util.replace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.replace()
方法的具体详情如下:
包路径:org.apache.calcite.util.Util
类名称:Util
方法名:replace
[英]Replaces every occurrence of find
in s
with replace
.
[中]将s
中出现的find
替换为replace
。
代码示例来源:origin: hortonworks/streamline
public static String escapeJavaString(String s, boolean nullMeansNull) {
if(s == null) {
return nullMeansNull ? "null" : "\"\"";
} else {
String s1 = Util.replace(s, "\\", "\\\\");
String s2 = Util.replace(s1, "\"", "\\\"");
String s3 = Util.replace(s2, "\n\r", "\\n");
String s4 = Util.replace(s3, "\n", "\\n");
String s5 = Util.replace(s4, "\r", "\\r");
return "\"" + s5 + "\"";
}
}
代码示例来源:origin: Qihoo360/Quicksql
/**
* Converts double-quoted Java strings to their contents. For example,
* <code>"foo\"bar"</code> becomes <code>foo"bar</code>.
*/
public static String stripDoubleQuotes(String value) {
assert value.charAt(0) == '"';
assert value.charAt(value.length() - 1) == '"';
String s5 = value.substring(1, value.length() - 1);
String s4 = Util.replace(s5, "\\r", "\r");
String s3 = Util.replace(s4, "\\n", "\n");
String s2 = Util.replace(s3, "\\\"", "\"");
String s1 = Util.replace(s2, "\\\\", "\\");
return s1;
}
代码示例来源:origin: org.apache.calcite/calcite-core
/**
* Converts double-quoted Java strings to their contents. For example,
* <code>"foo\"bar"</code> becomes <code>foo"bar</code>.
*/
public static String stripDoubleQuotes(String value) {
assert value.charAt(0) == '"';
assert value.charAt(value.length() - 1) == '"';
String s5 = value.substring(1, value.length() - 1);
String s4 = Util.replace(s5, "\\r", "\r");
String s3 = Util.replace(s4, "\\n", "\n");
String s2 = Util.replace(s3, "\\\"", "\"");
String s1 = Util.replace(s2, "\\\\", "\\");
return s1;
}
代码示例来源:origin: Qihoo360/Quicksql
/**
* Prints a string, enclosing in double quotes (") and escaping if
* necessary. For examples, <code>printDoubleQuoted(w,"x\"y",false)</code>
* prints <code>"x\"y"</code>.
*/
public static void printJavaString(
PrintWriter pw,
String s,
boolean nullMeansNull) {
if (s == null) {
if (nullMeansNull) {
pw.print("null");
}
} else {
String s1 = replace(s, "\\", "\\\\");
String s2 = replace(s1, "\"", "\\\"");
String s3 = replace(s2, "\n\r", "\\n");
String s4 = replace(s3, "\n", "\\n");
String s5 = replace(s4, "\r", "\\r");
pw.print("\"");
pw.print(s5);
pw.print("\"");
}
}
代码示例来源:origin: org.apache.calcite/calcite-core
/**
* Prints a string, enclosing in double quotes (") and escaping if
* necessary. For examples, <code>printDoubleQuoted(w,"x\"y",false)</code>
* prints <code>"x\"y"</code>.
*/
public static void printJavaString(
PrintWriter pw,
String s,
boolean nullMeansNull) {
if (s == null) {
if (nullMeansNull) {
pw.print("null");
}
} else {
String s1 = replace(s, "\\", "\\\\");
String s2 = replace(s1, "\"", "\\\"");
String s3 = replace(s2, "\n\r", "\\n");
String s4 = replace(s3, "\n", "\\n");
String s5 = replace(s4, "\r", "\\r");
pw.print("\"");
pw.print(s5);
pw.print("\"");
}
}
代码示例来源:origin: Qihoo360/Quicksql
/**
* Returns the string quoted for SQL, for example <code>_ISO-8859-1'is it a
* plane? no it''s superman!'</code>.
*
* @param prefix if true, prefix the character set name
* @param suffix if true, suffix the collation clause
* @return the quoted string
*/
public String asSql(
boolean prefix,
boolean suffix) {
StringBuilder ret = new StringBuilder();
if (prefix && (null != charsetName)) {
ret.append("_");
ret.append(charsetName);
}
ret.append("'");
ret.append(Util.replace(value, "'", "''"));
ret.append("'");
// NOTE jvs 3-Feb-2005: see FRG-78 for why this should go away
if (false) {
if (suffix && (null != collation)) {
ret.append(" ");
ret.append(collation.toString());
}
}
return ret.toString();
}
代码示例来源:origin: org.apache.calcite/calcite-core
/**
* Returns the string quoted for SQL, for example <code>_ISO-8859-1'is it a
* plane? no it''s superman!'</code>.
*
* @param prefix if true, prefix the character set name
* @param suffix if true, suffix the collation clause
* @return the quoted string
*/
public String asSql(
boolean prefix,
boolean suffix) {
StringBuilder ret = new StringBuilder();
if (prefix && (null != charsetName)) {
ret.append("_");
ret.append(charsetName);
}
ret.append("'");
ret.append(Util.replace(getValue(), "'", "''"));
ret.append("'");
// NOTE jvs 3-Feb-2005: see FRG-78 for why this should go away
if (false) {
if (suffix && (null != collation)) {
ret.append(" ");
ret.append(collation.toString());
}
}
return ret.toString();
}
代码示例来源:origin: org.apache.calcite/calcite-core
/**
* Converts a string (which may contain quotes and newlines) into a java
* literal.
*
* <p>For example,
* <pre><code>string with "quotes" split
* across lines</code></pre>
*
* <p>becomes
*
* <blockquote><pre><code>"string with \"quotes\" split" + NL +
* "across lines"</code></pre></blockquote>
*/
public static String quoteForJava(String s) {
s = Util.replace(s, "\\", "\\\\");
s = Util.replace(s, "\"", "\\\"");
s = LINE_BREAK_PATTERN.matcher(s).replaceAll(LINE_BREAK);
s = TAB_PATTERN.matcher(s).replaceAll("\\\\t");
s = "\"" + s + "\"";
final String spurious = " + \n\"\"";
if (s.endsWith(spurious)) {
s = s.substring(0, s.length() - spurious.length());
}
return s;
}
代码示例来源:origin: Qihoo360/Quicksql
/**
* Converts a string (which may contain quotes and newlines) into a java
* literal.
*
* <p>For example,
* <pre><code>string with "quotes" split
* across lines</code></pre>
*
* <p>becomes
*
* <blockquote><pre><code>"string with \"quotes\" split" + NL +
* "across lines"</code></pre></blockquote>
*/
public static String quoteForJava(String s) {
s = Util.replace(s, "\\", "\\\\");
s = Util.replace(s, "\"", "\\\"");
s = LINE_BREAK_PATTERN.matcher(s).replaceAll(LINE_BREAK);
s = TAB_PATTERN.matcher(s).replaceAll("\\\\t");
s = "\"" + s + "\"";
final String spurious = " + \n\"\"";
if (s.endsWith(spurious)) {
s = s.substring(0, s.length() - spurious.length());
}
return s;
}
代码示例来源:origin: Qihoo360/Quicksql
s = Util.replace(s, "\"", "\\\"");
s = LINE_BREAK_PATTERN.matcher(s).replaceAll(LINE_BREAK);
s = TAB_PATTERN.matcher(s).replaceAll("\\\\t");
代码示例来源:origin: org.apache.calcite/calcite-core
s = Util.replace(s, "\"", "\\\"");
s = LINE_BREAK_PATTERN.matcher(s).replaceAll(LINE_BREAK);
s = TAB_PATTERN.matcher(s).replaceAll("\\\\t");
内容来源于网络,如有侵权,请联系作者删除!