Convert spelled out numbers in a given text to digits.
558232
def extract_spellout_values(text):
    """"""
    values = []
    for item in r.REG_TXT.finditer(text):
        surface, span = clean_surface(item.group(0), item.span())
        if not surface or surface.lower() in r.SCALES:
            continue
        curr = result = 0.0
        for word in surface.split():
            try:
                scale, increment = 1, float(word.lower())
            except ValueError:
                scale, increment = r.NUMWORDS[word.lower()]
            curr = curr * scale + increment
            if scale > 100:
                result += curr
                curr = 0.0
        values.append({'old_surface': surface,
                       'old_span': span,
                       'new_surface': unicode(result + curr)})

    for item in re.finditer(r'\d+(,\d{3})+', text):
        values.append({'old_surface': item.group(0),
                       'old_span': item.span(),
                       'new_surface': unicode(item.group(0).replace(',', ''))})

    return sorted(values, key=lambda x: x['old_span'][0])
178351
def pad(text, bits=32):
    
    return text + (bits - len(text) % bits) * chr(bits - len(text) % bits)
154817
def string_to_int( s ):
  """"""
  result = 0
  for c in s:
    if not isinstance(c, int): c = ord( c )
    result = 256 * result + c
  return result
286945
def get_digits_from_string(cyphertext, length=4):
    
    digits = ''
   
    """
    The algorigthm is used for PVV and CVV calculation.

    1. The cyphertext is scanned from left to right. Decimal digits are
    selected during the scan until the needed number of decimal digits is found. 
    Each selected digit is placed from left to right according to the order
    of selection. If needed number of decimal digits is found (four in case of PVV, 
    three in case of CVV), those digits are the PVV or CVV.
    """
    for c in cyphertext:
        if len(digits) >= length:
            break
        try:
            int(c)
            digits += c
        except ValueError:
            continue
    
    """
    2. If, at the end of the first scan, less than four decimal digits
    have been selected, a second scan is performed from left to right.
    During the second scan, all decimal digits are skipped and only nondecimal
    digits can be processed. Nondecimal digits are converted to decimal
    digits by subtracting 10. The process proceeds until four digits of
    PVV are found.
    """
    if len(digits) < length:
        for c in cyphertext:
            if len(digits) >= length:
                break
    
            if (int(c, 16) - 10) >= 0:
                digits += str(int(c, 16) - 10)
    
    return digits
236329
def parse_numeric(self):
        """"""
        word = ''
        frac = False

        if self.char == '-':
            word += self.char
            self.update_chars()

        while self.char.isdigit() or (self.char == '.' and not frac):
            # Only allow one decimal point
            if self.char == '.':
                frac = True
            word += self.char
            self.update_chars()

        # Check for float exponent
        if self.char in 'eEdD':
            word += self.char
            self.update_chars()

        if self.char in '+-':
            word += self.char
            self.update_chars()
        while self.char.isdigit():
            word += self.char
            self.update_chars()

        return word
918786
def extract_number(text):
    
    result = list()
    chunk = list()
    valid_char = set(".1234567890")
    for char in text:
        if char in valid_char:
            chunk.append(char)
        else:
            result.append("".join(chunk))
            chunk = list()
    result.append("".join(chunk))

    result_new = list()
    for number in result:
        if "." in number:
            try:
                result_new.append(float(number))
            except:
                pass
        else:
            try:
                result_new.append(int(number))
            except:
                pass

    return result_new
1108685
@Unstable
    public static String toAlphaNumeric(String text)
    {
        if (isEmpty(text)) {
            return text;
        }

        return stripAccents(text).replaceAll("[^a-zA-Z0-9]", "");
    }
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)
548770
def _to_number(cls, string):
        """"""
        try:
            if float(string) - int(string) == 0:
                return int(string)
            return float(string)
        except ValueError:
            try:
                return float(string)
            except ValueError:
                return string
191321
def _hash(number, alphabet):
    """"""
    hashed = ''
    len_alphabet = len(alphabet)
    while True:
        hashed = alphabet[number % len_alphabet] + hashed
        number //= len_alphabet
        if not number:
            return hashed
1028758
def num_to_thaiword(number: int) -> str:
    
    ret = ""

    if number is None:
        pass
    elif number == 0:
        ret = "ศูนย์"
    else:
        _POS_CALL = ["แสน", "หมื่น", "พัน", "ร้อย", "สิบ", ""]
        _NUM_CALL = [
            "",
            "หนึ่ง",
            "สอง",
            "สาม",
            "สี่",
            "ห้า",
            "หก",
            "เจ็ด",
            "แปด",
            "เก้า",
        ]

        if number > 1000000:
            ret += num_to_thaiword(int(number / 1000000)) + "ล้าน"
            number = int(math.fmod(number, 1000000))
        divider = 100000

        pos = 0
        while number > 0:
            d = int(number / divider)

            if (divider == 10) and (d == 2):
                ret += "ยี่"
            elif (divider == 10) and (d == 1):
                ret += ""
            elif (divider == 1) and (d == 1) and (ret != ""):
                ret += "เอ็ด"
            else:
                ret += _NUM_CALL[d]

            if d:
                ret += _POS_CALL[pos]
            else:
                ret += ""

            number = number % divider
            divider = divider / 10
            pos += 1

    return ret
306280
def word(ctx, text, number, by_spaces=False):
    
    return word_slice(ctx, text, number, conversions.to_integer(number, ctx) + 1, by_spaces)
1088625
def number_to_dp(number: Optional[float],
                 dp: int,
                 default: Optional[str] = "",
                 en_dash_for_minus: bool = True) -> str:
    
    if number is None:
        return default
    if number == float("inf"):
        return u"∞"
    if number == float("-inf"):
        s = u"-∞"
    else:
        s = u"{:.{precision}f}".format(number, precision=dp)
    if en_dash_for_minus:
        s = s.replace("-", u"–")  # hyphen becomes en dash for minus sign
    return s
642692
def _filter(self, text):
        """"""

        self.markdown.reset()
        return self.markdown.convert(text)
532736
def remove_numbers(text_string):
    '''
    
    '''
    if text_string is None or text_string == "":
        return ""
    elif isinstance(text_string, str):
        return " ".join(re.sub(r'\b[\d.\/,]+', "", text_string).split())
    else:
        raise InputError("string not passed as argument")
851199
def from_text(text):
        
        number = int(filter(unicode.isdigit, unicode(text)))
        return Phone(number=number)
472219
def type_converter(text):
    
    if text.isdigit():
        return int(text), int

    try:
        return float(text), float
    except ValueError:
        return text, STRING_TYPE