wpiformat/wpiformat/licenseupdate.py
def __try_string_search(self, lines, last_year, license_template):
        """Try finding license with string search.

        Keyword arguments:
        lines -- lines of file
        last_year -- last year in copyright range
        license_template -- license_template string

        Returns:
        Tuple of whether license was found, first year in copyright range, and
        file contents after license.
        """
        linesep = super().get_linesep(lines)

        # Strip newlines at top of file
        stripped_lines = lines.lstrip().split(linesep)

        # If a comment at the beginning of the file is considered a license, it
        # is replaced with an updated license. Otherwise, a license header is
        # inserted before it.
        first_comment_is_license = False
        license_end = 0

        # Regex for tokenizing on comment boundaries
        token_regex = regex.compile(r"/\*|\*/|^//")

        in_multiline_comment = False
        for line in stripped_lines:
            # If part of comment contains "Copyright (c)", comment is
            # license.
            if "Copyright (c)" in line:
                first_comment_is_license = True

            line_has_comment = False
            for match in token_regex.finditer(line):
                # If any comment token was matched, the line has a comment
                line_has_comment = True

                token = match.group()

                if token == "/*":
                    in_multiline_comment = True
                elif token == "*/":
                    in_multiline_comment = False
            if not in_multiline_comment and not line_has_comment:
                break
            else:
                license_end += 1

        first_year = last_year

        # If comment at beginning of file is non-empty license, update it
        if first_comment_is_license and license_end > 0:
            license_part = linesep.join(stripped_lines[0:license_end])
            appendix_part = \
                linesep + linesep.join(stripped_lines[license_end:]).lstrip()

            year_regex = regex.compile(r"Copyright \(c\)(?>.*?\s(20..))")
            for line in license_part.split(linesep):
                match = year_regex.search(line)
                # If license contains copyright pattern, extract the first year
                if match:
                    first_year = match.group(1)
                    break

            return True, first_year, appendix_part
        else:
            return False, first_year, linesep + lines.lstrip()
Try finding license with string search.

        Keyword arguments:
        lines -- lines of file
        last_year -- last year in copyright range
        license_template -- license_template string

        Returns:
        Tuple of whether license was found, first year in copyright range, and
        file contents after license.
        
Try finding license with string search.
Try finding license with string search .
def __try_string_search(self, lines, last_year, license_template):
        linesep = super().get_linesep(lines)
        stripped_lines = lines.lstrip().split(linesep)
        first_comment_is_license = False
        license_end = 0
        token_regex = regex.compile(r"/\*|\*/|^//")
        in_multiline_comment = False
        for line in stripped_lines:
            if "Copyright (c)" in line:
                first_comment_is_license = True
            line_has_comment = False
            for match in token_regex.finditer(line):
                line_has_comment = True
                token = match.group()
                if token == "/*":
                    in_multiline_comment = True
                elif token == "*/":
                    in_multiline_comment = False
            if not in_multiline_comment and not line_has_comment:
                break
            else:
                license_end += 1
        first_year = last_year
        if first_comment_is_license and license_end > 0:
            license_part = linesep.join(stripped_lines[0:license_end])
            appendix_part = \
                linesep + linesep.join(stripped_lines[license_end:]).lstrip()
            year_regex = regex.compile(r"Copyright \(c\)(?>.*?\s(20..))")
            for line in license_part.split(linesep):
                match = year_regex.search(line)
                if match:
                    first_year = match.group(1)
                    break
            return True, first_year, appendix_part
        else:
            return False, first_year, linesep + lines.lstrip()
def __try_string_search ( self , lines , last_year , license_template ) : linesep = super ( ) . get_linesep ( lines ) stripped_lines = lines . lstrip ( ) . split ( linesep ) first_comment_is_license = False license_end = 0 token_regex = regex . compile ( r"/\*|\*/|^//" ) in_multiline_comment = False for line in stripped_lines : if "Copyright (c)" in line : first_comment_is_license = True line_has_comment = False for match in token_regex . finditer ( line ) : line_has_comment = True token = match . group ( ) if token == "/*" : in_multiline_comment = True elif token == "*/" : in_multiline_comment = False if not in_multiline_comment and not line_has_comment : break else : license_end += 1 first_year = last_year if first_comment_is_license and license_end > 0 : license_part = linesep . join ( stripped_lines [ 0 : license_end ] ) appendix_part = linesep + linesep . join ( stripped_lines [ license_end : ] ) . lstrip ( ) year_regex = regex . compile ( r"Copyright \(c\)(?>.*?\s(20..))" ) for line in license_part . split ( linesep ) : match = year_regex . search ( line ) if match : first_year = match . group ( 1 ) break return True , first_year , appendix_part else : return False , first_year , linesep + lines . lstrip ( )
Try finding license with string search.
Try finding license with string search .
"""Try finding license with string search.

        Keyword arguments:
        lines -- lines of file
        last_year -- last year in copyright range
        license_template -- license_template string

        Returns:
        Tuple of whether license was found, first year in copyright range, and
        file contents after license.
        """ # Strip newlines at top of file # If a comment at the beginning of the file is considered a license, it # is replaced with an updated license. Otherwise, a license header is # inserted before it. # Regex for tokenizing on comment boundaries # If part of comment contains "Copyright (c)", comment is # license. # If any comment token was matched, the line has a comment # If comment at beginning of file is non-empty license, update it # If license contains copyright pattern, extract the first year
None
self
lines
last_year
license_template