all characters except quote, <tt>;</tt> and <tt>\\ + n</tt>
429631
Rule NonQuoteOneTextLine() {
		//TODO TexText?
		return FirstOf(SP(),
				'!',
				CharRange('#', ':'),
				CharRange('<', '~'),
				LatinExtendedAndOtherAlphabet()
			).label(NonQuoteOneTextLine).suppressSubnodes();
	}
181792
public boolean quotedString(char quote,TextProvider textProvider)        
    {
        clearLastToken(textProvider);
        clearLeadingSpaces(textProvider);
        mark(textProvider);
        if (m_debug)
			debug("testing "+quote,textProvider);

        if (getNextChar(textProvider) != quote)
        {
            reset(textProvider);
            return false;
        }
        char lastChar = 0;
        char c = 0;
        StringBuilder sb = new StringBuilder();
        while (true)
        {
            lastChar = c;
            c = getNextChar(textProvider);
			if (c == 0) {
		        unmark(textProvider);
				return false;
			}
            if (c == quote && lastChar != '\\') break;
            sb.append(c);
        }
        unmark(textProvider);
        String s = sb.toString().trim();
        if (s.length() == 0) return false;
        textProvider.setLastToken(s);
        debug(textProvider);
        return true;
    }
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)
814438
private char rdQuotedCh() throws LexException
	{
		quotedQuote = false;
		char c = rdCh();

		if (c == '\\')
		{
			rdCh();

			switch (ch)
			{
				case 'r':
					ch = '\r';
					break;
				case 'n':
					ch = '\n';
					break;
				case 't':
					ch = '\t';
					break;
				case 'f':
					ch = '\f';
					break;
				case 'e':
					ch = '\033';
					break;
				case 'a':
					ch = '\007';
					break;
				case '\'':
					ch = '\'';
					break;
				case '\"':
					ch = '\"';
					quotedQuote = true;
					break;
				case '\\':
					ch = '\\';
					break;

				case 'x':
					ch = (char) (value(rdCh()) * 16 + value(rdCh()));
					break;

				case 'c':
					ch = (char) (rdCh() - 'A' + 1); // eg. CTRL-A = 1
					break;

				case 'u':
					ch = (char) (value(rdCh()) * 4096 + value(rdCh()) * 256
							+ value(rdCh()) * 16 + value(rdCh()));
					break;

				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
					ch = (char) (value(ch) * 64 + value(rdCh()) * 8 + value(rdCh()));
					break;

				default:
					throwMessage(1000, "Malformed quoted character");
			}
		}

		return ch;
	}
307947
private void quote(final String val) throws IOException {
    if (val.indexOf("\"") < 0) {
      value(val, "\"");
    } else {
      value(val, "'");
    }
  }
1294766
def escape_b(s, quote=True):
    ''''''
    s = s.replace(b"&", b"&amp;") # Must be done first!
    s = s.replace(b"<", b"&lt;")
    s = s.replace(b">", b"&gt;")
    if quote:
        s = s.replace(b'"', b"&quot;")
    return s
724647
static void escape(final char[] text, final int offset, final int len, final Writer writer)
                       throws IOException {

        if (text == null || text.length == 0) {
            return;
        }

        final int max = (offset + len);

        int readOffset = offset;

        for (int i = offset; i < max; i++) {

            final char c = text[i];


            /*
             * Shortcut: most characters will be Alphanumeric, and we won't need to do anything at
             * all for them.
             */
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
                continue;
            }


            /*
             * At this point we know for sure we will need some kind of escape, so we
             * initialize the string builder.
             */
            if (readOffset == offset) {
                // If we need this, it's because we have non-alphanumeric chars. And that means
                // we should enclose in double-quotes.
                writer.write(DOUBLE_QUOTE);
            }

            /*
             * Now we copy all the contents pending up to this point.
             */
            if (i - readOffset > 0) {
                writer.write(text, readOffset, (i - readOffset));
            }

            readOffset = i + 1;

            /*
             * Check whether the character is a double-quote (in which case, we escape it)
             */
            if (c == DOUBLE_QUOTE) {
                writer.write(TWO_DOUBLE_QUOTES);
                continue;
            }

            writer.write(c);

        }


        /*
         * -----------------------------------------------------------------------------------------------
         * Final cleaning: append the remaining unescaped text to the string builder and return.
         * -----------------------------------------------------------------------------------------------
         */

        if (max - readOffset > 0) {
            writer.write(text, readOffset, (max - readOffset));
        }

        if (readOffset > offset) {
            // If we reached here, it's because we had non-alphanumeric chars. And that means
            // we should enclose in double-quotes.
            writer.write(DOUBLE_QUOTE);
        }

    }
