-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffoon.h
32 lines (29 loc) · 1.05 KB
/
buffoon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once
#include <string>
namespace Buffoon {
class Buffoon {
static std::string escapeSpecialChars(const std::string& key) {
std::string escapedKey;
for (char c : key) {
if (c == '$' || c == '^' || c == '.' || c == '*' || c == '+' || c == '?' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '|') {
escapedKey += '\\';
}
escapedKey += c;
}
return escapedKey;
}
public:
/**
* method to find the value keyed by "payload" from JSON-like string
* @param json_like_string, key(unquoted key)
* @return payload (null string if "payload" key is not found)
*/
static std::string findValueByKey(const std::string& json_like_string, const std::string& key);
/**
* method to find username (only applicable for mongo client login messages)
* @param payloadValue
* @return username
*/
static std::string findUsername(const std::string& payload_value);
};
} // namespace Buffoon