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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2014-2017 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
/**
* SECTION:as-tag
* @short_description: Helper functions to convert to and from tag enums
* @include: appstream-glib.h
* @stability: Stable
*
* These functions will convert a tag enum such as %AS_TAG_COMPONENT to
* it's string form, and also vice-versa.
*
* These helper functions may be useful if implementing an AppStream parser.
*/
#include "config.h"
#include "as-tag.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#include "as-tag-private.h"
#pragma GCC diagnostic pop
/**
* as_tag_from_string:
* @tag: the string.
*
* Converts the text representation to an enumerated value.
*
* Returns: a %AsTag, or %AS_TAG_UNKNOWN if not known.
*
* Since: 0.1.0
**/
AsTag
as_tag_from_string (const gchar *tag)
{
return as_tag_from_string_full (tag, AS_TAG_FLAG_NONE);
}
/**
* as_tag_from_string_full:
* @tag: the string.
* @flags: the #AsTagFlags e.g. %AS_TAG_FLAG_USE_FALLBACKS
*
* Converts the text representation to an enumerated value also converting
* legacy key names.
*
* Returns: a %AsTag, or %AS_TAG_UNKNOWN if not known.
*
* Since: 0.1.2
**/
AsTag
as_tag_from_string_full (const gchar *tag, AsTagFlags flags)
{
const struct tag_data *ky;
AsTag etag = AS_TAG_UNKNOWN;
/* invalid */
if (tag == NULL)
return AS_TAG_UNKNOWN;
/* use a perfect hash */
ky = _as_tag_from_gperf (tag, strlen (tag));
if (ky != NULL)
etag = ky->etag;
/* deprecated names */
if (etag == AS_TAG_UNKNOWN && (flags & AS_TAG_FLAG_USE_FALLBACKS)) {
if (g_strcmp0 (tag, "appcategories") == 0)
return AS_TAG_CATEGORIES;
if (g_strcmp0 (tag, "appcategory") == 0)
return AS_TAG_CATEGORY;
if (g_strcmp0 (tag, "licence") == 0)
return AS_TAG_PROJECT_LICENSE;
if (g_strcmp0 (tag, "applications") == 0)
return AS_TAG_COMPONENTS;
if (g_strcmp0 (tag, "application") == 0)
return AS_TAG_COMPONENT;
if (g_strcmp0 (tag, "updatecontact") == 0)
return AS_TAG_UPDATE_CONTACT;
/* fix spelling error */
if (g_strcmp0 (tag, "metadata_licence") == 0)
return AS_TAG_METADATA_LICENSE;
}
/* translated versions */
if (etag == AS_TAG_UNKNOWN && (flags & AS_TAG_FLAG_USE_TRANSLATED)) {
if (g_strcmp0 (tag, "_name") == 0)
return AS_TAG_NAME;
if (g_strcmp0 (tag, "_summary") == 0)
return AS_TAG_SUMMARY;
if (g_strcmp0 (tag, "_caption") == 0)
return AS_TAG_CAPTION;
}
return etag;
}
/**
* as_tag_to_string:
* @tag: the %AsTag value.
*
* Converts the enumerated value to an text representation.
*
* Returns: string version of @tag
*
* Since: 0.1.0
**/
const gchar *
as_tag_to_string (AsTag tag)
{
const gchar *str[] = {
"unknown",
"components",
"component",
"id",
"pkgname",
"name",
"summary",
"description",
"url",
"icon",
"categories",
"category",
"keywords",
"keyword",
"mimetypes",
"mimetype",
"project_group",
"project_license",
"screenshot",
"screenshots",
"update_contact",
"image",
"compulsory_for_desktop",
"priority",
"caption",
"languages",
"lang",
"metadata",
"value",
"releases",
"release",
"architectures",
"arch",
"metadata_license",
"provides",
"extends",
"developer_name",
"kudos",
"kudo",
"source_pkgname",
"vetos",
"veto",
"bundle",
"permissions",
"permission",
"location",
"checksum",
"size",
"translation",
"content_rating",
"content_attribute",
"version",
"reviews",
"review",
"reviewer_name",
"reviewer_id",
"suggests",
"requires",
"custom",
"launchable",
"agreement",
"agreement_section",
"p",
"li",
"ul",
"ol",
"binary",
"font",
"dbus",
"modalias",
"library",
NULL };
if (tag > AS_TAG_LAST)
tag = AS_TAG_LAST;
return str[tag];
}
|