Skip to content

Commit

Permalink
all keys to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Feb 22, 2024
1 parent 786a777 commit 14d2d9a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 54 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.11.101
5.11.102
47 changes: 0 additions & 47 deletions src/fdb5/database/InspectionKey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,53 +106,6 @@ Key InspectionKey::canonical() const {
return key;
}

// void InspectionKey::decode(eckit::Stream& s) {

// ASSERT(rule_ == nullptr);

// keys_.clear();
// names_.clear();


// size_t n;

// s >> n;
// std::string k;
// std::string v;
// for (size_t i = 0; i < n; ++i) {
// s >> k;
// s >> v;
// keys_[k] = v;
// }

// s >> n;
// for (size_t i = 0; i < n; ++i) {
// s >> k;
// s >> v; // this is the type (ignoring FTM)
// names_.push_back(k);
// }
// s >> canonical_;
// }

// void InspectionKey::encode(eckit::Stream& s) const {
// const TypesRegistry& registry = this->registry();

// s << keys_.size();
// for (eckit::StringDict::const_iterator i = keys_.begin(); i != keys_.end(); ++i) {
// const Type &t = registry.lookupType(i->first);
// s << i->first << canonicalise(i->first, i->second);
// }

// s << names_.size();
// for (eckit::StringList::const_iterator i = names_.begin(); i != names_.end(); ++i) {
// const Type &t = registry.lookupType(*i);
// s << (*i);
// s << t.type();
// }

// s << true;
// }

void InspectionKey::rule(const Rule *rule) {
rule_ = rule;
}
Expand Down
26 changes: 22 additions & 4 deletions src/fdb5/database/Key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <algorithm>

#include "eckit/config/Resource.h"
#include "eckit/container/DenseSet.h"
#include "eckit/utils/Tokenizer.h"

Expand Down Expand Up @@ -79,7 +80,7 @@ void Key::decode(eckit::Stream& s) {
for (size_t i = 0; i < n; ++i) {
s >> k;
s >> v;
keys_[k] = v;
keys_[k] = lower(v);
}

s >> n;
Expand Down Expand Up @@ -126,9 +127,9 @@ void Key::set(const std::string &k, const std::string &v) {
eckit::StringDict::iterator it = keys_.find(k);
if (it == keys_.end()) {
names_.push_back(k);
keys_[k] = v;
keys_[k] = lower(v);
} else {
it->second = v;
it->second = lower(v);
}

}
Expand All @@ -138,7 +139,7 @@ void Key::unset(const std::string &k) {
}

void Key::push(const std::string &k, const std::string &v) {
keys_[k] = v;
keys_[k] = lower(v);
names_.push_back(k);
}

Expand Down Expand Up @@ -338,7 +339,24 @@ fdb5::Key::operator std::string() const {
return toString();
}

std::string Key::lower(const std::string& value) const {

static bool toLower = eckit::Resource<bool>("fdbKeysLowercase;$FDB_KEYS_LOWERCASE", true);

if (!toLower) {
return value;
}

std::string lowerCase;
lowerCase.resize(value.size());

std::transform(value.begin(), value.end(), lowerCase.begin(), [](unsigned char c){ return std::tolower(c); });

return lowerCase;
}

std::string Key::canonicalise(const std::string&, const std::string& value) const {

return value;
}

Expand Down
2 changes: 2 additions & 0 deletions src/fdb5/database/Key.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class Key {

protected: // methods

std::string lower(const std::string& value) const;

//TODO add unit test for each type
virtual std::string canonicalise(const std::string& keyword, const std::string& value) const;

Expand Down
4 changes: 2 additions & 2 deletions tests/fdb/type/test_toKey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ CASE( "Date - string ctor - expansion" ) {
eckit::Translator<long, std::string> t;

EXPECT(key.canonicalValue("date") == t(now.yyyymmdd()));
EXPECT(key.valuesToString() == "od:0001:oper:ofb:"+t(now.yyyymmdd())+":0000:MHS:3001");
EXPECT(key.valuesToString() == "od:0001:oper:ofb:"+t(now.yyyymmdd())+":0000:mhs:3001");

fdb5::Archiver archiver;
fdb5::ArchiveVisitor visitor(archiver, key, data, 4);
Expand All @@ -284,7 +284,7 @@ CASE( "Date - string ctor - expansion" ) {

// std::cout << key.valuesToString() << std::endl;
EXPECT(key.canonicalValue("date") == t(now.yyyymmdd()));
EXPECT(key.valuesToString() == "od:0001:oper:ofb:"+t(now.yyyymmdd())+":0000:MHS:3001");
EXPECT(key.valuesToString() == "od:0001:oper:ofb:"+t(now.yyyymmdd())+":0000:mhs:3001");

}

Expand Down

0 comments on commit 14d2d9a

Please sign in to comment.