Move escape_json_string and remove_newlines to zm_utils

pull/4344/head
Isaac Connor 2025-06-26 14:53:38 -04:00
parent 48a856a0ea
commit 548991ea3c
4 changed files with 22 additions and 35 deletions

View File

@ -23,7 +23,6 @@
#include "zm_time.h"
#include <regex>
std::string escape_json_string(std::string input);
Monitor::JanusManager::JanusManager(Monitor *parent_) :
parent(parent_),
@ -348,14 +347,3 @@ int Monitor::JanusManager::get_janus_handle() {
return 1;
} //get_janus_handle
std::string escape_json_string( std::string input ) {
std::string tmp;
tmp = regex_replace(input, std::regex("\n"), "\\n");
tmp = regex_replace(tmp, std::regex("\b"), "\\b");
tmp = regex_replace(tmp, std::regex("\f"), "\\f");
tmp = regex_replace(tmp, std::regex("\r"), "\\r");
tmp = regex_replace(tmp, std::regex("\t"), "\\t");
tmp = regex_replace(tmp, std::regex("\""), "\\\"");
tmp = regex_replace(tmp, std::regex("[\\\\]"), "\\\\");
return tmp;
}

View File

@ -21,13 +21,11 @@
#include "zm_monitor.h"
#include "zm_server.h"
#include "zm_time.h"
#include "zm_utils.h"
#include <algorithm>
#include <regex>
std::string remove_newlines(std::string input);
std::string escape_json_string(std::string input);
Monitor::RTSP2WebManager::RTSP2WebManager(Monitor *parent_) :
parent(parent_),
RTSP2Web_Healthy(false) {
@ -187,23 +185,3 @@ size_t Monitor::RTSP2WebManager::WriteCallback(void *contents, size_t size, size
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
std::string remove_newlines( std::string str ) {
while (!str.empty() && str.find("\n") != std::string::npos)
str.erase(std::remove(str.begin(), str.end(), '\n'), str.cend());
return str;
}
/*
std::string escape_json_string( std::string input ) {
std::string tmp;
tmp = regex_replace(input, std::regex("\n"), "\\n");
tmp = regex_replace(tmp, std::regex("\b"), "\\b");
tmp = regex_replace(tmp, std::regex("\f"), "\\f");
tmp = regex_replace(tmp, std::regex("\r"), "\\r");
tmp = regex_replace(tmp, std::regex("\t"), "\\t");
tmp = regex_replace(tmp, std::regex("\""), "\\\"");
tmp = regex_replace(tmp, std::regex("[\\\\]"), "\\\\");
return tmp;
}
*/

View File

@ -26,6 +26,7 @@
#include <cstdarg>
#include <cstring>
#include <fcntl.h> /* Definition of AT_* constants */
#include <regex>
#include <sstream>
#include <sys/stat.h>
@ -520,3 +521,21 @@ std::string remove_authentication(const std::string &url) {
}
return result;
}
std::string remove_newlines( std::string str ) {
while (!str.empty() && str.find("\n") != std::string::npos)
str.erase(std::remove(str.begin(), str.end(), '\n'), str.cend());
return str;
}
std::string escape_json_string( std::string input ) {
std::string tmp;
tmp = regex_replace(input, std::regex("\n"), "\\n");
tmp = regex_replace(tmp, std::regex("\b"), "\\b");
tmp = regex_replace(tmp, std::regex("\f"), "\\f");
tmp = regex_replace(tmp, std::regex("\r"), "\\r");
tmp = regex_replace(tmp, std::regex("\t"), "\\t");
tmp = regex_replace(tmp, std::regex("\""), "\\\"");
tmp = regex_replace(tmp, std::regex("[\\\\]"), "\\\\");
return tmp;
}

View File

@ -43,6 +43,8 @@
typedef std::vector<std::string> StringVector;
std::string escape_json_string(std::string input);
std::string remove_newlines(std::string input);
std::string Trim(const std::string &str, const std::string &char_set);
inline std::string TrimSpaces(const std::string &str) { return Trim(str, " \t"); }
std::string ReplaceAll(std::string str, const std::string &old_value, const std::string &new_value);