summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2019-11-03 19:57:31 +0000
committerThomas Holder <thomas@thomas-holder.de>2019-11-03 19:57:31 +0000
commit7c38b95f02b7fad29ead9057ccb50a9f48c904ae (patch)
tree6cdc1ee90970d43826a61852e2c1029c515361ab
parentsanity check for XML attribute names (diff)
downloadinkscape-7c38b95f02b7fad29ead9057ccb50a9f48c904ae.tar.gz
inkscape-7c38b95f02b7fad29ead9057ccb50a9f48c904ae.zip
make SP_ATTRIBUTE_IS_CSS a function
-rw-r--r--src/attributes.cpp20
-rw-r--r--src/attributes.h17
2 files changed, 17 insertions, 20 deletions
diff --git a/src/attributes.cpp b/src/attributes.cpp
index 549dcf8ce..15f1e51b5 100644
--- a/src/attributes.cpp
+++ b/src/attributes.cpp
@@ -566,7 +566,9 @@ static_assert(n_attrs == SPAttributeEnum_SIZE, "");
/**
* Inverse to the \c props array for lookup by name.
*/
-struct AttributeLookupImpl {
+class AttributeLookupImpl {
+ friend SPAttributeEnum sp_attribute_lookup(gchar const *key);
+
struct cstrless {
bool operator()(char const *lhs, char const *rhs) const { return std::strcmp(lhs, rhs) < 0; }
};
@@ -607,20 +609,11 @@ sp_attribute_name(SPAttributeEnum id)
return props[id].name;
}
-std::vector<Glib::ustring> sp_attribute_name_list(bool cssattr, bool attr)
+std::vector<Glib::ustring> sp_attribute_name_list(bool css_only)
{
std::vector<Glib::ustring> result;
- static AttributeLookupImpl const _instance;
- bool add = attr;
for (auto prop : props) {
- if (prop.code == SP_ATTR_D) {
- if (cssattr) {
- add = true;
- } else if (attr) {
- add = false;
- }
- }
- if (add) {
+ if (!css_only || SP_ATTRIBUTE_IS_CSS(prop.code)) {
result.emplace_back(prop.name);
}
}
@@ -628,6 +621,9 @@ std::vector<Glib::ustring> sp_attribute_name_list(bool cssattr, bool attr)
return result;
}
+bool SP_ATTRIBUTE_IS_CSS(SPAttributeEnum k) { //
+ return (k >= SP_ATTR_D) && (k < SP_PROP_SYSTEM_LANGUAGE);
+}
/*
Local Variables:
diff --git a/src/attributes.h b/src/attributes.h
index 2ccbe470b..52c012892 100644
--- a/src/attributes.h
+++ b/src/attributes.h
@@ -17,12 +17,6 @@
#include <glibmm/value.h>
#include <vector>
-/**
- * True iff k is a property in SVG, i.e. something that can be written either in a style attribute
- * or as its own XML attribute. This must be kept in sync with SPAttributeEnum.
- */
-#define SP_ATTRIBUTE_IS_CSS(k) (((k) >= SP_ATTR_D) && ((k) < SP_PROP_SYSTEM_LANGUAGE))
-
/*
* Do not change order of attributes and properties. Attribute and
* order in an SVG file is (optionally) determined by the order here.
@@ -570,6 +564,12 @@ enum SPAttributeEnum : unsigned {
};
/**
+ * True iff k is a property in SVG, i.e. something that can be written either in a style attribute
+ * or as its own XML attribute. This must be kept in sync with SPAttributeEnum.
+ */
+bool SP_ATTRIBUTE_IS_CSS(SPAttributeEnum k);
+
+/**
* Get attribute id by name. Return SP_ATTR_INVALID for invalid names.
*/
SPAttributeEnum sp_attribute_lookup(gchar const *key);
@@ -580,9 +580,10 @@ SPAttributeEnum sp_attribute_lookup(gchar const *key);
gchar const *sp_attribute_name(SPAttributeEnum id);
/**
- * Get attribute name css list.
+ * Get sorted attribute name list.
+ * @param css_only If true, only return CSS properties
*/
-std::vector<Glib::ustring> sp_attribute_name_list(bool cssattr = false, bool attr = false);
+std::vector<Glib::ustring> sp_attribute_name_list(bool css_only = false);
#endif