generated from obsproject/obs-plugintemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add filter-replace-utils for serializing and deserializing … (
#154) * refactor: Add filter-replace-utils for serializing and deserializing filter words replacements * refactor: Add filter-replace-utils for serializing and deserializing filter words replacements * refactor: Add filter-replace-utils for serializing and deserializing filter words replacements
- Loading branch information
Showing
10 changed files
with
139 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "filter-replace-utils.h" | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
std::string serialize_filter_words_replace( | ||
const std::vector<std::tuple<std::string, std::string>> &filter_words_replace) | ||
{ | ||
if (filter_words_replace.empty()) { | ||
return "[]"; | ||
} | ||
// use JSON to serialize the filter_words_replace map | ||
nlohmann::json j; | ||
for (const auto &entry : filter_words_replace) { | ||
j.push_back({{"key", std::get<0>(entry)}, {"value", std::get<1>(entry)}}); | ||
} | ||
return j.dump(); | ||
} | ||
|
||
std::vector<std::tuple<std::string, std::string>> | ||
deserialize_filter_words_replace(const std::string &filter_words_replace_str) | ||
{ | ||
if (filter_words_replace_str.empty()) { | ||
return {}; | ||
} | ||
// use JSON to deserialize the filter_words_replace map | ||
std::vector<std::tuple<std::string, std::string>> filter_words_replace; | ||
nlohmann::json j = nlohmann::json::parse(filter_words_replace_str); | ||
for (const auto &entry : j) { | ||
filter_words_replace.push_back(std::make_tuple(entry["key"], entry["value"])); | ||
} | ||
return filter_words_replace; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef FILTER_REPLACE_UTILS_H | ||
#define FILTER_REPLACE_UTILS_H | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
std::string serialize_filter_words_replace( | ||
const std::vector<std::tuple<std::string, std::string>> &filter_words_replace); | ||
std::vector<std::tuple<std::string, std::string>> | ||
deserialize_filter_words_replace(const std::string &filter_words_replace_str); | ||
|
||
#endif /* FILTER_REPLACE_UTILS_H */ |