2024-04-25 10:38:13 +08:00
|
|
|
#pragma once
|
2024-05-28 19:59:41 +08:00
|
|
|
#include "YYCCInternal.hpp"
|
|
|
|
|
2024-04-25 10:38:13 +08:00
|
|
|
#include <string>
|
|
|
|
#include <cstdarg>
|
2024-05-21 10:24:05 +08:00
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
2024-04-25 10:38:13 +08:00
|
|
|
|
|
|
|
namespace YYCC::StringHelper {
|
2024-06-10 17:55:23 +08:00
|
|
|
|
2024-04-25 10:38:13 +08:00
|
|
|
bool Printf(std::string& strl, const char* format, ...);
|
|
|
|
bool VPrintf(std::string& strl, const char* format, va_list argptr);
|
|
|
|
|
|
|
|
std::string Printf(const char* format, ...);
|
|
|
|
std::string VPrintf(const char* format, va_list argptr);
|
|
|
|
|
2024-06-10 17:55:23 +08:00
|
|
|
void Replace(std::string& strl, const char* _from_strl, const char* _to_strl);
|
|
|
|
std::string Replace(const char* _strl, const char* _from_strl, const char* _to_strl);
|
|
|
|
|
2024-05-21 10:24:05 +08:00
|
|
|
/**
|
|
|
|
* @brief The data provider of general Join function.
|
|
|
|
* This function pointer return non-null string pointer to represent a element of joined series.
|
|
|
|
* otherwise return nullptr to terminate the joining process.
|
|
|
|
*/
|
2024-06-10 17:55:23 +08:00
|
|
|
using JoinDataProvider = std::function<const char* ()>;
|
2024-05-21 10:24:05 +08:00
|
|
|
/**
|
|
|
|
* @brief General Join function.
|
|
|
|
* @details This function use function pointer as a general data provider interface,
|
|
|
|
* so this function suit for all types container, the user only need write a little bit adaption code.
|
|
|
|
* @param fct_data[in] The function pointer to data provider.
|
|
|
|
* @param decilmer[in] The decilmer.
|
|
|
|
* @return A std::string instance which containing the join result.
|
|
|
|
*/
|
|
|
|
std::string Join(JoinDataProvider fct_data, const char* decilmer);
|
|
|
|
/**
|
|
|
|
* @brief Specialized Join function for common used container.
|
2024-06-10 17:55:23 +08:00
|
|
|
* @param data
|
|
|
|
* @param decilmer
|
|
|
|
* @param reversed
|
|
|
|
* @return
|
2024-05-21 10:24:05 +08:00
|
|
|
*/
|
|
|
|
std::string Join(const std::vector<std::string>& data, const char* decilmer, bool reversed = false);
|
2024-04-26 15:37:28 +08:00
|
|
|
|
2024-05-21 10:24:05 +08:00
|
|
|
/**
|
|
|
|
* @brief Transform string to lower.
|
2024-06-10 17:55:23 +08:00
|
|
|
* @param strl
|
|
|
|
* @return
|
2024-05-21 10:24:05 +08:00
|
|
|
*/
|
|
|
|
std::string Lower(const char* strl);
|
|
|
|
void Lower(std::string& strl);
|
|
|
|
/**
|
|
|
|
* @brief Transform string to upper.
|
2024-06-10 17:55:23 +08:00
|
|
|
* @param strl
|
|
|
|
* @return
|
2024-05-21 10:24:05 +08:00
|
|
|
*/
|
|
|
|
std::string Upper(const char* strl);
|
|
|
|
void Upper(std::string& strl);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief General Split function.
|
2024-05-22 13:42:43 +08:00
|
|
|
* @param _strl[in] The string need to be splitting.
|
|
|
|
* If this is nullptr, the result will be empty.
|
|
|
|
* @param _decilmer[in] The decilmer for splitting.
|
|
|
|
* If decilmer is nullptr or zero length, the result will only have 1 element which is original string.
|
2024-06-10 17:55:23 +08:00
|
|
|
* @return
|
2024-05-21 10:24:05 +08:00
|
|
|
* @remarks This function may be low performance because it just a homebrew Split functon.
|
|
|
|
* It can works in most toy cases but not suit for high performance scenario.
|
|
|
|
* Also, this function will produce a copy of original string because it is not zero copy.
|
|
|
|
*/
|
|
|
|
std::vector<std::string> Split(const char* _strl, const char* _decilmer);
|
2024-04-25 10:38:13 +08:00
|
|
|
}
|