Skip to content

Commit

Permalink
#2216 Added m_replace_char
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Sep 15, 2022
1 parent 829602a commit f56ba5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/basic/vx_log/str_wrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ using namespace std;
#include "str_wrappers.h"


////////////////////////////////////////////////////////////////////////

bool is_whitespaces(char cur_char) {
return (' ' == cur_char || '\t' == cur_char || '\n' == cur_char || '\r' == cur_char);
}

////////////////////////////////////////////////////////////////////////

int m_strlen(const char *str) {
Expand Down Expand Up @@ -109,6 +115,21 @@ void m_strncpy(char *to_str, const char *from_str, const int buf_len,

////////////////////////////////////////////////////////////////////////

bool m_replace_char(char *str_buf, char from_ch, char to_ch, bool all_instances) {
bool replaced = false;
int str_len = m_strlen(str_buf);
for(int idx=0; idx<str_len; idx++) {
if (from_ch == str_buf[idx]) {
replaced = true;
str_buf[idx] = to_ch;
if (!all_instances) break;
}
}
return replaced;
}

////////////////////////////////////////////////////////////////////////

void m_rstrip(char *str_buf, int buf_len, bool find_white_ch) {
// Make sure it's NULL terminated
if (buf_len >= 0) str_buf[buf_len] = '\0';
Expand All @@ -124,9 +145,3 @@ void m_rstrip(char *str_buf, int buf_len, bool find_white_ch) {
}

////////////////////////////////////////////////////////////////////////

bool is_whitespaces(char cur_char) {
return (' ' == cur_char || '\t' == cur_char || '\n' == cur_char || '\r' == cur_char);
}

////////////////////////////////////////////////////////////////////////
3 changes: 3 additions & 0 deletions src/basic/vx_log/str_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ extern void m_strncpy(char *to_str, const char *from_str, const int buf_len,

extern void m_rstrip(char *str_buf, const int buf_len=-1, bool find_white_ch=true);

extern bool m_replace_char(char *str_buf, char from_ch, char to_ch,
bool all_instances=true);

extern bool is_whitespaces(char cur_char);

////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit f56ba5f

Please sign in to comment.