aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/cplusplus/PPToken.cpp
blob: 76252ec5e0d65ff67e7ea3bb2e108220f737aaea (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "PPToken.h"

#include <cstring>

using namespace CPlusPlus;
using namespace CPlusPlus::Internal;

bool ByteArrayRef::startsWith(const char *s) const
{
    const int l = int(std::strlen(s));
    if (l > m_length)
        return false;
    return !qstrncmp(start(), s, l);
}

int ByteArrayRef::count(char ch) const
{
    int num = 0;
    const char *b = start();
    const char *i = b + m_length;
    while (i != b)
        if (*--i == ch)
            ++num;
    return num;
}

void PPToken::squeezeSource()
{
    if (hasSource()) {
        m_src = m_src.mid(byteOffset, f.bytes);
        m_src.squeeze();
        m_originalOffset = byteOffset;
        byteOffset = 0;
        utf16charOffset = 0;
    }
}