Skip to content

Commit 4dbe73d

Browse files
author
Alex Ames
committed
Moved VariantToPathMap into util_desktop.(cc|h) so that it can be reused
in tests.
1 parent 3b2b1d2 commit 4dbe73d

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

database/src/desktop/core/repo.cc

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -534,25 +534,6 @@ void Repo::PostEvents(const std::vector<Event>& events) {
534534
}
535535
}
536536

537-
static std::map<Path, Variant> VariantToPathMap(const Variant& data) {
538-
std::map<Path, Variant> path_map;
539-
if (data.is_map()) {
540-
for (const auto& key_value : data.map()) {
541-
Variant key_string_variant;
542-
const char* key;
543-
if (key_value.first.is_string()) {
544-
key = key_value.first.string_value();
545-
} else {
546-
key_string_variant = key_value.first.AsString();
547-
key = key_string_variant.string_value();
548-
}
549-
const Variant& value = key_value.second;
550-
path_map.insert(std::make_pair(Path(key), value));
551-
}
552-
}
553-
return path_map;
554-
}
555-
556537
void Repo::OnConnect() {
557538
SAFE_REFERENCE_RETURN_VOID_IF_INVALID(ThisRefLock, lock, safe_this_);
558539

database/src/desktop/util_desktop.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,23 @@ std::vector<std::string> split_string(const std::string& s, const char delimiter
12291229
return split_parts;
12301230
}
12311231

1232+
std::map<Path, Variant> VariantToPathMap(const Variant& data) {
1233+
std::map<Path, Variant> path_map;
1234+
if (data.is_map()) {
1235+
for (const auto& key_value : data.map()) {
1236+
const char* key;
1237+
if (key_value.first.is_string()) {
1238+
key = key_value.first.string_value();
1239+
} else {
1240+
key = key_value.first.AsString().string_value();
1241+
}
1242+
const Variant& value = key_value.second;
1243+
path_map.insert(std::make_pair(Path(key), value));
1244+
}
1245+
}
1246+
return path_map;
1247+
}
1248+
12321249
} // namespace internal
12331250
} // namespace database
12341251
} // namespace firebase

database/src/desktop/util_desktop.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ std::string GetAppDataPath(const char* app_name, bool should_create = true);
357357
// delimiter. Returns of vector of constituent parts
358358
std::vector<std::string> split_string(const std::string& s,
359359
const char delimiter='/');
360+
361+
std::map<Path, Variant> VariantToPathMap(const Variant& data);
362+
360363
} // namespace internal
361364
} // namespace database
362365
} // namespace firebase

0 commit comments

Comments
 (0)