Quoting method used when outputting content that will be part of
DTD (internal/external subset). Additional quoting is needed for
percentage char, which signals parameter entities.
549390
public static void outputDTDText(Writer w, char[] ch, int offset, int len)
        throws IOException
    {
        int i = offset;
        len += offset;
        do {
            int start = i;
            char c = '\u0000';

            for (; i < len; ++i) {
                c = ch[i];
                if (c == '&' || c == '%' || c == '"') {
                    break;
                }
            }
            int outLen = i - start;
            if (outLen > 0) {
                w.write(ch, start, outLen);
            }
            if (i < len) {
                if (c == '&') {
                    /* Only need to quote to prevent it from being accidentally
                     * taken as part of char entity...
                     */
                    w.write("&amp;");
                } else if (c == '%') {
                    // Need to quote, to prevent use as Param Entity marker
                    w.write("&#37;");
                } else if (c == '"') {
                    // Need to quote assuming it encloses entity value
                    w.write("&#34;");
                }
            }
        } while (++i < len);
    }
812344
public static String quote(String s, String delim)
    {
        if (s==null)
            return null;
        if (s.length()==0)
            return "\"\"";

        
        for (int i=0;i<s.length();i++)
        {
            char c = s.charAt(i);
            if (c=='"' ||
                c=='\\' ||
                c=='\'' ||
                delim.indexOf(c)>=0)
            {
                StringBuffer b=new StringBuffer(s.length()+8);
                quote(b,s);
                return b.toString();
            }
        }
        
        return s;
    }
1105517
private String enrichMarkdown(String message, JsonNode entitiesNode, JsonNode mediaNode) throws InvalidInputException {

    TreeMap<Integer, JsonNode> entities = new TreeMap<>();
    TreeMap<Integer, JsonNode> media = new TreeMap<>();

    if (entitiesNode != null) {
      validateEntities(entitiesNode);
      for (JsonNode node : entitiesNode.findParents(INDEX_START)) {
        entities.put(node.get(INDEX_START).intValue(), node);
      }
    }

    if (mediaNode != null) {
      validateMedia(mediaNode);
      for (JsonNode node : mediaNode.findParents(INDEX)) {
        media.put(node.get(INDEX).intValue(), node.get(TEXT));
      }
    }

    // If entity indices are outside the message, pad the message to the necessary length
    int lastIndex = Math.max((!entities.isEmpty()) ? entities.lastKey() : 0, (!media.isEmpty()) ? media.lastKey() : 0);
    if (message.length() <= lastIndex) {
      message = StringUtils.rightPad(message, lastIndex + 1);
    }

    StringBuilder output = new StringBuilder();

    for (int i = 0; i < message.length(); i++) {
      char c = message.charAt(i);

      if (entities.containsKey(i)) {
        JsonNode entity = entities.get(i);
        String entityType = entity.get(TYPE).asText().toUpperCase();
        String id = entity.get(ID).asText();

        output.append(ENTITY_DELIMITER);
        output.append(entityType).append(FIELD_DELIMITER);
        output.append(id);
        output.append(ENTITY_DELIMITER);

        // We explicitly check the entity indices above, but make double sure that we don't get into an infinite loop here
        int endIndex = entity.get(INDEX_END).intValue() - 1;
        i = Math.max(endIndex, i);

      } else if (media.containsKey(i)) {
        JsonNode table = media.get(i);

        output.append(ENTITY_DELIMITER);
        output.append(TABLE).append(FIELD_DELIMITER);
        for (JsonNode row : table) {
          for (JsonNode cell : row) {
            String text = cell.asText();
            output.append(text).append(RECORD_DELIMITER);
          }
          output.append(GROUP_DELIMITER);
        }
        output.append(ENTITY_DELIMITER);
        output.append(c);
      } else {
        output.append(c);
      }
    }

    return output.toString();
  }
188582
private void _writeStringCustom(final int len)
			throws IOException, JsonGenerationException
	{
		// And then we'll need to verify need for escaping etc:
		int end = _outputTail + len;
		final int[] escCodes = _outputEscapes;
		final int maxNonEscaped = (_maximumNonEscapedChar < 1) ? 0xFFFF : _maximumNonEscapedChar;
		final int escLimit = Math.min(escCodes.length, maxNonEscaped+1);
		int escCode = 0;
		final CharacterEscapes customEscapes = _characterEscapes;

		output_loop:
		while (_outputTail < end) {
			char c;
			// Fast loop for chars not needing escaping
			escape_loop:
			while (true) {
				c = _outputBuffer[_outputTail];
				if (c < escLimit) {
					escCode = escCodes[c];
					if (escCode != 0) {
						break escape_loop;
					}
				} else if (c > maxNonEscaped) {
					escCode = CharacterEscapes.ESCAPE_STANDARD;
					break escape_loop;
				} else {
					if ((_currentEscape = customEscapes.getEscapeSequence(c)) != null) {
						escCode = CharacterEscapes.ESCAPE_CUSTOM;
						break escape_loop;
					}
				}
				if (++_outputTail >= end) {
					break output_loop;
				}
			}
			int flushLen = (_outputTail - _outputHead);
			if (flushLen > 0) {
				_writer.write(_outputBuffer, _outputHead, flushLen);
			}
			++_outputTail;
			_prependOrWriteCharacterEscape(c, escCode);
		}
	}
1195330
static Object appendQuotes(Object value)
    {
        if (value instanceof String || value instanceof Character)
        {
            StringBuilder builder = new StringBuilder();
            builder.append("\"");
            builder.append(value);
            builder.append("\"");
            return builder.toString();
        }
        return value;
    }
