characters back to their quoted form.
488112
protected static String stringOf(Value val)
	{
		StringBuilder s = new StringBuilder();
		val = val.deref();

		if (val instanceof SeqValue)
		{
			SeqValue sv = (SeqValue) val;

			for (Value v : sv.values)
			{
				v = v.deref();

				if (v instanceof CharacterValue)
				{
					CharacterValue cv = (CharacterValue) v;
					s.append(cv.unicode);
				} else
				{
					s.append("?");
				}
			}

			return s.toString();
		} else
		{
			return val.toString();
		}
	}
784344
def escape(s):
    """"""
    if not isinstance(s, bytes):
        s = s.encode('utf-8')
    return quote(s, safe='~')
1187214
private void readQuote( char quote, StringBuilder builder ) {
        builder.append( quote );
        boolean isBackslash = false;
        for( ;; ) {
            char ch = read();
            builder.append( ch );
            if( ch == quote && !isBackslash ) {
                return;
            }
            isBackslash = ch == '\\';
        }
    }
1135235
private void writeQuotedAndEscaped(CharSequence string) {
        if (string != null && string.length() != 0) {
            int len = string.length();
            writer.write('\"');

            for (int i = 0; i < len; ++i) {
                char cp = string.charAt(i);
                if ((cp < 0x7f &&
                     cp >= 0x20 &&
                     cp != '\"' &&
                     cp != '\\') ||
                    (cp > 0x7f &&
                     isConsolePrintable(cp) &&
                     !isSurrogate(cp))) {
                    // quick bypass for direct printable chars.
                    writer.write(cp);
                } else {
                    switch (cp) {
                        case '\b':
                            writer.write("\\b");
                            break;
                        case '\t':
                            writer.write("\\t");
                            break;
                        case '\n':
                            writer.write("\\n");
                            break;
                        case '\f':
                            writer.write("\\f");
                            break;
                        case '\r':
                            writer.write("\\r");
                            break;
                        case '\"':
                        case '\\':
                            writer.write('\\');
                            writer.write(cp);
                            break;
                        default:
                            if (isSurrogate(cp) && (i + 1) < len) {
                                char c2 = string.charAt(i + 1);
                                writer.format("\\u%04x", (int) cp);
                                writer.format("\\u%04x", (int) c2);
                                ++i;
                            } else {
                                writer.format("\\u%04x", (int) cp);
                            }
                            break;
                    }
                }
            }

            writer.write('\"');
        } else {
            writer.write("\"\"");
        }
    }
1142079
private String quoteFormatCharacters(String literal)
   {
      StringBuilder sb = new StringBuilder();
      int length = literal.length();
      char c;

      for (int loop = 0; loop < length; loop++)
      {
         c = literal.charAt(loop);
         switch (c)
         {
            case '0':
            case '#':
            case '.':
            case '-':
            case ',':
            case 'E':
            case ';':
            case '%':
            {
               sb.append("'");
               sb.append(c);
               sb.append("'");
               break;
            }

            default:
            {
               sb.append(c);
               break;
            }
         }
      }

      return (sb.toString());
   }
67045
def tmpl_replchars(text, replace, chars):
        
        for char in chars:
            text = text.replace(char, replace)
        return text
465637
def restore(s, t):
    
    t = (c for c in t)
    return ''.join(next(t) if not is_blacksquare(c) else c for c in s)
645254
def characters(self, characters):
    
    self._pad()
    self._writer.characters(str(characters))
    self._newline()
356005
def replaced(self, contents):
        
        line_num = len(contents.strip(' ').splitlines())
        replace_marks = self.RE_REPLACE_MARK.findall(contents.strip())
        if len(replace_marks) == line_num:
            return False
        return True
1085578
def unescape(s, quote=False):
    
    s = s.replace('&lt;', '<')
    s = s.replace('&gt;', '>')
    if quote:
        s = s.replace('&quot;', '"')
    s = s.replace('&amp;', '&')
    return s
1353100
def replace_emphasis(self, s, index = 0):
        """"""
        e = self.emphasized[index]
        self.body[e[0]:e[1]] = [s]
        del self.emphasized[index]
267750
def previous(self):
        
        self.params['offset'] = str(int(self.params['offset']) - int(self.params['limit']))
        return self.marvel.get_characters(self.marvel, (), **self.params)
520612
def putch(self, char):
        
        if char == '\r':
            self.carriage_return()

        elif char == '\n':
            self.newline()

        elif char == '\b':
            self.backspace()

        elif char == '\t':
            self.tab()

        else:
            w = self.font.getsize(char)[0]
            if self._cx + w >= self._device.width:
                self.newline()

            self.erase()
            self._canvas.text((self._cx, self._cy),
                              text=char,
                              font=self.font,
                              fill=self._fgcolor)

            self._cx += w
            if self.animate:
                self.flush()
597219
def reindent(tokens, indent=' '):
    
    old_levels = []
    old_level = 0
    new_level = 0
    for typ, tok, (start_row, start_col), (end_row, end_col), line in tokens:
        if typ == tokenize.INDENT:
            old_levels.append(old_level)
            old_level = len(tok)
            new_level += 1
            tok = indent * new_level
        elif typ == tokenize.DEDENT:
            old_level = old_levels.pop()
            new_level -= 1
        start_col = max(0, start_col - old_level + new_level)
        if start_row == end_row:
            end_col = start_col + len(tok)
        yield typ, tok, (start_row, start_col), (end_row, end_col), line
51880
def characters(self, numberOfCharacters):
        """"""
        return self.code[self.index:self.index + numberOfCharacters]
736705
def replace(self, re_text, replace_str, text):
        
        return re.sub(re_text, replace_str, text)
945492
def _reindent(s, indent, reformat=True):
    
    s = textwrap.dedent(s)
    s = s.split('\n')
    s = [x.rstrip() for x in s]
    while s and (not s[0]):
        s = s[1:]
    while s and (not s[-1]):
        s = s[:-1]
    if reformat:
        s = '\n'.join(s)
        s = textwrap.wrap(s, initial_indent=indent, subsequent_indent=indent)
    else:
        s = [indent + x for x in s]
    return '\n'.join(s) + '\n'