Make text into a single-quoted YAML string with correct escaping
    for special characters.  Includes the opening and closing single
    quote characters.
428492
def yaml_squote(text):
    '''
    
    '''
    with io.StringIO() as ostream:
        yemitter = yaml.emitter.Emitter(ostream, width=six.MAXSIZE)
        yemitter.write_single_quoted(six.text_type(text))
        return ostream.getvalue()
1280660
def _dash_escape_text(text: str) -> str:
        
        dash_escaped_text = str()

        for line in text.splitlines(True):
            # add dash '-' (0x2D) and space ' ' (0x20) as prefix
            dash_escaped_text += DASH_ESCAPE_PREFIX + line

        return dash_escaped_text
54481
def quotemeta(text):
    
    text = re.sub(r'/', '//', text)
    text = re.sub(r'\\{', '/{', text)
    text = re.sub(r'\\}', '/}', text)
    return text
248109
private static String buildText(String text) {
    // <JAR><JAR> to PARAGRAPH mark in unicode
    text = doubleLineBreak.matcher(text).replaceAll(PARAGRAPH);
    // <JAR> to " "
    text = lineBreak.matcher(text).replaceAll(" ");
    return text;
  }
453628
def _normalize_string(self, text):
        '''
        '''
        conversion = {
            # newlines
            '\r?\n': ' ',
            # replace excessive empty spaces
            '\s+': ' ',
            # convert all types of hyphens/dashes to a
            # simple old-school dash
            # from http://utf8-chartable.de/unicode-utf8-table.pl?
            # start=8192&number=128&utf8=string-literal
            '‐': '-',
            '‑': '-',
            '‒': '-',
            '–': '-',
            '—': '-',
            '―': '-',
        }
        for find, replace in six.iteritems(conversion):
            text = re.sub(find, replace, text, flags=re.UNICODE)
        return text
907077
def quoted(text):
    
    if text and " " in text:
        sep = "'" if '"' in text else '"'
        return "%s%s%s" % (sep, text, sep)
    return text
355192
def escape(string, quote=False):
    
    if string is None:
        return ''
    elif hasattr(string, '__html__'):
        return unicode(string)
    string = string.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
    if quote:
        string = string.replace('"', "&quot;")
    return string
786235
def quote(text):
  ''

  # Convert to unicode.
  if not isinstance(text, unicode):
    text = text.decode('utf-8')

  # Look for quote characters. Keep the text as is if it's already quoted.
  for qp in QUOTEPAIRS:
    if text[0] == qp[0] and text[-1] == qp[-1] and len(text) >= 2:
      return text

  # If it's not quoted, try quoting
  for qp in QUOTEPAIRS:
    if qp[1] not in text:
      return qp[0] + text + qp[1]

  #Darn
  raise ValueError(u'The value "%s" is not quoted and contains too many quote characters to quote' % text)
961856
private static String escapeString(String s, char quote,
                          String doublequoteEscape,
                          String singlequoteEscape,
                          String backslashEscape) {
    StringBuilder sb = new StringBuilder(s.length() + 2);
    sb.append(quote);
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      switch (c) {
        case '\n': sb.append("\\n"); break;
        case '\r': sb.append("\\r"); break;
        case '\t': sb.append("\\t"); break;
        case '\\': sb.append(backslashEscape); break;
        case '\"': sb.append(doublequoteEscape); break;
        case '\'': sb.append(singlequoteEscape); break;
        case '>':
          // Unicode-escape the '>' in '-->' and ']]>'
          if (i >= 2
              && ((s.charAt(i - 1) == '-' && s.charAt(i - 2) == '-')
                  || (s.charAt(i - 1) == ']' && s.charAt(i - 2) == ']'))) {
            sb.append("\\u003e");
          } else {
            sb.append(c);
          }
          break;
        case '<':
          // Unicode-escape the '<' in '</script' and '<!--'
          final String END_SCRIPT = "/script";
          final String START_COMMENT = "!--";

          if (s.regionMatches(true, i + 1, END_SCRIPT, 0,
                              END_SCRIPT.length())) {
            sb.append("\\u003c");
          } else if (s.regionMatches(false, i + 1, START_COMMENT, 0,
                                     START_COMMENT.length())) {
            sb.append("\\u003c");
          } else {
            sb.append(c);
          }
          break;
        default:
          // No charsetEncoder provided - pass straight Latin characters
          // through, and escape the rest.  Doing the explicit character
          // check is measurably faster than using the CharsetEncoder.
          if (c > 0x1f && c <= 0x7f) {
            sb.append(c);
          } else {
            // Other characters can be misinterpreted by some JS parsers,
            // or perhaps mangled by proxies along the way,
            // so we play it safe and Unicode escape them.
            appendHexJavaScriptRepresentation(sb, c);
          }
      }
    }
    sb.append(quote);
    return sb.toString();
  }
