Formats digits in text for reading in TTS
768740
public static String read_digits(EvaluationContext ctx, Object text) {
        String _text = Conversions.toString(text, ctx).trim();
        if (StringUtils.isEmpty(_text)) {
            return "";
        }

        // trim off the plus for phone numbers
        if (_text.startsWith("+")) {
            _text = _text.substring(1);
        }

        if (_text.length() == 9) { // SSN
            return StringUtils.join(_text.substring(0, 3).toCharArray(), ' ')
                    + " , " + StringUtils.join(_text.substring(3, 5).toCharArray(), ' ')
                    + " , " + StringUtils.join(_text.substring(5).toCharArray(), ' ');
        }
        else if (_text.length() % 3 == 0 && _text.length() > 3) { // triplets, most international phone numbers
            List<String> chunks = chunk(_text, 3);
            return StringUtils.join(StringUtils.join(chunks, ',').toCharArray(), ' ');
        }
        else if (_text.length() % 4 == 0) { // quads, credit cards
            List<String> chunks = chunk(_text, 4);
            return StringUtils.join(StringUtils.join(chunks, ',').toCharArray(), ' ');
        }
        else {
            // otherwise, just put a comma between each number
            return StringUtils.join(_text.toCharArray(), ',');
        }
    }
365052
def format_data(self, value):
        
        s = locale.format_string('%1.10e', (value,))
        return self.fix_minus(s)
1343538
function toFixedNumber (str, digits) {
  if (digits) {
    return stringToNumber(('' + stringToNumber(str)).replace(new RegExp('(\\d+.\\d{0,' + digits + '}).*'), '$1'))
  }
  return stringToInteger(str)
}
1228365
def FormatAsHexString(num, width=None, prefix="0x"):
  """"""
  # Strip "0x".
  hex_str = hex(num)[2:]
  # Strip "L" for long values.
  hex_str = hex_str.replace("L", "")
  if width:
    hex_str = hex_str.rjust(width, "0")
  return "%s%s" % (prefix, hex_str)
178351
def pad(text, bits=32):
    
    return text + (bits - len(text) % bits) * chr(bits - len(text) % bits)
13458
def format_result(line, line_num, txt):
    
    
    return '&nbsp;&nbsp;' + str(line_num) + ': ' + line.replace(txt, '<span style="background-color: #FFFF00">' + txt + '</span>')
144368
def format_character(char):
    """"""
    if \
        char in string.ascii_letters \
        or char in string.digits \
        or char in [
                '_', '.', ':', ';', ' ', '!', '?', '+', '-', '/', '=', '<',
                '>', '$', '(', ')', '@', '~', '`', '|', '#', '[', ']', '{',
                '}', '&', '*', '^', '%']:
        return char
    elif char in ['"', '\'', '\\']:
        return '\\{0}'.format(char)
    elif char == '\n':
        return '\\n'
    elif char == '\r':
        return '\\r'
    elif char == '\t':
        return '\\t'
    else:
        return '\\x{:02x}'.format(ord(char))
1276044
private static String hexFormat(int trgt) {
    String s = Integer.toHexString(trgt);
    int sz = s.length();

    if (sz == 8) {
      return s;
    }
    int fill = 8 - sz;
    StringBuilder buf = new StringBuilder();

    for (int i = 0; i < fill; ++i) {
      // add leading zeros
      buf.append('0');
    }
    buf.append(s);
    return buf.toString();
  }
666954
def read_digits(self, start: int, char: str) -> int:
        """"""
        source = self.source
        body = source.body
        position = start
        while "0" <= char <= "9":
            position += 1
            char = body[position : position + 1]
        if position == start:
            raise GraphQLSyntaxError(
                source,
                position,
                f"Invalid number, expected digit but got: {print_char(char)}.",
            )
        return position
1120402
def fmt_text(text):
    
    PRINTABLE_CHAR = set(
        list(range(ord(' '), ord('~') + 1)) + [ord('\r'), ord('\n')])
    newtext = ("\\x{:02X}".format(
        c) if c not in PRINTABLE_CHAR else chr(c) for c in text)
    textlines = "\r\n".join(l.strip('\r')
                            for l in "".join(newtext).split('\n'))
    return textlines
415204
def divine_format(text):
    """"""
    try:
        nbformat.reads(text, as_version=4)
        return 'ipynb'
    except nbformat.reader.NotJSONError:
        pass

    lines = text.splitlines()
    for comment in ['', '#'] + _COMMENT_CHARS:
        metadata, _, _, _ = header_to_metadata_and_cell(lines, comment)
        ext = metadata.get('jupytext', {}).get('text_representation', {}).get('extension')
        if ext:
            return ext[1:] + ':' + guess_format(text, ext)[0]

    # No metadata, but ``` on at least one line => markdown
    for line in lines:
        if line == '```':
            return 'md'

    return 'py:' + guess_format(text, '.py')[0]
1134369
private String digit(Data data) {
	String rtn = "";
	while (data.srcCode.isValidIndex()) {
	    if (!data.srcCode.isCurrentBetween('0', '9')) break;
	    rtn += data.srcCode.getCurrentLower();
	    data.srcCode.next();
	}
	return rtn;
    }
