Parse a font size keyword or numerical value
7120
private static Length  parseFontSize(String val)
   {
      try {
         Length  size = FontSizeKeywords.get(val);
         if (size == null)
            size = parseLength(val);
         return size;
      } catch (SVGParseException e) {
         return null;
      }
   }
1071528
function parseValueToStringOrNumber ( value ) {
	let resolvedValue, resolvedUnitValue;
	try {
		resolvedUnitValue = parseUnit(value);
		if ( unitTypes.indexOf(resolvedUnitValue.type) !== -1 ) {
			resolvedValue = new types.Number(resolvedUnitValue.value, resolvedUnitValue.unit);
		} else if ( resolvedUnitValue.type === 'percentage' ) {
			resolvedValue = new types.Number(resolvedUnitValue.value, '%');
		} else {
			resolvedValue = new types.String(resolvedUnitValue.value);
		}
	} catch ( e ) {
		resolvedValue = new types.String(value);
	}
	return resolvedValue;
}
23302
def parse_number(self, s):
        """"""
        start = 1 if s[0] in ["-","+"] else 0

        all_digits = lambda x: all(map(lambda c: c.isdigit(), x))
        ishex = lambda c: c.isdigit() or ord(c.lower()) in range(ord("a"), ord("f"))
        all_hex = lambda x: all(map(ishex, x))

        if all_digits(s[start:]):
            try:
                return (Tokenizer.INTEGER, int(s))
            except ValueError:
                raise ParseError("%d:%d: Invalid integer '%s'" % (self.lineno,
                    self.column, s))

        if s[start:].startswith("0x") and all_hex(s[start+2:]):
            try:
                return (Tokenizer.INTEGER, int(s, base=16))
            except ValueError:
                raise ParseError("%d:%d: Invalid hexadecimal integer '%s'" %
                        (self.lineno, self.column, s))

        if any(map(lambda c: c==".", s)) or any(map(lambda c: c=="e", s)):
            try:
                return (Tokenizer.FLOAT, float(s))
            except ValueError:
                raise ParseError("%d:%d: Invalid float '%s'" % (self.lineno,
                    self.column, s))

        raise ParseError("%d:%d: Invalid number '%s'" % (self.lineno,
            self.column, s))
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
885427
def parse(fmt, stri):
    """"""
    convdef = get_convert_dict(fmt)
    keyvals = regex_formatter.extract_values(fmt, stri)
    for key in convdef.keys():
        keyvals[key] = _convert(convdef[key], keyvals[key])

    return keyvals
610097
function parseFont(fontObject) {
    const pdfStreamInput = cpyCxtParser.parseNewObject(fontObject.getObjectID());
    const fontDictionary = pdfStreamInput.toJSObject();
    // See "Introduction to Font Data Structures" from PDF specification
    if (fontDictionary.Subtype.value === 'Type0') {
      // TODO: properly support composite fonts with multiple descendants
      const descendant = cpyCxtParser
        .parseNewObject(fontDictionary.DescendantFonts.toJSArray()[0].getObjectID())
        .toJSObject();
      if (descendant.Subtype.value == 'CIDFontType2') {
        const descriptor = cpyCxtParser
          .parseNewObject(descendant.FontDescriptor.getObjectID())
          .toJSObject();
        const id = descriptor.FontFile2.getObjectID();
        const buffer = readStream(cpyCxtParser.parseNewObject(id));
        const font = Font.create(buffer, { type: 'ttf', hinting: true });
        // PDF font name does not contain sub family on Windows 10 so a more robust key
        // is computed from the font metadata
        const name = descriptor.FontName.value + ' - ' + fontMetadataKey(font.data.name);
        if (context.pdfFonts[name]) {
          const f = context.pdfFonts[name].font;
          font.data.glyf.forEach((g, i) => {
            if (g.contours && g.contours.length > 0) {
              if (!f.data.glyf[i].contours || f.data.glyf[i].contours.length === 0) {
                f.data.glyf[i] = g;
              }
            } else if (g.compound) {
              if (typeof f.data.glyf[i].compound === 'undefined'
                  && f.data.glyf[i].contours.length === 0) {
                f.data.glyf[i] = g;
              }
            }
          });
          const replacement = {};
          replacement[id] = context.pdfFonts[name].id;
          cpyCxt.replaceSourceObjects(replacement);
        } else {
          const xObjectId = printer.getObjectsContext().allocateNewObjectID();
          context.pdfFonts[name] = { id: xObjectId, font: font };
          const replacement = {};
          replacement[id] = xObjectId;
          cpyCxt.replaceSourceObjects(replacement);
        }
      }
    }
  }