273303
def escape_dn_chars(s):
    
    if s:
        assert isinstance(s, six.string_types)
        s = s.replace('\\', '\\\\')
        s = s.replace(',', '\\,')
        s = s.replace('+', '\\+')
        s = s.replace('"', '\\"')
        s = s.replace('<', '\\<')
        s = s.replace('>', '\\>')
        s = s.replace(';', '\\;')
        s = s.replace('=', '\\=')
        s = s.replace('\000', '\\\000')
        if s[0] == '#' or s[0] == ' ':
            s = ''.join(('\\', s))
        if s[-1] == ' ':
            s = ''.join((s[:-1], '\\ '))
    return s
795741
def _indent(indent=0, quote='', indent_char=' '):
    """"""
    if indent > 0:
        indent_string = ''.join((
            str(quote),
            (indent_char * (indent - len(quote)))
        ))
    else:
        indent_string = ''.join((
            ('\x08' * (-1 * (indent - len(quote)))),
            str(quote))
        )

    if len(indent_string):
        INDENT_STRINGS.append(indent_string)
627348
static public String stripQuotes(String string0) {
        // if an empty string, return it
        if (string0.length() == 0) {
            return string0;
        }
        // if the first and last characters are quotes, just do 1 substring
        if (string0.length() > 1 && string0.charAt(0) == '"' && string0.charAt(string0.length() - 1) == '"') {
            return string0.substring(1, string0.length() - 1);
        } else if (string0.charAt(0) == '"') {
            string0 = string0.substring(1);
        } else if (string0.charAt(string0.length() - 1) == '"') {
            string0 = string0.substring(0, string0.length() - 1);
        }
        return string0;
    }
296369
private void _string() throws
      IOException,
      CssException
  {

    if (debug)
    {
      checkState(QUOTES.matches((char) reader.curChar));
    }

    /*
       * Note: resulting token excludes start+end quotes
       */

    builder.type = Type.STRING;
    int quoteType = reader.curChar;

    // in strings, we let escapes in general pass through
    while (true)
    {
      CssReader.Mark mark = reader.mark();
      int ch = reader.next();
      if (ch == -1)
      {
        builder.error(SCANNER_PREMATURE_EOF, reader);
        reader.unread(ch, mark);
        break;
      }
      else if (ch == '\n' || ch == '\r' || ch == '\f')
      {
        builder.error(SCANNER_ILLEGAL_CHAR, reader, "NEWLINE",
            Type.STRING.name());
        reader.forward(TERMINATOR);
        break;
      }
      else if (ch == '\\')
      {
        int[] peek = reader.peek(2);
        int nl = isNewLine(peek);
        if (nl > 0)
        {
          // in strings, ignore backslash followed by a literal
          // newline
          reader.forward(nl);
          continue;
        }

      }
      else if (ch == quoteType && reader.prevChar != '\\')
      {
        break;
      }

      builder.append(ch);
    }

    if (debug && builder.errors.size() == 0)
    {
      checkState(QUOTES.matches((char) reader.curChar));
    }
  }
39402
public static String dequoteFull(String str, char quote)
    {
        if (str == null)
        {
            return null;
        }

        return dequoteFull(str, 0, str.length(), quote);
    }
859306
def quote(self, data):
        
        if self.lang == 'python':
            quote_char = "'"
        elif self.lang == 'java':
            quote_char = "'"

        if re.findall(r'[!\-\=\s\$\&]{1,}', str(data)):
            data = '{0}{1}{0}'.format(quote_char, data)
        return data
1160534
@Override
    protected String escapeCharacter(char ch, char previousChar) {
      if(ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r') {
          return "";
      }
      switch(ch) {
          case '&': return ESCAPED_AMP;
          case '<': return ESCAPED_LT;
          case '>': return ESCAPED_GT;
          case '"': return ESCAPED_QUOTE;
          case '\'': return  ESCAPED_APOS;
          case '\\': return  ESCAPED_BACKSLASH;
          case '@': return ESCAPED_AT;
          case '`': return ESCAPED_BACKTICK;
          case NBSP: return ESCAPED_NON_BREAKING_SPACE;
          case LINE_SEPARATOR: return ESCAPED_LINE_SEPARATOR;
          case PARAGRAPH_SEPARATOR: return ESCAPED_PARAGRAPH_SEPARATOR;
      }
      return null;
    }
