Skip to content

Commit

Permalink
change func utility
Browse files Browse the repository at this point in the history
  • Loading branch information
hggq committed Jan 3, 2024
1 parent 3c4cef5 commit 9d09178
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 18 deletions.
4 changes: 4 additions & 0 deletions common/autocontrolmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "testdownloadauth.h"
#include "testmodelfromjson.h"
#include "teststrip_html.h"
#include "teststr_join.h"
#include "testrand.h"
#include "testormcache.h"
#include "testsendmail.h"
Expand Down Expand Up @@ -77,6 +78,9 @@ namespace http
temp.regfun = teststrip_html;
methodcallback.emplace("teststrip_html",temp);
temp.pre = nullptr;
temp.regfun = teststrjoin;
methodcallback.emplace("teststr_join",temp);
temp.pre = nullptr;
temp.regfun = testrand;
methodcallback.emplace("testrand",temp);
temp.pre = nullptr;
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);
}
30 changes: 30 additions & 0 deletions controller/src/teststr_join.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <chrono>
#include <thread>
#include <vector>
#include <list>
#include "httppeer.h"
#include "teststr_join.h"
#include "func.h"
namespace http
{
//@urlpath(null,teststr_join)
std::string teststrjoin(std::shared_ptr<httppeer> peer)
{
httppeer &client = peer->getpeer();
std::vector<std::string> a;
a.push_back("aaaa");
a.push_back("bbbb");
a.push_back("cccc");
client << "<p>std::vector<std::string>:" << str_join(a, ',') << "</p>";

std::list<std::string> b;
b.push_back("aaaa");
b.push_back("bbbb");
b.push_back("cccc");
client << "<p>std::list<std::string>:" << str_join(b, ',') << "</p>";

client << "<p>std::list<std::string>:" << str_join(b) << "</p>";
return "";
}

}// namespace http
Binary file modified docs/images/2c2ehello.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/2c2gdb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 26 additions & 9 deletions vendor/httpserver/include/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ bool str_lastcmp(std::string_view str1, std::string_view str2, unsigned int leng
bool str_caselastcmp(std::string_view str1, std::string_view str2, unsigned int length);
void get_filename(const std::string &filename, std::string &filename_name, std::string &filename_ext);
std::string get_filename(const std::string &filename);
std::vector<std::string> mb_split(const std::string, std::string &);
std::string html_encode(std::string &);
std::string strip_html(const std::string &);
std::string strip_annot(const std::string &);
std::string mb_trim(std::string &);
std::string mb_substr(std::string &, int, int length = 0);
int mb_strlen(std::string &);
std::vector<std::string> mb_split(std::string_view, std::string_view);
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 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 &);
struct stat filestat(std::string &);

Expand All @@ -47,6 +47,23 @@ std::string str2safemethold(const char *source, unsigned int str_length);

std::string numstr_to_sql(const char *source, unsigned int str_length, char b = ',');

template <typename _Tp>
std::string str_join(const _Tp &source, char b = 0x00)
{
std::stringstream _stream;
unsigned int j = 0;
for (typename _Tp::const_iterator iter = source.begin(); iter != source.end(); iter++)
{
if (j > 0 && b != 0x00)
{
_stream << b;
}
_stream << *iter;
j++;
}
return _stream.str();
}

template <typename _Tp>
requires std::is_integral_v<_Tp>
std::vector<_Tp> numstr_to_vector(const char *source, unsigned int str_length, char b = ',')
Expand All @@ -56,7 +73,7 @@ std::vector<_Tp> numstr_to_vector(const char *source, unsigned int str_length, c

for (unsigned int i = 0; i < str_length; i++)
{
if (source[i] == '-' || (source[i] > 0x2F && source[i] < 0x3A))
if (source[i] == '-' || source[i] == '.' || (source[i] > 0x2F && source[i] < 0x3A))
{
tempstr.push_back(source[i]);
}
Expand Down Expand Up @@ -91,7 +108,7 @@ std::vector<_Tp> numstr_to_vector(const char *source, unsigned int str_length, c

for (unsigned int i = 0; i < str_length; i++)
{
if (source[i] == '-' || (source[i] > 0x2F && source[i] < 0x3A))
if (source[i] == '-' || source[i] == '.' || (source[i] > 0x2F && source[i] < 0x3A))
{
tempstr.push_back(source[i]);
}
Expand Down
19 changes: 10 additions & 9 deletions vendor/httpserver/src/func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ std::string get_filename(const std::string &filename)
std::reverse(filename_name.begin(), filename_name.end());
return filename_name;
}
std::vector<std::string> mb_split(std::string pattern, std::string &msg)
std::vector<std::string> mb_split(std::string_view pattern, std::string_view msg)
{
std::vector<std::string> temp;

Expand Down Expand Up @@ -323,9 +323,9 @@ std::vector<std::string> mb_split(std::string pattern, std::string &msg)
}
return temp;
}
int mb_strlen(std::string &str)
unsigned int mb_strlen(std::string_view str)
{
int length = 0;
unsigned int length = 0;
unsigned long long pos = 0;
unsigned char c;
for (; pos < str.size(); pos++)
Expand Down Expand Up @@ -361,7 +361,7 @@ int mb_strlen(std::string &str)
}
return length;
}
std::string mb_substr(std::string &str, int begin, int length)
std::string mb_substr(std::string_view str, int begin, int length)
{
std::string temp;
int strlength = 0;
Expand Down Expand Up @@ -1104,13 +1104,14 @@ std::map<std::string, std::string> filepath(std::string &str)
}
return temp;
}
std::string mb_trim(std::string &str)
std::string str_trim(std::string_view str)
{
std::string temp;
unsigned int tlen = str.size();
for (; tlen > 0; tlen--)
{
if (str[tlen - 1] == 0x20 || str[tlen - 1] == 0x09 || str[tlen - 1] == 0x0A || str[tlen - 1] == 0x0D)
unsigned int j = tlen - 1;
if (str[j] == 0x20 || str[j] == 0x09 || str[j] == 0x0A || str[j] == 0x0D)
{
continue;
}
Expand All @@ -1131,7 +1132,7 @@ std::string mb_trim(std::string &str)
}
return temp;
}
std::string html_encode(std::string &str)
std::string html_encode(std::string_view str)
{
std::string temp;
for (unsigned int i = 0; i < str.size(); i++)
Expand Down Expand Up @@ -1325,7 +1326,7 @@ std::string json_addslash(const std::string &content)
return temp;
}

std::string strip_html(const std::string &content)
std::string strip_html(std::string_view content)
{
std::string temp;
std::string tempstr;
Expand Down Expand Up @@ -1611,7 +1612,7 @@ std::string strip_html(const std::string &content)

return temp;
}
std::string strip_annot(const std::string &content)
std::string strip_annot(std::string_view content)
{
std::string temp;
for (unsigned int i = 0; i < content.size(); i++)
Expand Down

0 comments on commit 9d09178

Please sign in to comment.