676167
def font_parse_string(font):
    

    if font is None:
        return ''

    if type(font) is str:
        _font = font.split(' ')
    else:
        _font = font
    family = _font[0]
    point_size = int(_font[1])

    style = _font[2:] if len(_font) > 1 else None

    # underline =  'underline' in _font[2:]
    # bold =  'bold' in _font

    return family, point_size, style
181528
def parse_float_literal(ast, _variables=None):
    """"""
    if isinstance(ast, (FloatValueNode, IntValueNode)):
        return float(ast.value)
    return INVALID
1297546
def _convert_size(self, size_str):
        """"""
        suffix = size_str[-1]
        if suffix == 'K':
            multiplier = 1.0 / (1024.0 * 1024.0)
        elif suffix == 'M':
            multiplier = 1.0 / 1024.0
        elif suffix == 'T':
            multiplier = 1024.0
        else:
            multiplier = 1

        try:
            val = float(size_str.split(' ')[0])
            return val * multiplier
        except ValueError:
            return 0.0
956967
def num(string):
    """"""
    if not isinstance(string, type('')):
        raise ValueError(type(''))
    try:
        string = re.sub('[^a-zA-Z0-9\.\-]', '', string)
        number = re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", string)
        return float(number[0])
    except Exception as e:
        logger = logging.getLogger('tradingAPI.utils.num')
        logger.debug("number not found in %s" % string)
        logger.debug(e)
        return None
1337942
def ParseFromString(self, text, message):
    """"""
    if not isinstance(text, str):
      text = text.decode('utf-8')
    return self.ParseLines(text.split('\n'), message)
1272938
function parse_FontFlags(data) {
	var d = data.read_shift(1);
	data.l++;
	var out = {
		/* fBold: d & 0x01 */
		fItalic: d & 0x02,
		/* fUnderline: d & 0x04 */
		fStrikeout: d & 0x08,
		fOutline: d & 0x10,
		fShadow: d & 0x20,
		fCondense: d & 0x40,
		fExtend: d & 0x80
	};
	return out;
}
552316
def OnTextSize(self, event):
        """"""

        try:
            size = int(event.GetString())

        except Exception:
            size = get_default_font().GetPointSize()

        post_command_event(self, self.FontSizeMsg, size=size)
984977
def parse_modeString(s):
        
        refresh, width, height = None, None, None
        if '@' in s:
                s, refresh = s.split('@', 1)
                refresh = int(refresh)
        if 'x' in s:
                width, height = [int(x) if x.strip() else None
                                        for x in s.split('x', 1)]
        elif s.strip():
                width = int(s)
        else:
                width = None
        return (width, height, refresh)
472219
def type_converter(text):
    
    if text.isdigit():
        return int(text), int

    try:
        return float(text), float
    except ValueError:
        return text, STRING_TYPE
940608
def _parse_da(self):
        
        if not self._text_da:
            return
        font = "Helv"
        fsize = 0
        col = (0, 0, 0)
        dat = self._text_da.split()              # split on any whitespace
        for i, item in enumerate(dat):
            if item == "Tf":
                font = dat[i - 2][1:]
                fsize = float(dat[i - 1])
                dat[i] = dat[i-1] = dat[i-2] = ""
                continue
            if item == "g":            # unicolor text
                col = [(float(dat[i - 1]))]
                dat[i] = dat[i-1] = ""
                continue
            if item == "rg":           # RGB colored text
                col = [float(f) for f in dat[i - 3:i]]
                dat[i] = dat[i-1] = dat[i-2] = dat[i-3] = ""
                continue
        self.text_font     = font
        self.text_fontsize = fsize
        self.text_color    = col
        self._text_da = " ".join([c for c in dat if c != ""])
        return
787178
def get_output_str(item, detect_numerics, precision, sign_value):
    """"""
    if detect_numerics:
        item = _convert_to_numeric(item)
    if isinstance(item, float):
        item = round(item, precision)
    try:
        item = '{:{sign}}'.format(item, sign=sign_value)
    except (ValueError, TypeError):
        pass
    return to_unicode(item)