1101398
function (quote) {
      var str;
      var n = this.html.indexOf(quote, this.currentChar);
      if (n === -1) {
        this.currentChar = this.html.length;
        str = null;
      } else {
        str = this.html.substring(this.currentChar, n);
        this.currentChar = n + 1;
      }

      return str;
    }
639288
public static StringBuilder quotedString(String s) {
        final EscapeStringResult escapeString = escapeString(s, '\"');
        final StringBuilder result = escapeString.buffer;

        result.insert(0, '\"');
        result.append('\"');
        return result;
    }
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();
    }
381384
public static String quote(String identifier) {
        if (StringUtils.isEmpty(identifier)) {
            return identifier;
        }

        String res = identifier.trim();

        if (!res.startsWith("\"")) {
            res = "\"" + res;
        }

        if (!res.endsWith("\"")) {
            res = res + "\"";
        }

        return res;

    }
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();
  }
1069051
private int getQuoteToken( String content, int startOffset, int endOffset ) {
        String quoteDelimiter = content.substring(startOffset, startOffset + 1);
        String escapeString = getEscapeString(quoteDelimiter);
        int index;
        int endOfQuote = startOffset;
        // skip over the escape quotes in this quote
        index = content.indexOf(escapeString, endOfQuote + 1);
        while( (index > -1) && (index < endOffset) ) {
            endOfQuote = index + 1;
            index = content.indexOf(escapeString, endOfQuote);
        }
        // now find the matching delimiter
        index = content.indexOf(quoteDelimiter, endOfQuote + 1);
        if ((index < 0) || (index > endOffset))
            endOfQuote = endOffset;
        else
            endOfQuote = index;
        doc.setCharacterAttributes(startOffset, endOfQuote - startOffset + 1, quote, false);
        return endOfQuote + 1;
    }
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
463854
private void value(final String val,
                     final String quoteChar) throws IOException {
    if (val == null) {
      return;
    }

    String q = quoteChar;
    if (q == null) {
      q = "";
    }

    if ((val.indexOf('&') >= 0) ||
        (val.indexOf('<') >= 0)) {
      out("<![CDATA[");
      out(q);
      out(val);
      out(q);
      out("]]>");
    } else {
      out(q);
      out(val);
      out(q);
    }
  }
703928
def quote(self, identifier, errors="strict"):
        
        if identifier is None:
            return None

        encodable = identifier.encode("utf-8", errors).decode("utf-8")

        nul_index = encodable.find("\x00")

        if nul_index >= 0:
            error = UnicodeEncodeError(
                "NUL-terminated utf-8",
                encodable,
                nul_index,
                nul_index + 1,
                "NUL not allowed"
            )
            error_handler = codecs.lookup_error(errors)
            replacement, _ = error_handler(error)
            encodable = encodable.replace("\x00", replacement)

        return "\"" + encodable.replace("\"", "\"\"") + "\""
1275122
@Override
    public String getCharsetFromContentType(String type) {
        if (null != type) {
            int index = type.indexOf(';');
            if (-1 != index) {
                index = type.indexOf("charset=", (index + 1));
                if (-1 != index) {
                    String charset = type.substring(index + 8).trim();
                    int end = charset.length() - 1;
                    if (-1 == end) {
                        // empty value following charset=
                        return null;
                    }
                    if (end > 0 && '"' == charset.charAt(0) && '"' == charset.charAt(end)) {
                        // strip off quotes if both exist
                        charset = charset.substring(1, end);
                    }
                    return charset;
                }
            }
        }
        return null;
    }
662312
public static boolean needsDoubleQuotes(String s) {
    // this method should only be called for C*-provided identifiers,
    // so we expect it to be non-null and non-empty.
    assert s != null && !s.isEmpty();
    char c = s.charAt(0);
    if (!(c >= 97 && c <= 122)) // a-z
    return true;
    for (int i = 1; i < s.length(); i++) {
      c = s.charAt(i);
      if (!((c >= 48 && c <= 57) // 0-9
          || (c == 95) // _
          || (c >= 97 && c <= 122) // a-z
      )) {
        return true;
      }
    }
    return isReservedCqlKeyword(s);
  }
574339
public final void mQUOTED_VALUE() throws RecognitionException {
        try {
            int _type = QUOTED_VALUE;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // BELStatement.g:287:13: ( '\"' ( EscapeSequence | ~ ( '\\\\' | '\"' ) )* '\"' )
            // BELStatement.g:288:5: '\"' ( EscapeSequence | ~ ( '\\\\' | '\"' ) )* '\"'
            {
            match('\"'); 
            // BELStatement.g:288:9: ( EscapeSequence | ~ ( '\\\\' | '\"' ) )*
            loop3:
            do {
                int alt3=3;
                int LA3_0 = input.LA(1);

                if ( (LA3_0=='\\') ) {
                    alt3=1;
                }
                else if ( ((LA3_0>='\u0000' && LA3_0<='!')||(LA3_0>='#' && LA3_0<='[')||(LA3_0>=']' && LA3_0<='\uFFFF')) ) {
                    alt3=2;
                }


                switch (alt3) {
            	case 1 :
            	    // BELStatement.g:288:11: EscapeSequence
            	    {
            	    mEscapeSequence(); 

            	    }
            	    break;
            	case 2 :
            	    // BELStatement.g:288:28: ~ ( '\\\\' | '\"' )
            	    {
            	    if ( (input.LA(1)>='\u0000' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFF') ) {
            	        input.consume();

            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        recover(mse);
            	        throw mse;}


            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);

            match('\"'); 

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }