2015-06-01 18:51:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
#include <clang-c/CXString.h>
|
|
|
|
|
|
|
|
|
|
#include <utf8string.h>
|
|
|
|
|
|
2016-09-07 11:57:42 +02:00
|
|
|
#include <cstring>
|
2017-06-13 16:04:45 +02:00
|
|
|
#include <ostream>
|
2016-09-07 11:57:42 +02:00
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
namespace ClangBackEnd {
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
class ClangString
|
|
|
|
|
{
|
|
|
|
|
public:
|
2016-09-07 11:57:42 +02:00
|
|
|
ClangString(CXString cxString)
|
|
|
|
|
: cxString(cxString)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ClangString()
|
|
|
|
|
{
|
|
|
|
|
clang_disposeString(cxString);
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 16:22:02 +02:00
|
|
|
ClangString(const ClangString &) = delete;
|
|
|
|
|
const ClangString &operator=(const ClangString &) = delete;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
|
2016-09-07 11:57:42 +02:00
|
|
|
ClangString(ClangString &&other)
|
|
|
|
|
: cxString(std::move(other.cxString))
|
|
|
|
|
{
|
|
|
|
|
other.cxString.data = nullptr;
|
|
|
|
|
other.cxString.private_flags = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ClangString &operator=(ClangString &&other)
|
|
|
|
|
{
|
|
|
|
|
if (this != &other) {
|
|
|
|
|
clang_disposeString(cxString);
|
|
|
|
|
cxString = std::move(other.cxString);
|
|
|
|
|
other.cxString.data = nullptr;
|
|
|
|
|
other.cxString.private_flags = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *cString() const
|
|
|
|
|
{
|
|
|
|
|
return clang_getCString(cxString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator Utf8String() const
|
|
|
|
|
{
|
|
|
|
|
return Utf8String(cString(), -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isNull() const
|
|
|
|
|
{
|
|
|
|
|
return cxString.data == nullptr;
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-06-13 16:04:45 +02:00
|
|
|
bool hasContent() const
|
|
|
|
|
{
|
|
|
|
|
return !isNull() && std::strlen(cString()) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 11:58:34 +02:00
|
|
|
friend bool operator==(const ClangString &first, const ClangString &second)
|
|
|
|
|
{
|
|
|
|
|
return std::strcmp(first.cString(), second.cString()) == 0;
|
|
|
|
|
}
|
2015-11-17 13:33:31 +01:00
|
|
|
|
2016-09-07 11:58:34 +02:00
|
|
|
template<std::size_t Size>
|
|
|
|
|
friend bool operator==(const ClangString &first, const char(&second)[Size])
|
|
|
|
|
{
|
|
|
|
|
return std::strncmp(first.cString(), second, Size) == 0; // Size includes \0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<std::size_t Size>
|
|
|
|
|
friend bool operator==(const char(&first)[Size], const ClangString &second)
|
|
|
|
|
{
|
|
|
|
|
return second == first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type,
|
|
|
|
|
typename = typename std::enable_if<std::is_pointer<Type>::value>::type
|
|
|
|
|
>
|
|
|
|
|
friend bool operator==(const ClangString &first, Type second)
|
|
|
|
|
{
|
|
|
|
|
return std::strcmp(first.cString(), second) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type,
|
|
|
|
|
typename = typename std::enable_if<std::is_pointer<Type>::value>::type
|
|
|
|
|
>
|
|
|
|
|
friend bool operator==(Type first, const ClangString &second)
|
|
|
|
|
{
|
|
|
|
|
return second == first;
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-06-13 16:04:45 +02:00
|
|
|
friend std::ostream &operator<<(std::ostream &out, const ClangString &string)
|
|
|
|
|
{
|
|
|
|
|
out << string.cString();
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
private:
|
|
|
|
|
CXString cxString;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
} // namespace ClangBackEnd
|