For <character-string> see: http://tools.ietf.org/html/rfc1035#section-3.3 For TXT: http://tools.ietf.org/html/rfc1035#section-3.3.14
345969
function writeTxt(buff, val) {
  //TODO XXX FIXME -- split on max char string and loop
  assertUndefined(val.data, 'TXT record requires "data"');
  for (var i=0,len=val.data.length; i<len; i++) {
    var dataLen = Buffer.byteLength(val.data[i], 'utf8');
    buff.writeUInt8(dataLen);
    buff.write(val.data[i], dataLen, 'utf8');
  }
  return WRITE_RESOURCE_DONE;
}
81816
private String encodeString(String str) {
        m_buffer.setLength(0);
        char ch;
        int inx = 0;
        while (inx < str.length()) {
            ch = str.charAt(inx++);
            switch (ch) {
            case '"':  m_buffer.append("\\\""); break;
            case '\\': m_buffer.append("\\\\"); break;
            case '\b':  m_buffer.append("\\b"); break;
            case '\f':  m_buffer.append("\\f"); break;
            case '\n':  m_buffer.append("\\n"); break;
            case '\r':  m_buffer.append("\\r"); break;
            case '\t':  m_buffer.append("\\t"); break;
            default:
                // All other chars are allowed as-is, despite JSON spec.
                m_buffer.append(ch);
            }
        }
        return m_buffer.toString();
    }
1140126
function strToFlags(str) {
	if (!str) {
		return;
	}

	var buff = new Buffer([0, 0, 0, 0]);
	buff.write(str, 0, 4, 'ascii');
	return buff.readUInt32BE(0);
}
508137
function uriEncodeString( text ){
    return encodeURIComponent(text).replace( /[\!\*\'\(\)]/g, function( chr ){
        chr = chr.charCodeAt(0).toString(16);
        while( chr.length < 2 ){
            chr = '0'+hex;
        }
        return '%'+chr;
    } )
}
338434
function _getPadding (source, char, len) {
    if (!isNil(source) && type(source) !== "String") {
        source = String(source);
    }

    return _repeat(String(char)[0] || "", Math.ceil(len - source.length));
}
976881
function(string) {
            // If the string contains no control characters, no quote characters, and no
            // backslash characters, then we can simply slap some quotes around it.
            // Otherwise we must also replace the offending characters with safe
            // sequences.    
            var m = {
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"' : '\\"',
                '\\': '\\\\'
            };
            if(/["\\\x00-\x1f]/.test(string)) {
                return '"' + string.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                    var c = m[b];
                    if(c) {
                        return c;
                    }
                    c = b.charCodeAt();
                    return '\\u00' +
                        Math.floor(c / 16).toString(16) +
                        (c % 16).toString(16);
                }) + '"';
            }
            return '"' + string + '"';
        }
1052255
private char rdCh()
	{
		char c = super.readCh();

		if (c == '\n')
		{
			linecount++;
			charpos = 0;
		} else if (c == '\t')
		{
			charpos += Properties.parser_tabstop - charpos
					% Properties.parser_tabstop;
		} else if (c != (char) -1)
		{
			charpos++;
		}

		ch = c;
		charsread++;
		offset = getCurrentRawReadOffset();

		// if(ch == '\r')
		// {
		// ch = rdCh();
		// }else
		// {
		// ch = c;
		// }
		return ch;
	}
792276
function(value)
	{
		switch (value.charAt(1)) {
			case '0':
				return String.fromCharCode(0);
			case 'a':
				return String.fromCharCode(7);
			case 'b':
				return String.fromCharCode(8);
			case 't':
				return "\t";
			case "\t":
				return "\t";
			case 'n':
				return "\n";
			case 'v':
				return String.fromCharCode(11);
			case 'f':
				return String.fromCharCode(12);
			case 'r':
				return String.fromCharCode(13);
			case 'e':
				return "\x1b";
			case ' ':
				return ' ';
			case '"':
				return '"';
			case '/':
				return '/';
			case '\\':
				return '\\';
			case 'N':
				// U+0085 NEXT LINE
				return "\x00\x85";
			case '_':
				// U+00A0 NO-BREAK SPACE
				return "\x00\xA0";
			case 'L':
				// U+2028 LINE SEPARATOR
				return "\x20\x28";
			case 'P':
				// U+2029 PARAGRAPH SEPARATOR
				return "\x20\x29";
			case 'x':
				return this.pack('n', new YamlInline().hexdec(value.substr(2, 2)));
			case 'u':
				return this.pack('n', new YamlInline().hexdec(value.substr(2, 4)));
			case 'U':
				return this.pack('N', new YamlInline().hexdec(value.substr(2, 8)));
		}
	}
