diff --git a/common/autocontrolmethod.hpp b/common/autocontrolmethod.hpp index 83f17057..339ac5f7 100755 --- a/common/autocontrolmethod.hpp +++ b/common/autocontrolmethod.hpp @@ -17,6 +17,7 @@ #include "teststr_join.h" #include "testrand.h" #include "testormcache.h" +#include "teststr_trim.h" #include "testsendmail.h" #include "admin/articles.h" #include "admin/topics.h" @@ -93,6 +94,9 @@ namespace http temp.regfun = testormcachec; methodcallback.emplace("testormcachec",temp); temp.pre = nullptr; + temp.regfun = teststrtrim; + methodcallback.emplace("teststr_trim",temp); + temp.pre = nullptr; temp.regfun = testsendmaildo; methodcallback.emplace("testsendmaildo",temp); temp.pre = admin_islogin; diff --git "a/controller/include/teststr_join\347\232\204\345\211\257\346\234\254.h" "b/controller/include/teststr_join\347\232\204\345\211\257\346\234\254.h" new file mode 100644 index 00000000..d8e21dc8 --- /dev/null +++ "b/controller/include/teststr_join\347\232\204\345\211\257\346\234\254.h" @@ -0,0 +1,12 @@ + +#pragma once +#include +#include +#include "httppeer.h" + +namespace http +{ + + + std::string teststrjoin(std::shared_ptr peer); +} diff --git a/controller/include/teststr_trim.h b/controller/include/teststr_trim.h new file mode 100644 index 00000000..48f58d2b --- /dev/null +++ b/controller/include/teststr_trim.h @@ -0,0 +1,12 @@ + +#pragma once +#include +#include +#include "httppeer.h" + +namespace http +{ + + + std::string teststrtrim(std::shared_ptr peer); +} diff --git a/controller/src/teststr_trim.cpp b/controller/src/teststr_trim.cpp new file mode 100755 index 00000000..25f93583 --- /dev/null +++ b/controller/src/teststr_trim.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include "httppeer.h" +#include "teststr_trim.h" +#include "func.h" +namespace http +{ +//@urlpath(null,teststr_trim) +std::string teststrtrim(std::shared_ptr peer) +{ + httppeer &client = peer->getpeer(); + std::string a = " 0123456789abcdefghij "; + client << "

strim|" << a << "|

"; + client << "

str_trim result|" << str_trim(a) << "|

"; + client << "

str_trim_view result|" << str_trim_view(a) << "|

"; + return ""; +} + +}// namespace http \ No newline at end of file diff --git a/vendor/httpserver/include/func.h b/vendor/httpserver/include/func.h index 876aca31..fa17086a 100755 --- a/vendor/httpserver/include/func.h +++ b/vendor/httpserver/include/func.h @@ -34,6 +34,7 @@ std::string html_encode(std::string_view); std::string strip_html(std::string_view); std::string strip_annot(std::string_view); std::string str_trim(std::string_view); +std::string_view str_trim_view(std::string_view); std::string mb_substr(std::string_view, int, int length = 0); unsigned int mb_strlen(std::string_view); std::map filepath(std::string &); diff --git a/vendor/httpserver/src/func.cpp b/vendor/httpserver/src/func.cpp index 1afc4afa..af79c3a8 100755 --- a/vendor/httpserver/src/func.cpp +++ b/vendor/httpserver/src/func.cpp @@ -1132,6 +1132,31 @@ std::string str_trim(std::string_view str) } return temp; } +std::string_view str_trim_view(std::string_view str) +{ + unsigned int tlen = str.size(); + for (; tlen > 0; tlen--) + { + unsigned int j = tlen - 1; + if (str[j] == 0x20 || str[j] == 0x09 || str[j] == 0x0A || str[j] == 0x0D) + { + continue; + } + break; + } + unsigned int i = 0; + for (; i < tlen; i++) + { + if (str[i] == 0x20 || str[i] == 0x09 || str[i] == 0x0A || str[i] == 0x0D) + { + continue; + } + break; + } + tlen = tlen - i; + return std::string_view(str.substr(i, tlen)); +} + std::string html_encode(std::string_view str) { std::string temp;