| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qqmlcompletioncontextstrings_p.h" |
| 5 | |
| 6 | CompletionContextStrings::CompletionContextStrings(QString code, qsizetype pos) |
| 7 | : m_code(code), m_pos(pos) |
| 8 | { |
| 9 | // computes the context just before pos in code. |
| 10 | // After this code all the values of all the attributes should be correct (see above) |
| 11 | // handle also letter or numbers represented a surrogate pairs? |
| 12 | m_filterStart = m_pos; |
| 13 | while (m_filterStart != 0) { |
| 14 | QChar c = code.at(i: m_filterStart - 1); |
| 15 | if (!c.isLetterOrNumber() && c != u'_') |
| 16 | break; |
| 17 | else |
| 18 | --m_filterStart; |
| 19 | } |
| 20 | // handle spaces? |
| 21 | m_baseStart = m_filterStart; |
| 22 | while (m_baseStart != 0) { |
| 23 | QChar c = code.at(i: m_baseStart - 1); |
| 24 | if (c != u'.' || m_baseStart == 1) |
| 25 | break; |
| 26 | c = code.at(i: m_baseStart - 2); |
| 27 | if (!c.isLetterOrNumber() && c != u'_') |
| 28 | break; |
| 29 | qsizetype baseEnd = --m_baseStart; |
| 30 | while (m_baseStart != 0) { |
| 31 | QChar c = code.at(i: m_baseStart - 1); |
| 32 | if (!c.isLetterOrNumber() && c != u'_') |
| 33 | break; |
| 34 | else |
| 35 | --m_baseStart; |
| 36 | } |
| 37 | if (m_baseStart == baseEnd) |
| 38 | break; |
| 39 | } |
| 40 | m_atLineStart = true; |
| 41 | m_lineStart = m_baseStart; |
| 42 | while (m_lineStart != 0) { |
| 43 | QChar c = code.at(i: m_lineStart - 1); |
| 44 | if (c == u'\n' || c == u'\r') |
| 45 | break; |
| 46 | if (!c.isSpace()) |
| 47 | m_atLineStart = false; |
| 48 | --m_lineStart; |
| 49 | } |
| 50 | } |
| 51 |