1016779
function crc32(str: string): number {
  /* jslint bitwise: true */
  var crc = -1;
  for (var i = 0, len = str.length; i < len; i++) {
    crc = (crc >>> 8) ^ table[(crc ^ str.charCodeAt(i)) & 0xFF];
  }
  return ~crc;
}
268508
private String nextAT() {
    // skip preceding space chars, they can present after
    // comma or semicolon (compatibility with RFC 1779)
    for (; pos < length && chars[pos] == ' '; pos++) {
    }
    if (pos == length) {
      return null; // reached the end of DN
    }

    // mark the beginning of attribute type
    beg = pos;

    // attribute type chars
    pos++;
    for (; pos < length && chars[pos] != '=' && chars[pos] != ' '; pos++) {
      // we don't follow exact BNF syntax here:
      // accept any char except space and '='
    }
    if (pos >= length) {
      throw new IllegalStateException("Unexpected end of DN: " + dn);
    }

    // mark the end of attribute type
    end = pos;

    // skip trailing space chars between attribute type and '='
    // (compatibility with RFC 1779)
    if (chars[pos] == ' ') {
      for (; pos < length && chars[pos] != '=' && chars[pos] == ' '; pos++) {
      }

      if (chars[pos] != '=' || pos == length) {
        throw new IllegalStateException("Unexpected end of DN: " + dn);
      }
    }

    pos++; //skip '=' char

    // skip space chars between '=' and attribute value
    // (compatibility with RFC 1779)
    for (; pos < length && chars[pos] == ' '; pos++) {
    }

    // in case of oid attribute type skip its prefix: "oid." or "OID."
    // (compatibility with RFC 1779)
    if ((end - beg > 4) && (chars[beg + 3] == '.')
        && (chars[beg] == 'O' || chars[beg] == 'o')
        && (chars[beg + 1] == 'I' || chars[beg + 1] == 'i')
        && (chars[beg + 2] == 'D' || chars[beg + 2] == 'd')) {
      beg += 4;
    }

    return new String(chars, beg, end - beg);
  }
991777
function ( text ){
		   var out = [text],
			   chars = ['-','+','z','Z'],
			   i = chars.length;

			while (i--) {
			  if(text.indexOf(chars[i]) > -1){
				  out[0] = text.slice( 0, text.indexOf(chars[i]) );
				  out.push( text.slice( text.indexOf(chars[i]) ) );
				  break;
			   }
			}
		   return out;
		}
1353341
function txt(text) {
        var name = '"' + text.replace(/"/gm, '\\"') + '"';
        return new Pattern(name, function (str, pos) {
            if (str.substr(pos, text.length) == text)
                return { res: text, end: pos + text.length };
        });
    }
514525
private char readEscapedChar() throws IOException {
    int ch = getChar();
    switch (ch) {
      case '"' : return '"';
      case '\'' : return '\'';
      case '\\' : return '\\';
      case '/' : return '/';
      case 'n' : return '\n';
      case 'r' : return '\r';
      case 't' : return '\t';
      case 'f' : return '\f';
      case 'b' : return '\b';
      case 'u' :
        return (char)(
               (hexval(getChar()) << 12)
             | (hexval(getChar()) << 8)
             | (hexval(getChar()) << 4)
             | (hexval(getChar())));
    }
    if ( (flags & ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER) != 0 && ch != EOF) {
      return (char)ch;
    }
    throw err("Invalid character escape");
  }
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));
    }
  }
468118
private static void htmlEncode(final CharSequence unsafeStr, final boolean turnNewlineIntoBreak,
            final StringBuilder buf) {
        for (int i = 0, n = unsafeStr.length(); i < n; i++) {
            final char c = unsafeStr.charAt(i);
            switch (c) {
            case '&':
                buf.append("&amp;");
                break;
            case '<':
                buf.append("&lt;");
                break;
            case '>':
                buf.append("&gt;");
                break;
            case '"':
                buf.append("&quot;");
                break;
            case '\'':
                buf.append("&#x27;"); // See http://goo.gl/FzoP6m
                break;
            case '\\':
                buf.append("&lsol;");
                break;
            case '/':
                buf.append("&#x2F;"); // '/' can be a dangerous char if attr values are not quoted
                break;
            // Encode a few common characters that like to get screwed up in some charset/browser variants
            case '—':
                buf.append("&mdash;");
                break;
            case '–':
                buf.append("&ndash;");
                break;
            case '“':
                buf.append("&ldquo;");
                break;
            case '”':
                buf.append("&rdquo;");
                break;
            case '‘':
                buf.append("&lsquo;");
                break;
            case '’':
                buf.append("&rsquo;");
                break;
            case '«':
                buf.append("&laquo;");
                break;
            case '»':
                buf.append("&raquo;");
                break;
            case '£':
                buf.append("&pound;");
                break;
            case '©':
                buf.append("&copy;");
                break;
            case '®':
                buf.append("&reg;");
                break;
            case (char) 0x00A0:
                buf.append("&nbsp;");
                break;
            case '\n':
                if (turnNewlineIntoBreak) {
                    buf.append("<br>");
                } else {
                    buf.append(' '); // Newlines function as whitespace in HTML text
                }
                break;
            default:
                if (c <= 32 || isUnicodeWhitespace(c)) {
                    buf.append(' ');
                } else {
                    buf.append(c);
                }
                break;
            }
        }
    }
120945
def CharacterData(self,data):
		''
		## HACK: to preserve the newlines
		#if string.strip(data):
		data = data.encode("utf-8")
		element = self.nodeStack[-1]
		element.cdata += data
		return
140984
public static String HTMLEntityEncode(String input) {
        String next = scriptPattern.matcher(input).replaceAll("&#x73;cript");

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < next.length(); ++i) {
            char ch = next.charAt(i);

            if (ch == '<') {
                sb.append("&lt;");
            } else if (ch == '>') {
                sb.append("&gt;");
            } else {
                sb.append(ch);
            }
        }

        return sb.toString();
    }