Skip to content

Commit 9626f2e

Browse files
committed
Add new utility function 'trim'
Right now used in TAP tests.
1 parent 6759de3 commit 9626f2e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

include/proxysql_utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ std::string replace_str(const std::string& str, const std::string& match, const
298298
*/
299299
std::vector<std::string> split_str(const std::string& s, char delimiter);
300300

301+
/**
302+
* @brief Trims leading and trailing whitespace from a string.
303+
* @param s A string to trim (rvalue reference). The string will be modified in place.
304+
* @return The trimmed string (the modified input string).
305+
*/
306+
std::string trim(std::string&& s);
307+
301308
std::string generate_multi_rows_query(int rows, int params);
302309

303310
/**

lib/proxysql_utils.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#include "mysqld_error.h"
33

44
#include <algorithm>
5-
#include <functional>
65
#include <sstream>
76
#include <algorithm>
8-
#include <climits>
97

108
#include <fcntl.h>
119
#include <poll.h>
@@ -17,7 +15,6 @@
1715
#include <string.h>
1816
#include <unistd.h>
1917

20-
using std::function;
2118
using std::string;
2219
using std::unique_ptr;
2320
using std::vector;
@@ -401,6 +398,13 @@ std::string replace_str(const std::string& str, const std::string& match, const
401398
return result;
402399
}
403400

401+
string trim(string&& s) {
402+
s.erase(0, s.find_first_not_of(" \n\r\t"));
403+
s.erase(s.find_last_not_of(" \n\r\t") + 1);
404+
405+
return s;
406+
}
407+
404408
std::string generate_multi_rows_query(int rows, int params) {
405409
std::string s = "";
406410
int v = 1;

0 commit comments

Comments
 (0)