tools/metrics/common/etree_util.py
def GetTopLevelContent(file_content):
  """Returns a string of all the text in the xml file before the first tag."""
  handler = _FirstTagFinder()

  first_tag_line = 0
  first_tag_column = 0
  try:
    xml.sax.parseString(file_content.encode('utf-8'), handler)
  except _FirstTagFoundError:
    # This is the expected case, it means a tag was found in the doc.
    first_tag_line = handler.GetFirstTagLine()
    first_tag_column = handler.GetFirstTagColumn()
  if first_tag_line == 0 and first_tag_column == 0:
    return ''

  char = 0
  for _ in range(first_tag_line - 1):
    char = file_content.index('\n', char) + 1
  char += first_tag_column - 1

  # |char| is now pointing at the final character before the opening tag '<'.
  top_content = file_content[:char + 1].strip()
  if not top_content:
    return ''

  return top_content + '\n\n'
Returns a string of all the text in the xml file before the first tag.
Returns a string of all the text in the xml file before the first tag.
Returns a string of all the text in the xml file before the first tag .
def GetTopLevelContent(file_content):
  handler = _FirstTagFinder()
  first_tag_line = 0
  first_tag_column = 0
  try:
    xml.sax.parseString(file_content.encode('utf-8'), handler)
  except _FirstTagFoundError:
    first_tag_line = handler.GetFirstTagLine()
    first_tag_column = handler.GetFirstTagColumn()
  if first_tag_line == 0 and first_tag_column == 0:
    return ''
  char = 0
  for _ in range(first_tag_line - 1):
    char = file_content.index('\n', char) + 1
  char += first_tag_column - 1
  top_content = file_content[:char + 1].strip()
  if not top_content:
    return ''
  return top_content + '\n\n'
def GetTopLevelContent ( file_content ) : handler = _FirstTagFinder ( ) first_tag_line = 0 first_tag_column = 0 try : xml . sax . parseString ( file_content . encode ( 'utf-8' ) , handler ) except _FirstTagFoundError : first_tag_line = handler . GetFirstTagLine ( ) first_tag_column = handler . GetFirstTagColumn ( ) if first_tag_line == 0 and first_tag_column == 0 : return '' char = 0 for _ in range ( first_tag_line - 1 ) : char = file_content . index ( '\n' , char ) + 1 char += first_tag_column - 1 top_content = file_content [ : char + 1 ] . strip ( ) if not top_content : return '' return top_content + '\n\n'
Returns a string of all the text in the xml file before the first tag.
Returns a string of all the text in the xml file before the first tag .
"""Returns a string of all the text in the xml file before the first tag.""" # This is the expected case, it means a tag was found in the doc. # |char| is now pointing at the final character before the opening tag '<'.
file_content