From 02ce75550c12b14c9b4bdf3f04f18716220c5152 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 20 Oct 2020 17:09:05 -0400 Subject: [PATCH] =?UTF-8?q?fix=20isUnclassified()=20so=20it=20works=20for?= =?UTF-8?q?=20"NON=20CLASSIFI=C3=89=20/=20UNCLASSIFIED"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../six.sicd/unittests/test_CollectionInfo.cpp | 4 ++-- six/modules/c++/six/include/six/Classification.h | 6 +----- six/modules/c++/six/source/Classification.cpp | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/six/modules/c++/six.sicd/unittests/test_CollectionInfo.cpp b/six/modules/c++/six.sicd/unittests/test_CollectionInfo.cpp index 4b9a63576..0f0a7ba71 100644 --- a/six/modules/c++/six.sicd/unittests/test_CollectionInfo.cpp +++ b/six/modules/c++/six.sicd/unittests/test_CollectionInfo.cpp @@ -73,7 +73,7 @@ TEST_CASE(ClassificationFrench) auto data = createData(types::RowCol(10, 10)); data->collectionInformation->setClassificationLevel(classificationText); data->setPreserveCharacterData(true); // needed to parse UTF-8 XML - //TEST_ASSERT_TRUE(data->getClassification().isUnclassified()); + TEST_ASSERT_TRUE(data->getClassification().isUnclassified()); const std::vector schemaPaths; const auto strXml = six::sicd::Utilities::toXMLString(*data, schemaPaths); @@ -83,7 +83,7 @@ TEST_CASE(ClassificationFrench) const auto UNCLASSIFIED = strXml.find(" / UNCLASSIFIED"); TEST_ASSERT(UNCLASSIFIED != std::string::npos); const auto utf8 = strXml.substr(NON_CLASSIFI, UNCLASSIFIED - NON_CLASSIFI); - TEST_ASSERT_EQ(utf8.size(), 14); + TEST_ASSERT_EQ(utf8.size(), std::string("NON CLASSIFI\xc3\x89").size()); // UTF-8, "NON CLASSIFI�" const auto E_ = utf8.find("\xc3\x89"); // UTF-8, "�" TEST_ASSERT(E_ != std::string::npos); diff --git a/six/modules/c++/six/include/six/Classification.h b/six/modules/c++/six/include/six/Classification.h index b3d8ac250..995783cfb 100644 --- a/six/modules/c++/six/include/six/Classification.h +++ b/six/modules/c++/six/include/six/Classification.h @@ -56,11 +56,7 @@ class Classification // SICD spells this out, SIDD does not virtual std::string getLevel() const = 0; - bool isUnclassified() const - { - const std::string level(getLevel()); - return (!level.empty() && ::toupper(level[0]) == 'U'); - } + bool isUnclassified() const; virtual void setSecurity(const std::string& /*prefix*/, logging::Logger& /*log*/, diff --git a/six/modules/c++/six/source/Classification.cpp b/six/modules/c++/six/source/Classification.cpp index 5ddcef99e..51b3b2e34 100644 --- a/six/modules/c++/six/source/Classification.cpp +++ b/six/modules/c++/six/source/Classification.cpp @@ -23,6 +23,22 @@ using namespace six; +bool six::Classification::isUnclassified() const +{ + const std::string level(getLevel()); + if (!level.empty() && (::toupper(level[0]) == 'U')) + { + return true; + } + + // There could be French text first: "NON CLASSIFI� / UNCLASSIFIED" + if (level.find("UNCLASS") != std::string::npos) + { + return true; + } + return level.find("Unclass") != std::string::npos; +} + std::ostream& operator<<(std::ostream& os, const Classification& c) { os << "Classification: " << std::endl;