Skip to content

Commit

Permalink
constexpr instead of local static in TelegramParser::try_extract_json…
Browse files Browse the repository at this point in the history
…_value_str
  • Loading branch information
w0lek committed May 21, 2024
1 parent a4c90dd commit e1b578a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion vpr/src/server/convertutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::string get_truncated_middle_str(const std::string& src, std::size_t num) {
if (num < minimal_string_size_to_truncate) {
num = minimal_string_size_to_truncate;
}
constexpr char middle_place_holder[] = "...";
constexpr const char middle_place_holder[] = "...";
const std::size_t src_size = src.size();
if (src_size > num) {
int prefix_num = num / 2;
Expand Down
6 changes: 4 additions & 2 deletions vpr/src/server/telegramparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include "convertutils.h"
#include "commconstants.h"

#include <cstring>

namespace comm {

std::optional<std::string> TelegramParser::try_extract_json_value_str(const std::string& json_string, const std::string& key) {
static const std::string end_key_pattern{"\":\""};
constexpr const char end_key_pattern[] = {"\":\""};

// Find the position of the key
size_t key_pos = json_string.find('\"' + key + end_key_pattern);
Expand All @@ -18,7 +20,7 @@ std::optional<std::string> TelegramParser::try_extract_json_value_str(const std:
}

// Find the position of the value after the key
size_t value_pos_start = json_string.find('\"', key_pos + key.length() + end_key_pattern.size());
size_t value_pos_start = json_string.find('\"', key_pos + key.length() + std::strlen(end_key_pattern));

if (value_pos_start == std::string::npos) {
// Value not found
Expand Down

0 comments on commit e1b578a

Please sign in to comment.