tools/binary_size/libsupersize/bcanalyzer.py
def ParseTag(line):
  """Heuristically parses a single-line tag from bcanalyzer dump.

  Since input data are machine-generated, so we only need "good enough" parsing
  logic that favors simplicity. For example, '</FOO/>' is accepted.

  Args:
    line: Stripped line that may have a single-line tag with trailing text.

  Returns:
    (tag_type, tag, attrib_pos) if successful, else (None) * 3. Details:
    tag_type: One of {OPENING_TAG, CLOSING_TAG, SELF_CLOSING_TAG}.
    tag: The tag name.
    attrib_pos: Position in |line| to start parsing attributes.
  """
  # <TYPE_BLOCK_ID NumWords=103 BlockCodeSize=4>
  #     ==> (OPENING_TAG, 'TYPE_BLOCK_ID', 14).
  # <ARRAY abbrevid=9 op0=1 op1=7/> Trailing text!
  #     ==> (SELF_CLOSING_TAG, 'ARRAY', 6).
  # </TYPE_BLOCK_ID>
  #     ==> (CLOSING_TAG, 'TYPE_BLOCK_ID', 15).

  # Assumes |line| is stripped, i.e., so no indent and no trailing new line.
  if len(line) < 2 or line[0] != '<':
    return (None, None, None)
  tag_type, pos = (CLOSING_TAG, 2) if line[1] == '/' else (OPENING_TAG, 1)
  for i in range(pos, len(line)):
    if not line[i].isalnum() and line[i] != '_':
      if i == pos or not line[i] in ' >/':
        break
      end = line.find('>', i)
      if end < 0:
        break
      if line[end - 1] == '/':
        return (SELF_CLOSING_TAG, line[pos:i], i)
      return (tag_type, line[pos:i], i)
  return (None, None, None)
Heuristically parses a single-line tag from bcanalyzer dump.

  Since input data are machine-generated, so we only need "good enough" parsing
  logic that favors simplicity. For example, '</FOO/>' is accepted.

  Args:
    line: Stripped line that may have a single-line tag with trailing text.

  Returns:
    (tag_type, tag, attrib_pos) if successful, else (None) * 3. Details:
    tag_type: One of {OPENING_TAG, CLOSING_TAG, SELF_CLOSING_TAG}.
    tag: The tag name.
    attrib_pos: Position in |line| to start parsing attributes.
  
Heuristically parses a single-line tag from bcanalyzer dump.
Since input data are machine-generated, so we only need "good enough" parsing
logic that favors simplicity. For example, '' is accepted.
Heuristically parses a single - line tag from bcanalyzer dump . Since input data are machine - generated so we only need " good enough " parsing logic that favors simplicity . For example ' ' is accepted .
def ParseTag(line):
  if len(line) < 2 or line[0] != '<':
    return (None, None, None)
  tag_type, pos = (CLOSING_TAG, 2) if line[1] == '/' else (OPENING_TAG, 1)
  for i in range(pos, len(line)):
    if not line[i].isalnum() and line[i] != '_':
      if i == pos or not line[i] in ' >/':
        break
      end = line.find('>', i)
      if end < 0:
        break
      if line[end - 1] == '/':
        return (SELF_CLOSING_TAG, line[pos:i], i)
      return (tag_type, line[pos:i], i)
  return (None, None, None)
def ParseTag ( line ) : if len ( line ) < 2 or line [ 0 ] != '<' : return ( None , None , None ) tag_type , pos = ( CLOSING_TAG , 2 ) if line [ 1 ] == '/' else ( OPENING_TAG , 1 ) for i in range ( pos , len ( line ) ) : if not line [ i ] . isalnum ( ) and line [ i ] != '_' : if i == pos or not line [ i ] in ' >/' : break end = line . find ( '>' , i ) if end < 0 : break if line [ end - 1 ] == '/' : return ( SELF_CLOSING_TAG , line [ pos : i ] , i ) return ( tag_type , line [ pos : i ] , i ) return ( None , None , None )
Heuristically parses a single-line tag from bcanalyzer dump.
Heuristically parses a single - line tag from bcanalyzer dump .
"""Heuristically parses a single-line tag from bcanalyzer dump.

  Since input data are machine-generated, so we only need "good enough" parsing
  logic that favors simplicity. For example, '</FOO/>' is accepted.

  Args:
    line: Stripped line that may have a single-line tag with trailing text.

  Returns:
    (tag_type, tag, attrib_pos) if successful, else (None) * 3. Details:
    tag_type: One of {OPENING_TAG, CLOSING_TAG, SELF_CLOSING_TAG}.
    tag: The tag name.
    attrib_pos: Position in |line| to start parsing attributes.
  """ # <TYPE_BLOCK_ID NumWords=103 BlockCodeSize=4> #     ==> (OPENING_TAG, 'TYPE_BLOCK_ID', 14). # <ARRAY abbrevid=9 op0=1 op1=7/> Trailing text! #     ==> (SELF_CLOSING_TAG, 'ARRAY', 6). # </TYPE_BLOCK_ID> #     ==> (CLOSING_TAG, 'TYPE_BLOCK_ID', 15). # Assumes |line| is stripped, i.e., so no indent and no trailing new line.
(tag_type, tag, attrib_pos) if successful, else (None) * 3. Details:
tag_type: One of {OPENING_TAG, CLOSING_TAG, SELF_CLOSING_TAG}.
tag: The tag name.
attrib_pos: Position in |line| to start parsing attributes.
( tag_type tag attrib_pos ) if successful else ( None ) * 3 . Details : tag_type : One of { OPENING_TAG CLOSING_TAG SELF_CLOSING_TAG } . tag : The tag name . attrib_pos : Position in |line| to start parsing attributes .
line
Stripped line that may have a single-line tag with trailing text.
Stripped line that may have a single - line tag with trailing text .