91556
def _escapeText(text):
	
	output = ""
	index = 0
	match = reCharsToEscape.search(text, index)
	while match:
		output = output + text[index:match.start()] + '\\' + text[match.start()]
		index = match.end()
		match = reCharsToEscape.search(text, index)
	output = output + text[index:]
	return output
1207430
public static boolean doesStringContainOpenQuote(String text) {
        boolean doubleQuote = false;
        boolean singleQuote = false;
        boolean escapedByBackSlash = false;
        // do not parse comment
        if (commentPattern.matcher(text).find())
            return false;

        for (int i = 0; i < text.length(); i++) {
             if (text.charAt(i) == BACK_SLASH || escapedByBackSlash) {
                 escapedByBackSlash = !escapedByBackSlash;
                 continue;
             }
            if (text.charAt(i) == SINGLE_QUOTE) {
                if (!doubleQuote)
                    singleQuote = !singleQuote;
            }
            else if (text.charAt(i) == DOUBLE_QUOTE) {
                if (!singleQuote)
                    doubleQuote = !doubleQuote;
            }
        }
        return doubleQuote || singleQuote;
    }
89305
function(contents, quoteChar, indentString, htmlmin) {
  var content = contents;

  if(Object.keys(htmlmin).length) {
    try{
      content = minify(content, htmlmin);
    } catch(err) {
      gutil.log(filepath + '\n' + err);
    }
  }

  return escapeContent(content, quoteChar, indentString);
}
716014
private static String escapeDoubleQuotes(String s, int beginIndex, int endIndex) {

        if (s == null || s.length() == 0 || s.indexOf('"') == -1) {
            return s;
        }

        StringBuilder b = new StringBuilder();
        for (int i = beginIndex; i < endIndex; i++) {
            char c = s.charAt(i);
            if (c == '\\' ) {
                b.append(c);
                //ignore the character after an escape, just append it
                if (++i>=endIndex) throw UndertowMessages.MESSAGES.invalidEscapeCharacter();
                b.append(s.charAt(i));
            } else if (c == '"')
                b.append('\\').append('"');
            else
                b.append(c);
        }

        return b.toString();
    }
436951
def _escapify(qstring):
    

    text = ''
    for c in qstring:
        if c in __escaped:
            text += '\\' + c
        elif ord(c) >= 0x20 and ord(c) < 0x7F:
            text += c
        else:
            text += '\\%03d' % ord(c)
    return text
517138
def wash_for_js(text):
    
    from invenio_utils.html import escape_javascript_string
    if isinstance(text, six.string_types):
        return '"%s"' % escape_javascript_string(
            text,
            escape_for_html=False,
            escape_CDATA=False,
            escape_script_tag_with_quote=None)
    else:
        return text
670367
def quote_xml(text):
    
    text = _coerce_unicode(text)

    # If it's a CDATA block, return the text as is.
    if text.startswith(CDATA_START):
        return text

    # If it's not a CDATA block, escape the XML and return the character
    # encoded string.
    return saxutils.escape(text)
671090
def escape(self, string):
        
        html_entities = {"&": "&amp;", '<': '&lt;', '>': '&gt;'}
        return HTML("".join(html_entities.get(c, c) for c in string))