aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlls/qqmlcompletioncontextstrings.cpp
blob: 5fc20066611bdd0fbd716772daab0f7097f63fa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qqmlcompletioncontextstrings_p.h"

CompletionContextStrings::CompletionContextStrings(QString code, qsizetype pos)
    : m_code(code), m_pos(pos)
{
    // computes the context just before pos in code.
    // After this code all the values of all the attributes should be correct (see above)
    // handle also letter or numbers represented a surrogate pairs?
    m_filterStart = m_pos;
    while (m_filterStart != 0) {
        QChar c = code.at(m_filterStart - 1);
        if (!c.isLetterOrNumber() && c != u'_')
            break;
        else
            --m_filterStart;
    }
    // handle spaces?
    m_baseStart = m_filterStart;
    while (m_baseStart != 0) {
        QChar c = code.at(m_baseStart - 1);
        if (c != u'.' || m_baseStart == 1)
            break;
        c = code.at(m_baseStart - 2);
        if (!c.isLetterOrNumber() && c != u'_')
            break;
        qsizetype baseEnd = --m_baseStart;
        while (m_baseStart != 0) {
            QChar c = code.at(m_baseStart - 1);
            if (!c.isLetterOrNumber() && c != u'_')
                break;
            else
                --m_baseStart;
        }
        if (m_baseStart == baseEnd)
            break;
    }
    m_atLineStart = true;
    m_lineStart = m_baseStart;
    while (m_lineStart != 0) {
        QChar c = code.at(m_lineStart - 1);
        if (c == u'\n' || c == u'\r')
            break;
        if (!c.isSpace())
            m_atLineStart = false;
        --m_lineStart;
    }
}