Use splitString in trantor (#413)

Co-authored-by: antao <antao2002@gmail.com>
This commit is contained in:
ihmc3jn09hk 2020-04-18 11:13:53 +08:00 committed by GitHub
parent 17b8c337f9
commit 269acbc477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 27 deletions

View File

@ -27,6 +27,7 @@ set(INSTALL_DROGON_CMAKE_DIR
CACHE PATH "Installation directory for cmake files")
if(BUILD_DROGON_SHARED)
set(BUILD_TRANTOR_SHARED TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}" isSystemDir)

View File

@ -15,6 +15,7 @@
#pragma once
#include <trantor/utils/Date.h>
#include <trantor/utils/Funcs.h>
#include <drogon/utils/string_view.h>
#include <memory>
#include <string>
@ -45,8 +46,18 @@ std::string hexToBinaryString(const char *ptr, size_t length);
std::vector<char> hexToBinaryVector(const char *ptr, size_t length);
/// Split the string into multiple separated strings.
std::vector<std::string> splitString(const std::string &str,
const std::string &separator);
/**
* @param acceptEmptyString if true, empty strings are accepted in the
* result, for example, splitting the ",1,2,,3," by "," produces
* ["","1","2","","3",""]
*/
inline std::vector<std::string> splitString(const std::string &str,
const std::string &separator,
bool acceptEmptyString = false)
{
return trantor::splitString(str, separator, acceptEmptyString);
}
std::set<std::string> splitStringToSet(const std::string &str,
const std::string &separator);

View File

@ -248,30 +248,6 @@ std::string binaryStringToHex(const unsigned char *ptr, size_t length)
}
return idString;
}
std::vector<std::string> splitString(const std::string &str,
const std::string &separator)
{
std::vector<std::string> ret;
std::string::size_type pos1, pos2;
pos2 = 0;
pos1 = str.find(separator);
while (pos1 != std::string::npos)
{
if (pos1 != 0)
{
std::string item = str.substr(pos2, pos1 - pos2);
ret.push_back(item);
}
pos2 = pos1 + separator.length();
while (pos2 < str.length() &&
str.substr(pos2, separator.length()) == separator)
pos2 += separator.length();
pos1 = str.find(separator, pos2);
}
if (pos2 < str.length())
ret.push_back(str.substr(pos2));
return ret;
}
std::set<std::string> splitStringToSet(const std::string &str,
const std::string &separator)

@ -1 +1 @@
Subproject commit 82a61062acc94fca3114ff0d764f9961c2ae23aa
Subproject commit a2878af4320eff14bd815e3b6b2fdf84fbc19ab1