Searches for given pattern occurrences in given document using given settings.

        :param document: Document.
        :type document: QTextDocument
        :param pattern: Pattern.
        :type pattern: unicode
        :param settings: Search settings.
        :type settings: Structure
        :return: Matched occurrences.
        :rtype: list

def __search_document(self, document, pattern, settings):
        """
        Searches for given pattern occurrences in given document using given settings.

        :param document: Document.
        :type document: QTextDocument
        :param pattern: Pattern.
        :type pattern: unicode
        :param settings: Search settings.
        :type settings: Structure
        :return: Matched occurrences.
        :rtype: list
        """

        pattern = settings.regular_expressions and QRegExp(pattern) or pattern

        flags = QTextDocument.FindFlags()
        if settings.case_sensitive:
            flags = flags | QTextDocument.FindCaseSensitively
        if settings.whole_word:
            flags = flags | QTextDocument.FindWholeWords

        occurrences = []
        block = document.findBlock(0)
        cursor = document.find(pattern, block.position(), flags)
        while block.isValid() and cursor.position() != -1:
            if self.__interrupt:
                return

            block_cursor = QTextCursor(cursor)
            block_cursor.movePosition(QTextCursor.StartOfLine, QTextCursor.MoveAnchor)
            block_cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)
            length = cursor.selectionEnd() - cursor.selectionStart()
            occurrences.append(Occurence(line=cursor.blockNumber(),
                                         column=cursor.columnNumber() - length,
                                         length=length,
                                         position=cursor.position() - length,
                                         text=block_cursor.selectedText()))
            cursor = document.find(pattern, cursor.position(), flags)
            block = block.next()
        return occurrences