Closed MaxClerkwell closed 6 months ago
How about Eighth and Tenth characters? This works but there also might be improvements to it. If it's not what you wanted, let me know please, and I will try another way or making it better.
static char buf[18];
auto vinFilter = [](ImGuiInputTextCallbackData* data) -> int
{
const std::regex first_to_four("[A-HJ-NPR-Z]");
const std::regex fifth_to_seventh("[A-HJ-NPR-Z0-9]");
const std::regex eighth_to_tenth("[0-9]");
const std::regex eleventh_to_seventeenth("[A-HJ-NPR-Z0-9]");
std::string s;
s += data->EventChar;
size_t indx = strlen(buf) + 1;
if (indx >= 1 && indx <= 4)
return !std::regex_match(s, first_to_four);
else if (indx >= 5 && indx <= 7)
return !std::regex_match(s, fifth_to_seventh);
else if (indx >= 8 && indx <= 10)
return !std::regex_match(s, eighth_to_tenth);
else if (indx >= 11 && indx <= 17)
return !std::regex_match(s, eleventh_to_seventeenth);
};
ImGui::InputTextWithHint("VIN", "Enter VIN", buf, IM_ARRAYSIZE(buf),
ImGuiInputTextFlags_CharsUppercase |
ImGuiInputTextFlags_CharsNoBlank |
ImGuiInputTextFlags_CallbackCharFilter,
vinFilter
);
This looks like an exact solution to the challenge! Is clearly readable and should do the job.
I looked into the definition of a VIN once more and saw, that in other countries than germany, any part of the vin can have numbers and letters, so i'd only has to match: [A-HJ-NPR-Z0-9]
My initial input was to restrictive. Please implement in feature-branch and merge into master!
This has been implemented in the current version v0.9.0 and can be closed.
Pull-Request #59 provides neat improvements for the VIN input when generating training-data. Anyhow, there are only a few legal characters when it comes to the input of VINs.
I, O and Q, as well as all special characters here is a list of legal characters for all 17-chars of the VIN as regex: First to fourth character:
[A-HJ-NPR-Z]
Fifth to seventh character:[A-HJ-NPR-Z0-9]
Ninth character:[0-9]
Eleventh to seventeenth character:[A-HJ-NPR-Z0-9]
Wen a character is typed, a sort of a "filter" between
stdin
and the actual buffer should check, what character was entered and whether it is illegal.Expected Behavior: If the VIN-input of
is at each given place a legal character, the char shall be displayed on the screen in the text-edit-box. If an illegal character is typed, the char shall be dropped and not be displayed at all, as if nothing had happened.