(line)
return line[:prefix_length]
Examine a line of text and extract what would be a comment prefix.

  The pattern we are looking for is ' *[^ ::punctuation::]*'.  This covers most
  programming languages in common use.  Fortran and Basic are obviously not
  supported. :-)

  Args:
    line: (str) a sample line
  Returns:
    (str) The comment prefix
Examine a line of text and extract what would be a comment prefix.
Examine a line of text and extract what would be a comment prefix .
def _ExtractCommentPrefix(line):
  """Examine a line of text and extract what would be a comment prefix.

  The pattern we are looking for is ' *[^ ::punctuation::]*'.  This covers most
  programming languages in common use.  Fortran and Basic are obviously not
  supported. :-)

  Args:
    line: (str) a sample line
  Returns:
    (str) The comment prefix
  """
  # look for spaces followed by a comment tag and break after that.
  got_tag = False
  prefix_length = 0
  # collect the prefix pattern
  for c in line:
    if c == ' ':
      if got_tag:
        break
      prefix_length += 1
    elif c in string.punctuation:
      got_tag = True
      prefix_length += 1
    else:
      break
  return line[:prefix_length]
def _ExtractCommentPrefix ( line ) : # look for spaces followed by a comment tag and break after that. got_tag = False prefix_length = 0 # collect the prefix pattern for c in line : if c == ' ' : if got_tag : break prefix_length += 1 elif c in string . punctuation : got_tag = True prefix_length += 1 else : break return line [ : prefix_length ]