651494
private Number parseInt(String text,
                            int maxDigits,
                            ParsePosition pos,
                            boolean allowNegative,
                            NumberFormat fmt) {
        Number number;
        int oldPos = pos.getIndex();
        if (allowNegative) {
            number = fmt.parse(text, pos);
        } else {
            // Invalidate negative numbers
            if (fmt instanceof DecimalFormat) {
                String oldPrefix = ((DecimalFormat)fmt).getNegativePrefix();
                ((DecimalFormat)fmt).setNegativePrefix(SUPPRESS_NEGATIVE_PREFIX);
                number = fmt.parse(text, pos);
                ((DecimalFormat)fmt).setNegativePrefix(oldPrefix);
            } else {
                boolean dateNumberFormat = (fmt instanceof DateNumberFormat);
                if (dateNumberFormat) {
                    ((DateNumberFormat)fmt).setParsePositiveOnly(true);
                }
                number = fmt.parse(text, pos);
                if (dateNumberFormat) {
                    ((DateNumberFormat)fmt).setParsePositiveOnly(false);
                }
            }
        }
        if (maxDigits > 0) {
            // adjust the result to fit into
            // the maxDigits and move the position back
            int nDigits = pos.getIndex() - oldPos;
            if (nDigits > maxDigits) {
                double val = number.doubleValue();
                nDigits -= maxDigits;
                while (nDigits > 0) {
                    val /= 10;
                    nDigits--;
                }
                pos.setIndex(oldPos + maxDigits);
                number = Integer.valueOf((int)val);
            }
        }
        return number;
    }
344760
function _format (input, locale) {
  locale = locale || Locale.browserLocale() // eslint-disable-line no-param-reassign

  let result = input

  const { thousands, decimal } = Decimal.getDelimiters(locale)
  const isNegative = (result[0] === '-')

  // remove all characters except for digits and decimal delimiters
  result = result.replace(new RegExp(`[^\\d\\${decimal}]`, 'g'), '')

  // remove all decimal delimiters except for the last one if present
  result = result.replace(new RegExp(`[${decimal}](?=.*[${decimal}])`, 'g'), '')

  // remove the leading zeros using positive lookahead
  result = result.replace(new RegExp(`^[0${thousands}]+(?=\\d|0${decimal})`, ''), '')

  // add leading zero to decimal, if not present
  result = result.charAt(0) === decimal ? result.replace(/^/, '0') : result

  const parts = result.split(decimal)
  const thousandSections = []

  let curr = parts[0]
  while (curr.length > 0) {
    thousandSections.unshift(curr.substr(Math.max(0, curr.length - 3), 3))
    curr = curr.substr(0, curr.length - 3)
  }

  result = thousandSections.join(thousands)

  if (parts[1]) {
    result = `${result}${decimal}${parts[1]}`
  }

  if (isNegative && result) {
    result = `-${result}`
  }

  return result
}
292918
private final void zeroPaddingNumber(int value, int minDigits, int maxDigits, StringBuffer buffer)
    {
        // Optimization for 1, 2 and 4 digit numbers. This should
        // cover most cases of formatting date/time related items.
        // Note: This optimization code assumes that maxDigits is
        // either 2 or Integer.MAX_VALUE (maxIntCount in format()).
        try {
            if (zeroDigit == 0) {
                zeroDigit = ((DecimalFormat)numberFormat).getDecimalFormatSymbols().getZeroDigit();
            }
            if (value >= 0) {
                if (value < 100 && minDigits >= 1 && minDigits <= 2) {
                    if (value < 10) {
                        if (minDigits == 2) {
                            buffer.append(zeroDigit);
                        }
                        buffer.append((char)(zeroDigit + value));
                    } else {
                        buffer.append((char)(zeroDigit + value / 10));
                        buffer.append((char)(zeroDigit + value % 10));
                    }
                    return;
                } else if (value >= 1000 && value < 10000) {
                    if (minDigits == 4) {
                        buffer.append((char)(zeroDigit + value / 1000));
                        value %= 1000;
                        buffer.append((char)(zeroDigit + value / 100));
                        value %= 100;
                        buffer.append((char)(zeroDigit + value / 10));
                        buffer.append((char)(zeroDigit + value % 10));
                        return;
                    }
                    if (minDigits == 2 && maxDigits == 2) {
                        zeroPaddingNumber(value % 100, 2, 2, buffer);
                        return;
                    }
                }
            }
        } catch (Exception e) {
        }

        numberFormat.setMinimumIntegerDigits(minDigits);
        numberFormat.setMaximumIntegerDigits(maxDigits);
        numberFormat.format((long)value, buffer, DontCareFieldPosition.INSTANCE);
    }
671159
def read_digits(ctx, text):
    
    def chunk(value, chunk_size):
        return [value[i: i + chunk_size] for i in range(0, len(value), chunk_size)]

    text = conversions.to_string(text, ctx).strip()
    if not text:
        return ''

    # trim off the plus for phone numbers
    if text[0] == '+':
        text = text[1:]

    length = len(text)

    # ssn
    if length == 9:
        result = ' '.join(text[:3])
        result += ' , ' + ' '.join(text[3:5])
        result += ' , ' + ' '.join(text[5:])
        return result

    # triplets, most international phone numbers
    if length % 3 == 0 and length > 3:
        chunks = chunk(text, 3)
        return ' '.join(','.join(chunks))

    # quads, credit cards
    if length % 4 == 0:
        chunks = chunk(text, 4)
        return ' '.join(','.join(chunks))

    # otherwise, just put a comma between each number
    return ','.join(text)
73466
function(text) {
  if (text.indexOf('\t') == -1) {
    return text;
  } else {
    var lastStop = 0;
    return text.replace(reAllTab, function(match, offset) {
      var result = '    '.slice((offset - lastStop) % 4);
      lastStop = offset + 1;
      return result;
    });
  }
}