Exemple #1
0
    def _updateStringIndex(self, text):
        """Regenerate index of found strings.
        
        This algorythm is suitable for either multiline strings and multiline comments.
        There are no any difference for highlighter
        """
        block = self.currentBlock()
        if block.previous().isValid():
            prevState = block.previous().userState()
        else:
            prevState = 0

        start = 0
        state = prevState
        foundStrings = []
        for match in re.finditer('"', text):
            if state:  # string end
                foundStrings.append(
                    _FoundString(start,
                                 match.start() + 1 - start))
                state = 0
            else:  # string start
                state = 1
                start = match.start()
        if state:
            foundStrings.append(_FoundString(start, len(text) - start))

        block.setUserState(state)

        data = self.currentBlockUserData()
        if data is None:
            data = QTextBlockUserData()
        data.foundStrings = foundStrings
        self.setCurrentBlockUserData(data)
Exemple #2
0
def data(block):
    """Get the block's QTextBlockUserData, creating it if necessary."""
    data = block.userData()
    if not data:
        data = QTextBlockUserData()
        block.setUserData(data)
    return data
Exemple #3
0
    def _updateBraceIndex(self, text):
        """Regenerate index of found braces for a block
        """
        foundBraces = []
        for match in self._bracePattern.finditer(text):
            if not self._insideString(match.start()):
                foundBraces.append(
                    _FoundBrace(self.currentBlock(), match.start(),
                                match.group(0)))

        data = self.currentBlockUserData()
        if data is None:
            data = QTextBlockUserData()
        data.foundBraces = foundBraces
        self.setCurrentBlockUserData(data)