File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -7,24 +7,26 @@ namespace comm {
7
7
8
8
std::optional<std::string> TelegramParser::tryExtractJsonValueStr (const std::string& jsonString, const std::string& key)
9
9
{
10
+ static const std::string end_key_pattern{" \" :\" " };
11
+
10
12
// Find the position of the key
11
- size_t keyPos = jsonString.find (" \" " + key + " \" : " );
13
+ size_t keyPos = jsonString.find (' \" ' + key + end_key_pattern );
12
14
13
15
if (keyPos == std::string::npos) {
14
16
// Key not found
15
17
return std::nullopt;
16
18
}
17
19
18
20
// Find the position of the value after the key
19
- size_t valuePosStart = jsonString.find (" \" " , keyPos + key.length () + std::string ( " \" : \" " ) .size ());
21
+ size_t valuePosStart = jsonString.find (' \" ' , keyPos + key.length () + end_key_pattern .size ());
20
22
21
23
if (valuePosStart == std::string::npos) {
22
24
// Value not found
23
25
return std::nullopt;
24
26
}
25
27
26
28
// Find the position of the closing quote for the value
27
- size_t valueEnd = jsonString.find (" \" " , valuePosStart + std::string ( " \" " ). size ( ));
29
+ size_t valueEnd = jsonString.find (' \" ' , valuePosStart + sizeof ( ' \" ' ));
28
30
29
31
if (valueEnd == std::string::npos) {
30
32
// Closing quote not found
You can’t perform that action at this time.
0 commit comments