correct extract_line to avoid duplicate with erase or substr, and to resolve pbm of returning trailing delim

This commit is contained in:
hugogogo
2022-08-11 17:33:42 +02:00
parent ff77dfd298
commit ad2b5a629a
3 changed files with 91 additions and 55 deletions

View File

@@ -10,6 +10,7 @@
# include <sys/stat.h> // stat()
# include <cctype> // tolower
# include <algorithm> // transform
# include <cstdio> // fflush
# define CR "\r"
# define LF "\n"
@@ -36,7 +37,7 @@ bool operator==(const listen_socket& lhs, int fd);
bool operator==(int fd, const listen_socket& rhs);
std::vector<std::string> split(std::string input, char delimiter);
std::vector<std::string> split_trim(std::string s, std::string d, char c);
std::vector<std::string> split_trim(std::string input, std::string delim = "\n", char ctrim = '\0');
bool isNumeric(std::string str);
bool isNumeric_btw(int low, int high, std::string str);
std::string itos(int n);
@@ -46,9 +47,11 @@ std::string http_methods_to_str(unsigned int methods);
int path_is_valid(std::string path);
void replace_all_substr(std::string &str, const std::string &ori_substr, const std::string &new_substr);
std::string str_tolower(std::string str);
std::string extract_line(std::string & s, size_t p, std::string d);
std::string get_line(std::string str, size_t pos, std::string del);
std::string extract_line(std::string & str, size_t pos = 0, std::string delim = "\n");
std::string get_line (std::string str, size_t pos = 0, std::string delim = "\n");
size_t parse_http_headers (std::string headers, std::map<std::string, std::string> fields );
void throw_test();
// debug
void print_special(std::string str);
#endif