import re


def ExtractTagFromLine(file_type, line):
  """Extract a tag from a line of HTML, C++, JS or JSON."""
  if file_type == "html":
    # HTML-style (tags)
    m = re.search('i18n-content=[\'"]([^\'"]*)[\'"]', line)
    if m: return m.group(1)
    # HTML-style (titles)
    m = re.search('i18n-title=[\'"]([^\'"]*)[\'"]', line)
    if m: return m.group(1)
    # HTML-style (substitutions)
    m = re.search('i18n-value-name-[1-9]=[\'"]([^\'"]*)[\'"]', line)
    if m: return m.group(1)
  elif file_type == 'js':
    # Javascript style
    m = re.search('/\*i18n-content\*/[\'"]([^\`"]*)[\'"]', line)
    if m: return m.group(1)
  elif file_type == 'cc' or file_type == 'mm':
    # C++ style
    m = re.search('IDS_([A-Z0-9_]*)', line)
    if m: return m.group(1)
    m = re.search('/\*i18n-content\*/["]([^\`"]*)["]', line)
    if m: return m.group(1)
  elif file_type == 'json.jinja2':
    # Manifest style
    m = re.search('__MSG_(.*)__', line)
    if m: return m.group(1)
  elif file_type == 'jinja2':
    # Jinja2 template file
    m = re.search('\{\%\s+trans\s+\%\}([A-Z0-9_]+)\{\%\s+endtrans\s+\%\}', line)
    if m: return m.group(1)
  return None