fix: fix issues.
- add chars format argument for floating point overload of ParserHelper::TryParse. - add overload for ParserHelper::Parse to match with ParserHelper::TryParse. - fix the issue that we can not specify c++ standard in command line when configuring project. - update documentation for changes. - change following function's argument from const yycc_char8_t* to const yycc_u8string_view&. - StringHelper::Split, StringHelper::SplitView - StringHelper::Lower, StringHelper::Upper - StringHelper::Join - StringHelper::Replace - use iterator type, not std::vector<yycc_u8string> for specialized StringHelper::Join to have more wide usage.
This commit is contained in:
		@ -15,7 +15,7 @@ Functions located in this helper support the convertion between string and follo
 | 
			
		||||
 | 
			
		||||
Please note in C++, \c bool is integral type but we list it individually because parser will treat it specially.
 | 
			
		||||
For \c bool type, parser will try doing convertion between it and \c "true" \c "false" string.
 | 
			
		||||
(\b case-sensitive. It means that \c true will only be converted to \c "true" and \c "TRUE" can not be recognised.)
 | 
			
		||||
(\b case-insensitive. It means that \c true can be converted from \c "true", \c "True" or \c "TRUE".)
 | 
			
		||||
 | 
			
		||||
\section parser_helper__try_parse Try Parse
 | 
			
		||||
 | 
			
		||||
@ -31,6 +31,7 @@ YYCC::ParserHelper::TryParse<uint32_t>(YYCC_U8("123"), val);
 | 
			
		||||
YYCC::ParserHelper::TryParse<uint32_t>(YYCC_U8("7fff"), val, 16);
 | 
			
		||||
\endcode
 | 
			
		||||
 | 
			
		||||
For floating point type, this function allows caller to specify extra argument providing the format of given number string (\c std::chars_format).
 | 
			
		||||
For integral type, this function allows caller to specify extra argument providing the base of given number string.
 | 
			
		||||
 | 
			
		||||
\section parser_helper__parse Parse
 | 
			
		||||
@ -45,8 +46,8 @@ There is an example:
 | 
			
		||||
uint32_t val = YYCC::ParserHelper::Parse<uint32_t>(YYCC_U8("123"));
 | 
			
		||||
\endcode
 | 
			
		||||
 | 
			
		||||
Please note, for integral types, there is no base argument in #Parse.
 | 
			
		||||
Please use #TryParse instead.
 | 
			
		||||
For integral and floating point value, 
 | 
			
		||||
it has same extra argument with #TryParse to provide more number infomation.
 | 
			
		||||
 | 
			
		||||
Using this function is dangerous if the validation of your input is important.
 | 
			
		||||
In this case, please use #TryParse instead.
 | 
			
		||||
@ -63,6 +64,11 @@ There is an example:
 | 
			
		||||
auto result = YYCC::ParserHelper::ToString<uint32_t>(UINT32_C(114));
 | 
			
		||||
\endcode
 | 
			
		||||
 | 
			
		||||
For floating point type, this function allows caller to specify extra arguments
 | 
			
		||||
which provides the format (\c std::chars_format) and precision when getting string representation.
 | 
			
		||||
For integral type, this function allows caller to specify extra argument
 | 
			
		||||
providing the base of number when getting string representation.
 | 
			
		||||
 | 
			
		||||
\section parser_helper__notes Notes
 | 
			
		||||
 | 
			
		||||
All functions within this helper are implementated by standard library functions.
 | 
			
		||||
 | 
			
		||||
@ -38,8 +38,8 @@ and second overload will return empty string when formatter failed.
 | 
			
		||||
YYCC::StringHelper provide 2 functions for programmer do string replacement:
 | 
			
		||||
 | 
			
		||||
\code
 | 
			
		||||
void Replace(yycc_u8string&, const yycc_char8_t*, const yycc_char8_t*);
 | 
			
		||||
yycc_u8string Replace(const yycc_char8_t*, const yycc_char8_t*, const yycc_char8_t*);
 | 
			
		||||
void Replace(yycc_u8string&, const yycc_u8string_view&, const yycc_u8string_view&);
 | 
			
		||||
yycc_u8string Replace(const yycc_u8string_view&, const yycc_u8string_view&, const yycc_u8string_view&);
 | 
			
		||||
\endcode
 | 
			
		||||
 | 
			
		||||
The first overload will do replacement in given string container directly.
 | 
			
		||||
@ -47,9 +47,9 @@ The second overload will produce a copy of original string and do replacement on
 | 
			
		||||
 | 
			
		||||
#Replace has special treatments for following scenarios:
 | 
			
		||||
 | 
			
		||||
\li If given string is empty or nullptr, the return value will be empty.
 | 
			
		||||
\li If the character sequence to be replaced is nullptr or empty string, no replacement will happen.
 | 
			
		||||