14569
public char[] quoteAsString(String input) {
        TextBuffer textBuffer = _textBuffer;
        if (textBuffer == null) {
            // no allocator; can add if we must, shouldn't need to
            _textBuffer = textBuffer = new TextBuffer(null);
        }
        char[] outputBuffer = textBuffer.emptyAndGetCurrentSegment();
        final int[] escCodes = sOutputEscapes128;
        final int escCodeCount = escCodes.length;
        int inPtr = 0;
        final int inputLen = input.length();
        int outPtr = 0;

        outer_loop: while (inPtr < inputLen) {
            tight_loop: while (true) {
                char c = input.charAt(inPtr);
                if (c < escCodeCount && escCodes[c] != 0) {
                    break tight_loop;
                }
                if (outPtr >= outputBuffer.length) {
                    outputBuffer = textBuffer.finishCurrentSegment();
                    outPtr = 0;
                }
                outputBuffer[outPtr++] = c;
                if (++inPtr >= inputLen) {
                    break outer_loop;
                }
            }
        // something to escape; 2 or 6-char variant?
        int escCode = escCodes[input.charAt(inPtr++)];
        int length = _appendSingleEscape(escCode, _quoteBuffer);
        if ((outPtr + length) > outputBuffer.length) {
            int first = outputBuffer.length - outPtr;
            if (first > 0) {
                System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, first);
            }
            outputBuffer = textBuffer.finishCurrentSegment();
            int second = length - first;
            System.arraycopy(_quoteBuffer, first, outputBuffer, outPtr, second);
            outPtr += second;
        }
        else {
            System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, length);
            outPtr += length;
        }

        }
        textBuffer.setCurrentLength(outPtr);
        return textBuffer.contentsAsArray();
    }
846969
private void serializeNoQuoteTo(String s, Writer writer, boolean escapeSlash, boolean unicodeEscapeAll) throws UncheckedIOException {
		try {
			char[] carr = s.toCharArray();
			int len = carr.length;
			for(int i = 0; i < len; i++) {
				char c = carr[i];
				switch (c) {
				case '"':
					writer.write("\\\"");
					break;
				case '/':
					writer.write(escapeSlash ? "\\/" : "/");
					break;
				case '\\':
					writer.write("\\\\");
					break;
				case '\b':
					writer.write("\\b");
					break;
				case '\f':
					writer.write("\\f");
					break;
				case '\n':
					writer.write("\\n");
					break;
				case '\r':
					writer.write("\\r");
					break;
				case '\t':
					writer.write("\\t");
					break;
				default:
					if(unicodeEscapeAll) {
						if(c < 127) {
							writer.append(c);
						} else {
							String hex = Integer.toHexString(c);
							writer.write("\\u");
							switch (hex.length()) {
							case 1:
								writer.write("000");
								break;
							case 2:
								writer.write("00");
								break;
							case 3:
								writer.write("0");
								break;
							default:
								break;
							}
							writer.write(Integer.toHexString(c));
						}
					} else {
						writer.append(c);
					}
					break;
				}
			}
		} catch(IOException e) {
			throw EX.uncheckedIO(e);
		}
	}
1186441
public static String unquoteHtmlChars(String item) {
    if (item == null) {
      return null;
    }
    int next = item.indexOf('&');
    // nothing was quoted
    if (next == -1) {
      return item;
    }
    int len = item.length();
    int posn = 0;
    StringBuilder buffer = new StringBuilder();
    while (next != -1) {
      buffer.append(item.substring(posn, next));
      if (item.startsWith("&amp;", next)) {
        buffer.append('&');
        next += 5;
      } else if (item.startsWith("&apos;", next)) {
        buffer.append('\'');
        next += 6;        
      } else if (item.startsWith("&gt;", next)) {
        buffer.append('>');
        next += 4;
      } else if (item.startsWith("&lt;", next)) {
        buffer.append('<');
        next += 4;
      } else if (item.startsWith("&quot;", next)) {
        buffer.append('"');
        next += 6;
      } else {
        int end = item.indexOf(';', next)+1;
        if (end == 0) {
          end = len;
        }
        throw new IllegalArgumentException("Bad HTML quoting for " + 
                                           item.substring(next,end));
      }
      posn = next;
      next = item.indexOf('&', posn);
    }
    buffer.append(item.substring(posn, len));
    return buffer.toString();
  }