Skip to content

Commit

Permalink
fix isUnclassified() so it works for "NON CLASSIFIÉ / UNCLASSIFIED"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Oct 20, 2020
1 parent acfdeb3 commit 02ce755
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions six/modules/c++/six.sicd/unittests/test_CollectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TEST_CASE(ClassificationFrench)
auto data = createData<float>(types::RowCol<size_t>(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<std::string> schemaPaths;
const auto strXml = six::sicd::Utilities::toXMLString(*data, schemaPaths);
Expand All @@ -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);

Expand Down
6 changes: 1 addition & 5 deletions six/modules/c++/six/include/six/Classification.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*/,
Expand Down
16 changes: 16 additions & 0 deletions six/modules/c++/six/source/Classification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 02ce755

Please sign in to comment.