From 7c0ddcf5b14552ee4058c9098e6599d087d5c012 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 9 Jan 2019 15:32:33 +0100 Subject: [PATCH] qt: expose the spdx parser to Qt users --- qt/meson.build | 6 ++++-- qt/spdx.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ qt/spdx.h | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 qt/spdx.cpp create mode 100644 qt/spdx.h diff --git a/qt/meson.build b/qt/meson.build index 9da4da433..93b0082fe 100644 --- a/qt/meson.build +++ b/qt/meson.build @@ -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 = [ diff --git a/qt/spdx.cpp b/qt/spdx.cpp new file mode 100644 index 000000000..b8d4026a7 --- /dev/null +++ b/qt/spdx.cpp @@ -0,0 +1,53 @@ +/* + * Copyright(C) 2019 Aleix Pol Gonzalez + * + * 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 . + */ + +#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))); +} diff --git a/qt/spdx.h b/qt/spdx.h new file mode 100644 index 000000000..03f185e56 --- /dev/null +++ b/qt/spdx.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 Aleix Pol Gonzalez + * + * 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 . + */ + +#ifndef APPSTREAMQT_SPDX_H +#define APPSTREAMQT_SPDX_H + +#include +#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