\li If the character sequence will be replaced into string is nullptr or empty, it will simply delete found character sequence from given string.
 | 
			
		||||
\li If given string is empty, the return value will be empty.
 | 
			
		||||
\li If the character sequence to be replaced is empty string, no replacement will happen.
 | 
			
		||||
\li If the character sequence will be replaced into string is or empty, it will simply delete found character sequence from given string.
 | 
			
		||||
 | 
			
		||||
\section string_helper__join Join
 | 
			
		||||
 | 
			
		||||
@ -95,10 +95,18 @@ auto joined_string = YYCC::StringHelper::Join(
 | 
			
		||||
\subsection string_helper__join__specialized Specialized Join Function
 | 
			
		||||
 | 
			
		||||
Despite universal join function, 
 | 
			
		||||
YYCC::StringHelper also provide some specialized join functions for commonly used types.
 | 
			
		||||
Current we support following join function:
 | 
			
		||||
YYCC::StringHelper also provide a specialized join functions for standard library container.
 | 
			
		||||
For example, the code written above can be written in following code by using this specialized overload.
 | 
			
		||||
The first two argument is just the begin and end iterator.
 | 
			
		||||
However, you must make sure that we can dereference it and then implicitly convert it to yycc_u8string_view.
 | 
			
		||||
Otherwise this overload will throw template error.
 | 
			
		||||
 | 
			
		||||
\li \c std::vector<yycc_u8string>: With an extra option which allow join it with reversed order.
 | 
			
		||||
\code
 | 
			
		||||
std::vector<yycc_u8string> data {
 | 
			
		||||
    YYCC_U8(""), YYCC_U8("1"), YYCC_U8("2"), YYCC_U8("")
 | 
			
		||||
};
 | 
			
		||||
auto joined_string = YYCC::StringHelper::Join(data.begin(), data.end(), decilmer);
 | 
			
		||||
\endcode
 | 
			
		||||
 | 
			
		||||
\section string_helper__lower_upper Lower Upper
 | 
			
		||||
 | 
			
		||||
@ -106,11 +114,11 @@ String helper provides Python-like string lower and upper function.
 | 
			
		||||
Both lower and upper function have 2 overloads:
 | 
			
		||||
 | 
			
		||||
\code
 | 
			
		||||
yycc_u8string Lower(const yycc_char8_t*);
 | 
			
		||||
yycc_u8string Lower(const yycc_u8string_view&);
 | 
			
		||||
void Lower(yycc_u8string&);
 | 
			
		||||
\endcode
 | 
			
		||||
 | 
			
		||||
First overload accepts a NULL-terminated string as argument and return a \b copy whose content are all the lower case of original string.
 | 
			
		||||
First overload accepts a string view as argument and return a \b copy whose content are all the lower case of original string.
 | 
			
		||||
Second overload accepts a mutable string container as argument and will make all characters stored in it become their lower case.
 | 
			
		||||
You can choose on of them for your flavor and requirements.
 | 
			
		||||
Upper also has similar 2 overloads.
 | 
			
		||||
@ -121,19 +129,19 @@ String helper provides Python-like string split function.
 | 
			
		||||
It has 2 types for you:
 | 
			
		||||
 | 
			
		||||
\code
 | 
			
		||||
std::vector<yycc_u8string> Split(const yycc_u8string_view&, const yycc_char8_t*);
 | 
			
		||||
std::vector<yycc_u8string_view> SplitView(const yycc_u8string_view&, const yycc_char8_t*);
 | 
			
		||||
std::vector<yycc_u8string> Split(const yycc_u8string_view&, const yycc_u8string_view&);
 | 
			
		||||
std::vector<yycc_u8string_view> SplitView(const yycc_u8string_view&, const yycc_u8string_view&);
 | 
			
		||||
\endcode
 | 
			
		||||
 | 
			
		||||
All these overloads take a string view as the first argument representing the string need to be split.
 | 
			
		||||
The second argument is a raw string pointer representing the decilmer for splitting.
 | 
			
		||||
The second argument is a string view representing the decilmer for splitting.
 | 
			
		||||
The only difference between these 2 split function are overt according to their names.
 | 
			
		||||
The first split function will return a list of copied string as its split result.
 | 
			
		||||
The second split function will return a list of string view as its split result,
 | 
			
		||||
and it will keep valid as long as the life time of your given string view argument.
 | 
			
		||||
It also means that the last overload will cost less memory if you don't need the copy of original string.
 | 
			
		||||
 | 
			
		||||
If the source string (the string need to be split) is empty, or the decilmer is \c nullptr or empty,
 | 
			
		||||
If the source string (the string need to be split) is empty, or the decilmer is empty,
 | 
			
		||||
the result will only has 1 item and this item is source string itself.
 | 
			
		||||
There is no way that these methods return an empty list, except the code is buggy.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user