-
Notifications
You must be signed in to change notification settings - Fork 74
v0.2.54..v0.2.55 changeset Tags.cpp
Garret Voltz edited this page Aug 14, 2020
·
1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/elements/Tags.cpp b/hoot-core/src/main/cpp/hoot/core/elements/Tags.cpp
index 3f422b1..ba1a948 100644
--- a/hoot-core/src/main/cpp/hoot/core/elements/Tags.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/elements/Tags.cpp
@@ -56,6 +56,28 @@ QHash<QString, QString>()
set(key, value);
}
+Tags::Tags(const QString& kvp)
+{
+ const QString errorMsg = "Invalid key/value pair passed to Tags: " + kvp;
+ if (!kvp.contains("="))
+ {
+ throw IllegalArgumentException(errorMsg);
+ }
+ const QStringList kvpParts = kvp.split("=");
+ if (kvpParts.size() != 2)
+ {
+ throw IllegalArgumentException(errorMsg);
+ }
+ const QString key = kvpParts[0];
+ const QString val = kvpParts[1];
+ if (key.trimmed().isEmpty() || val.trimmed().isEmpty())
+ {
+ throw IllegalArgumentException(errorMsg);
+ }
+
+ set(key, val);
+}
+
void Tags::add(const Tags& t)
{
for (Tags::const_iterator it = t.constBegin(); it != t.constEnd(); ++it)
@@ -579,9 +601,35 @@ bool Tags::operator==(const Tags& other) const
return true;
}
+bool Tags::hasSameNonMetadataTags(const Tags& other) const
+{
+ Tags otherCopy = other;
+ otherCopy.removeMetadata();
+ Tags thisCopy = *this;
+ thisCopy.removeMetadata();
+ return otherCopy == thisCopy;
+}
+
void Tags::removeMetadata()
{
removeByTagKeyStartsWith(MetadataTags::HootTagPrefix());
+
+ // there are some other metadata keys that don't start with hoot::
+ QStringList keysToRemove;
+ OsmSchema& schema = OsmSchema::getInstance();
+ for (Tags::const_iterator it = begin(); it != end(); ++it)
+ {
+ const QString key = it.key();
+ if (schema.isMetaData(key, it.value()))
+ {
+ keysToRemove.append(key);
+ }
+ }
+
+ for (int i = 0; i < keysToRemove.size(); i++)
+ {
+ remove(keysToRemove.at(i));
+ }
}
void Tags::removeByTagKeyContains(const QString& tagKeySubstring)
@@ -933,4 +981,14 @@ QString Tags::getDiffString(const Tags& other) const
return diffStr.trimmed();
}
+bool Tags::bothHaveInformation(const Tags& tags1, const Tags& tags2)
+{
+ return tags1.hasInformationTag() && tags2.hasInformationTag();
+}
+
+bool Tags::onlyOneHasInformation(const Tags& tags1, const Tags& tags2)
+{
+ return tags1.hasInformationTag() || tags2.hasInformationTag();
+}
+
}