Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt: expose the spdx parser to Qt users #213

Merged
merged 1 commit into from Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -21,7 +21,8 @@ asqt_src = [
'contentrating.cpp',
'launchable.cpp',
'translation.cpp',
'metadata.cpp'
'metadata.cpp',
'spdx.cpp'
]

asqt_pub_headers = [
@@ -39,7 +40,8 @@ asqt_pub_headers = [
'contentrating.h',
'launchable.h',
'translation.h',
'metadata.h'
'metadata.h',
'spdx.h'
]

asqt_priv_headers = [
@@ -0,0 +1,53 @@
/*
* Copyright(C) 2019 Aleix Pol Gonzalez <aleixpol@kde.rog>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the license, or
*(at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#include "spdx.h"
#include "chelpers.h"
#include "as-spdx.h"

bool AppStream::SPDX::isLicenseId(const QString &license_id)
{
return as_is_spdx_license_id(qPrintable(license_id));
}

bool AppStream::SPDX::isLicenseExpression(const QString &license)
{
return as_is_spdx_license_expression(qPrintable(license));
}

bool AppStream::SPDX::isMetadataLicense(const QString &license)
{
return as_license_is_metadata_license(qPrintable(license));
}

QStringList AppStream::SPDX::tokenizeLicense(const QString &license)
{
return AppStream::valueWrap(as_spdx_license_tokenize(qPrintable(license)));
}

QString AppStream::SPDX::detokenizeLicense(const QStringList &license_tokens)
{
gchar** tokens = AppStream::stringListToCharArray(license_tokens);
return QString::fromUtf8(as_spdx_license_detokenize(tokens));
}

QString AppStream::SPDX::asSpdxId(const QString &license)
{
return QString::fromUtf8(as_license_to_spdx_id(qPrintable(license)));
}
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2019 Aleix Pol Gonzalez <aleixpol@kde.rog>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the license, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef APPSTREAMQT_SPDX_H
#define APPSTREAMQT_SPDX_H

#include <QStringList>
#include "appstreamqt_export.h"

namespace AppStream {

namespace SPDX {
APPSTREAMQT_EXPORT bool isLicenseId(const QString &license_id);
APPSTREAMQT_EXPORT bool isLicenseExpression(const QString &license);
APPSTREAMQT_EXPORT bool isMetadataLicense(const QString &license);

APPSTREAMQT_EXPORT QStringList tokenizeLicense(const QString &license);
APPSTREAMQT_EXPORT QString detokenizeLicense(const QStringList &license_tokens);

APPSTREAMQT_EXPORT QString asSpdxId(const QString &license);

}

}

#endif