void TestMultilangString(lang_string const * arr, size_t count) { StringUtf8Multilang s; for (size_t i = 0; i < count; ++i) { string src(arr[i].m_str); TEST(utf8::is_valid(src.begin(), src.end()), ()); s.AddString(arr[i].m_lang, src); string comp; TEST(s.GetString(arr[i].m_lang, comp), ()); TEST_EQUAL(src, comp, ()); } for (size_t i = 0; i < count; ++i) { string comp; TEST(s.GetString(arr[i].m_lang, comp), ()); TEST_EQUAL(arr[i].m_str, comp, ()); } string test; TEST(!s.GetString("xxx", test), ()); }
void EditableMapObject::RemoveBlankAndDuplicationsForDefault() { StringUtf8Multilang editedName; string defaultName; m_name.GetString(StringUtf8Multilang::kDefaultCode, defaultName); m_name.ForEach([&defaultName, &editedName](int8_t langCode, string const & name) { auto const duplicate = langCode != StringUtf8Multilang::kDefaultCode && defaultName == name; if (!name.empty() && !duplicate) editedName.AddString(langCode, name); }); m_name = editedName; }
void EditorDialog::OnSave() { // Store all edits. if (m_feature.IsNameEditable()) { StringUtf8Multilang names; for (int8_t langCode = StringUtf8Multilang::kDefaultCode; langCode < StringUtf8Multilang::kMaxSupportedLanguages; ++langCode) { QLineEdit * le = findChild<QLineEdit *>(StringUtf8Multilang::GetLangByCode(langCode)); if (!le) continue; string const name = le->text().toStdString(); if (!name.empty()) names.AddString(langCode, name); } m_feature.SetName(names); } if (m_feature.IsAddressEditable()) { m_feature.SetHouseNumber(findChild<QLineEdit *>(kHouseNumberObjectName)->text().toStdString()); QString const editedStreet = findChild<QComboBox *>(kStreetObjectName)->currentText(); QStringList const names = editedStreet.split(" / ", QString::SkipEmptyParts); QString const localized = names.size() > 1 ? names.at(1) : QString(); if (!names.empty()) m_feature.SetStreet({names.at(0).toStdString(), localized.toStdString()}); else m_feature.SetStreet({}); m_feature.SetPostcode(findChild<QLineEdit *>(kPostcodeObjectName)->text().toStdString()); } for (osm::Props const prop : m_feature.GetEditableProperties()) { if (prop == osm::Props::Internet) { QComboBox * cmb = findChild<QComboBox *>(kInternetObjectName); string const str = cmb->currentText().toStdString(); osm::Internet v = osm::Internet::Unknown; if (str == DebugPrint(osm::Internet::Wlan)) v = osm::Internet::Wlan; else if (str == DebugPrint(osm::Internet::Wired)) v = osm::Internet::Wired; else if (str == DebugPrint(osm::Internet::No)) v = osm::Internet::No; else if (str == DebugPrint(osm::Internet::Yes)) v = osm::Internet::Yes; m_feature.SetInternet(v); continue; } QLineEdit * editor = findChild<QLineEdit *>(QString::fromStdString(DebugPrint(prop))); if (!editor) continue; string const v = editor->text().toStdString(); switch (prop) { case osm::Props::Phone: m_feature.SetPhone(v); break; case osm::Props::Fax: m_feature.SetFax(v); break; case osm::Props::Email: m_feature.SetEmail(v); break; case osm::Props::Website: m_feature.SetWebsite(v); break; case osm::Props::Internet: ASSERT(false, ("Is handled separately above.")); case osm::Props::Cuisine: { vector<string> cuisines; strings::Tokenize(v, ";", MakeBackInsertFunctor(cuisines)); m_feature.SetCuisines(cuisines); } break; case osm::Props::OpeningHours: m_feature.SetOpeningHours(v); break; case osm::Props::Stars: { int num; if (strings::to_int(v, num)) m_feature.SetStars(num); } break; case osm::Props::Operator: m_feature.SetOperator(v); break; case osm::Props::Elevation: { double ele; if (strings::to_double(v, ele)) m_feature.SetElevation(ele); } break; case osm::Props::Wikipedia: m_feature.SetWikipedia(v); break; case osm::Props::Flats: m_feature.SetFlats(v); break; case osm::Props::BuildingLevels: m_feature.SetBuildingLevels(v); break; } } accept(); }