'Checks if a block/cursor is a string or a comment.
:param cursor_or_block: QTextCursor or QTextBlock
:param formats: the list of color scheme formats to consider. By
default, it will consider the following keys: \'comment\', \'string\',
\'docstring\'.'

def is_comment_or_string(self, cursor_or_block, formats=None):

    if (formats is None):
        formats = ['comment', 'string', 'docstring']
    layout = None
    pos = 0
    if isinstance(cursor_or_block, QTextBlock):
        pos = (len(cursor_or_block.text()) - 1)
        layout = cursor_or_block.layout()
    elif isinstance(cursor_or_block, QTextCursor):
        b = cursor_or_block.block()
        pos = (cursor_or_block.position() - b.position())
        layout = b.layout()
    if (layout is not None):
        additional_formats = layout.additionalFormats()
        sh = self._editor.syntax_highlighter
        if sh:
            ref_formats = sh.color_scheme.formats
            for r in additional_formats:
                if (r.start <= pos < (r.start + r.length)):
                    for fmt_type in formats:
                        is_user_obj = (r.format.objectType() == r.format.UserObject)
                        if ((ref_formats[fmt_type] == r.format) and is_user_obj):
                            return True
    return False
