1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include "simdutf.h"
#include <cstdlib>
#include <cstdio>
#include <string>
int main() {
// This is just a demonstration, not actual testing required.
std::string source = "La vie est belle.";
std::string chosen_implementation;
for (auto &implementation : simdutf::get_available_implementations()) {
if (!implementation->supported_by_runtime_system()) {
continue;
}
bool validutf8 =
implementation->validate_utf8(source.c_str(), source.size());
if (!validutf8) {
return EXIT_FAILURE;
}
printf("%s: %s\n", implementation->name().c_str(),
implementation->description().c_str());
chosen_implementation = implementation->name();
}
auto my_implementation =
simdutf::get_available_implementations()[chosen_implementation];
if (!my_implementation) {
return EXIT_FAILURE;
}
if (!my_implementation->supported_by_runtime_system()) {
return EXIT_FAILURE;
}
simdutf::get_active_implementation() = my_implementation;
bool validutf8 = simdutf::validate_utf8(source.c_str(), source.size());
if (!validutf8) {
return EXIT_FAILURE;
}
if (simdutf::get_active_implementation()->name() != chosen_implementation) {
return EXIT_FAILURE;
}
printf("Manually selected: %s\n",
simdutf::get_active_implementation()->name().c_str());
return EXIT_SUCCESS;
}
|