mimic++ v4
|
Contains symbols for generic string processing. More...
Topics | |
is_character | |
Type-trait, which determines, whether the given type is a character-type. | |
string_case_fold_converter | |
Type-trait, which provides the case-folding algorithm for the char-type, they are specialized for. | |
string_literal_prefix | |
Yields the printable prefix for any char-type. | |
string_traits | |
Type-trait, which contains properties for the provided string type. | |
Concepts | |
concept | mimicpp::string |
Determines, whether the given type can be used as a string-type. | |
concept | mimicpp::case_foldable_string |
Determines, whether the given type supports string normalization. | |
Contains symbols for generic string processing.
There are plenty of different character-types and even more string-types out there. They mostly differ in their details, but in general some common operations shall be applied (like equality- or prefix-tests). Therefore, mimic++
offers various abstractions, which users can utilize to make their char- and string-types compatible with the framework, and thus with all string-matchers.
Custom strings, which do use any of the common char-types (char
, wchar_t
, char16_t
, etc.), can be made compatible in no time. Users do just have to provide a specialization for the string_traits
template: Given the following string-type, which in fact is just an abstraction around a std::string
:
To make it compatible with mimic++
, just that simple specialization is necessary:
formattable
.It is possible to make custom char-types (and strings which use those) compatible with mimic++
, but this requires quite some effort, depending on the features you are planning to use.
Given the following (regular
) char-type
and this string type:
At first, we have to tell mimic++
, that my_char
is an actual char-type. This can be done by specializing the is_character
-trait.
Next, the string_traits
must be specialized:
After that, the string can be used with any string matcher, but just with case-sensitive matching:
The current setup is already enough, that these strings can be printed. Unfortunately this will print the whole string just as comma separated hex-values, because mimic++
doesn't know yet, how to print the underlying char-type. This can easily be fixed by proving a custom::Printer
specialization for that particular char-type.
mimic++
prints all strings with a literal prefix. This depends on the underlying char-type and can be customized by adding a specialization to string_literal_prefix for any user char-type.As stated in the string-matcher section, case-insensitive-matching requires some sort of case-folding. For ascii
-like strings a common strategy is to simply convert all characters to upper-case before the actual comparison. For wide-chars and Unicode this is definitely more complex, if it shall be done correctly. Nevertheless, users can provide their own strategy how to perform the case-folding by simply specializing the string_case_fold_converter
trait. For the my_char
from above, this may look like follows:
This is then enough to make all strings with underlying type of my_char
compatible with case-insensitive string-matchers: