Skip to content

Commit

Permalink
add str_trim_view
Browse files Browse the repository at this point in the history
  • Loading branch information
hggq committed Jan 3, 2024
1 parent 01ddaae commit 3e3bf69
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/autocontrolmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions controller/include/teststr_join的副本.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#pragma once
#include <chrono>
#include <thread>
#include "httppeer.h"

namespace http
{


std::string teststrjoin(std::shared_ptr<httppeer> peer);
}
12 changes: 12 additions & 0 deletions controller/include/teststr_trim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#pragma once
#include <chrono>
#include <thread>
#include "httppeer.h"

namespace http
{


std::string teststrtrim(std::shared_ptr<httppeer> peer);
}
21 changes: 21 additions & 0 deletions controller/src/teststr_trim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <chrono>
#include <thread>
#include <vector>
#include <list>
#include "httppeer.h"
#include "teststr_trim.h"
#include "func.h"
namespace http
{
//@urlpath(null,teststr_trim)
std::string teststrtrim(std::shared_ptr<httppeer> peer)
{
httppeer &client = peer->getpeer();
std::string a = " 0123456789abcdefghij ";
client << "<p>strim|" << a << "|</p>";
client << "<p>str_trim result|" << str_trim(a) << "|</p>";
client << "<p>str_trim_view result|" << str_trim_view(a) << "|</p>";
return "";
}

}// namespace http
1 change: 1 addition & 0 deletions vendor/httpserver/include/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> filepath(std::string &);
Expand Down
25 changes: 25 additions & 0 deletions vendor/httpserver/src/func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3e3bf69

Please sign in to comment.