tcp_cmd
Add tcp_cmd_remove_leading_space + tests
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
void tcp_cmd_remove_newline(char* str, size_t len);
|
||||
char* tcp_cmd_remove_leading_space(char* str, size_t len);
|
||||
char* tcp_cmd_get_filename_ext(char* filename);
|
||||
char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next);
|
||||
void tcp_cmd_init(void);
|
||||
|
||||
@@ -74,6 +74,17 @@ void tcp_cmd_remove_newline(char* str, size_t len) {
|
||||
str[i] = '\0';
|
||||
}
|
||||
|
||||
char* tcp_cmd_remove_leading_space(char* str, size_t len) {
|
||||
size_t i = 0;
|
||||
while (str[i] != '\0' && i < len) {
|
||||
if (isspace((int)str[i]) == 0) {
|
||||
return &str[i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function converts a string to lowercase
|
||||
* @param str The string to convert
|
||||
|
||||
@@ -54,6 +54,22 @@ TEST(TCP_CMD, tcp_cmd_remove_newline) {
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
TEST(TCP_CMD, tcp_cmd_remove_leading_space) {
|
||||
char* cmd = (char*)calloc(50, 1);
|
||||
strcpy(cmd, "help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, "\n\t\r\n help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
}
|
||||
|
||||
TEST(TCP_CMD, tcp_data_cb) {
|
||||
char* cmd = (char*)calloc(50, 1);
|
||||
std::string output;
|
||||
|
||||
Reference in New Issue
Block a user