Skip to content

Commit 58e232d

Browse files
committed
added getPath object support for customstring
1 parent 9cb9a8b commit 58e232d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Utils/Json/CustomStringsLoader.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,23 @@ namespace dotnamecpp::utils {
147147
return std::nullopt;
148148
}
149149

150+
std::optional<std::string> CustomStringsLoader::getPath (const std::string& id) const {
151+
auto item = findById (id);
152+
if (!item) {
153+
return std::nullopt;
154+
}
155+
156+
try {
157+
if (item->contains ("data") && (*item)["data"].contains ("path")) {
158+
return (*item)["data"]["path"].get<std::string> ();
159+
}
160+
} catch (const std::exception&) {
161+
return std::nullopt;
162+
}
163+
164+
return std::nullopt;
165+
}
166+
150167
std::string CustomStringsLoader::getCustomStringSign () const {
151168
std::string result;
152169

src/Utils/Json/CustomStringsLoader.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ namespace dotnamecpp::utils {
3838
[[nodiscard]]
3939
std::optional<std::string> getTel (const std::string& id) const override;
4040

41+
[[nodiscard]]
42+
std::optional<std::string> getPath (const std::string& id) const override;
43+
4144
[[nodiscard]]
4245
std::string getCustomStringSign () const override;
4346

src/Utils/Json/ICustomStringsLoader.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ namespace dotnamecpp::utils {
6161
[[nodiscard]]
6262
virtual std::optional<std::string> getTel (const std::string& id) const = 0;
6363

64+
/**
65+
* @brief Get the Path object
66+
*
67+
* @param id
68+
* @return std::optional<std::string>
69+
*/
70+
[[nodiscard]]
71+
virtual std::optional<std::string> getPath (const std::string& id) const = 0;
72+
6473
/**
6574
* @brief Get the Custom String Sign object
6675
*

0 commit comments

Comments
 (0)