// The number of characters in the fake data URL prefix.
const size_t kFakeDataUrlLength = sizeof FakeDownloader::kFakeDataUrl - 1;
-// Each key begins with this string.
-const char kKeyPrefix[] = "data/";
+// Returns "data/HK" for "data/HK--en".
+std::string RemoveLanguageCode(const std::string& key) {
+ std::string::size_type language_code_pos = key.find("--");
+ return language_code_pos == std::string::npos
+ ? key
+ : key.substr(0, language_code_pos);
+}
-// The number of characters in the key prefix.
-const size_t kKeyPrefixLength = sizeof kKeyPrefix - 1;
+std::string CCKey(const std::string& key) {
+ const char kSplitChar = '/';
-// The number of characters in a country-level key.
-const size_t kCountryKeyLength = kKeyPrefixLength + 2;
+ std::string::size_type split = key.find(kSplitChar);
+ if (split == std::string::npos) {
+ return key;
+ }
+ split = key.find(kSplitChar, split + 1);
+ if (split == std::string::npos) {
+ return key;
+ }
+
+ return key.substr(0, split);
+}
std::map<std::string, std::string> InitData() {
std::map<std::string, std::string> data;
std::string line;
while (file.good()) {
std::getline(file, line);
- if (line.compare(0, kKeyPrefixLength, kKeyPrefix, kKeyPrefixLength) != 0) {
- continue;
- }
std::string::size_type divider = line.find('=');
if (divider == std::string::npos) {
}
std::string key = line.substr(0, divider);
+ std::string cc_key = RemoveLanguageCode(CCKey(key));
std::string value = line.substr(divider + 1);
- std::string url =
- FakeDownloader::kFakeDataUrl + key.substr(0, kCountryKeyLength);
+ std::string url = FakeDownloader::kFakeDataUrl + cc_key;
std::map<std::string, std::string>::iterator data_it = data.find(url);
if (data_it != data.end()) {
data_it->second += ", \"" + key + "\": " + value;