org.apache.felix.utils.properties.Properties.escapeJava()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中org.apache.felix.utils.properties.Properties.escapeJava()方法的一些代码示例,展示了Properties.escapeJava()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.escapeJava()方法的具体详情如下:
包路径:org.apache.felix.utils.properties.Properties
类名称:Properties
方法名:escapeJava

Properties.escapeJava介绍

[英]Escapes the characters in a String using Java String rules.

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't'.

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

Example:

input string: He didn't say, "Stop!" 
output string: He didn't say, \"Stop!\"

[中]使用Java字符串规则转义String中的字符。
正确处理引号和控制字符(制表符、反斜杠、cr、ff等)
所以一个标签变成了字符'\\'和[$2$]。
Java字符串和JavaScript字符串之间的唯一区别是,在JavaScript中,必须转义一个引号。
例子:

input string: He didn't say, "Stop!" 
output string: He didn't say, \"Stop!\"

代码示例

代码示例来源:origin: org.everit.osgi.bundles/org.everit.osgi.bundles.org.apache.felix.utils

public String put(String key, List<String> commentLines, List<String> valueLines) {
  commentLines = new ArrayList<String>(commentLines);
  valueLines = new ArrayList<String>(valueLines);
  String escapedKey = escapeKey(key);
  int lastLine = valueLines.size() - 1;
  if (valueLines.isEmpty()) {
    valueLines.add(escapedKey + "=");
  } else if (!valueLines.get(0).trim().startsWith(escapedKey)) {
    valueLines.set(0, escapedKey + " = " + escapeJava(valueLines.get(0)) + (0 < lastLine? "\\": ""));
  }
  for (int i = 1; i < valueLines.size(); i++) {
    valueLines.set(i, escapeJava(valueLines.get(i)) + (i < lastLine? "\\": ""));
  }
  StringBuilder value = new StringBuilder();
  for (String line: valueLines) {
    value.append(line);
  }
  this.layout.put(key, new Layout(commentLines, valueLines));
  return storage.put(key, unescapeJava(value.toString()));
}

代码示例来源:origin: org.apache.felix/org.apache.felix.utils

} else {
  String val0 = valueLines.get(0);
  String rv0 = typed ? val0 : escapeJava(val0);
  if (!val0.trim().startsWith(escapedKey)) {
    valueLines.set(0, escapedKey + " = " + rv0 /*+ (0 < lastLine? "\\": "")*/);
  valueLines.set(i, typed ? val : escapeJava(val) /*+ (i < lastLine? "\\": "")*/);
  while (val.length() > 0 && Character.isWhitespace(val.charAt(0))) {
    val = val.substring(1);

代码示例来源:origin: apache/felix

} else {
  String val0 = valueLines.get(0);
  String rv0 = typed ? val0 : escapeJava(val0);
  if (!val0.trim().startsWith(escapedKey)) {
    valueLines.set(0, escapedKey + " = " + rv0 /*+ (0 < lastLine? "\\": "")*/);
  valueLines.set(i, typed ? val : escapeJava(val) /*+ (i < lastLine? "\\": "")*/);
  while (val.length() > 0 && Character.isWhitespace(val.charAt(0))) {
    val = val.substring(1);

代码示例来源:origin: org.apache.felix/org.apache.felix.fileinstall

} else {
  String val0 = valueLines.get(0);
  String rv0 = typed ? val0 : escapeJava(val0);
  if (!val0.trim().startsWith(escapedKey)) {
    valueLines.set(0, escapedKey + " = " + rv0 /*+ (0 < lastLine? "\\": "")*/);
  valueLines.set(i, typed ? val : escapeJava(val) /*+ (i < lastLine? "\\": "")*/);
  while (val.length() > 0 && Character.isWhitespace(val.charAt(0))) {
    val = val.substring(1);

代码示例来源:origin: apache/felix

/**
 * Writes the given property and its value.
 *
 * @param key the property key
 * @param value the property value
 * @throws java.io.IOException if an error occurs
 */
public void writeProperty(String key, String value) throws IOException
{
  write(escapeKey(key));
  write(" = ");
  write(typed ? value : escapeJava(value));
  writeln(null);
}

代码示例来源:origin: org.apache.felix/org.apache.felix.fileinstall

/**
 * Writes the given property and its value.
 *
 * @param key the property key
 * @param value the property value
 * @throws java.io.IOException if an error occurs
 */
public void writeProperty(String key, String value) throws IOException
{
  write(escapeKey(key));
  write(" = ");
  write(typed ? value : escapeJava(value));
  writeln(null);
}

代码示例来源:origin: org.everit.osgi.bundles/org.everit.osgi.bundles.org.apache.felix.utils

/**
 * Writes the given property and its value.
 *
 * @param key the property key
 * @param value the property value
 * @throws java.io.IOException if an error occurs
 */
public void writeProperty(String key, String value) throws IOException
{
  write(escapeKey(key));
  write(" = ");
  write(escapeJava(value));
  writeln(null);
}

代码示例来源:origin: org.apache.felix/org.apache.felix.utils

/**
 * Writes the given property and its value.
 *
 * @param key the property key
 * @param value the property value
 * @throws java.io.IOException if an error occurs
 */
public void writeProperty(String key, String value) throws IOException
{
  write(escapeKey(key));
  write(" = ");
  write(typed ? value : escapeJava(value));
  writeln(null);
}

相关文章