feat: finish console input.

- finish console input function. add test for it.
- add Replace function in string helper.
This commit is contained in:
2024-06-10 17:55:23 +08:00
parent 1e990b74ae
commit 629a608133
4 changed files with 195 additions and 21 deletions

View File

@ -7,19 +7,22 @@
#include <vector>
namespace YYCC::StringHelper {
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);
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);
/**
* @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.
*/
using JoinDataProvider = std::function<const char*()>;
using JoinDataProvider = std::function<const char* ()>;
/**
* @brief General Join function.
* @details This function use function pointer as a general data provider interface,
@ -31,24 +34,24 @@ namespace YYCC::StringHelper {
std::string Join(JoinDataProvider fct_data, const char* decilmer);
/**
* @brief Specialized Join function for common used container.
* @param data
* @param decilmer
* @param reversed
* @return
* @param data
* @param decilmer
* @param reversed
* @return
*/
std::string Join(const std::vector<std::string>& data, const char* decilmer, bool reversed = false);
/**
* @brief Transform string to lower.
* @param strl
* @return
* @param strl
* @return
*/
std::string Lower(const char* strl);
void Lower(std::string& strl);
/**
* @brief Transform string to upper.
* @param strl
* @return
* @param strl
* @return
*/
std::string Upper(const char* strl);
void Upper(std::string& strl);
@ -59,7 +62,7 @@ namespace YYCC::StringHelper {
* 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.
* @return
* @return
* @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.