fix case testing

main
Clyne 3 days ago
parent c229a83121
commit b5ec681780
Signed by: clyne
GPG Key ID: 7BA5A2980566A649

@ -67,12 +67,7 @@ bool parse_stream(auto &fth, std::istream& str, bool say_okay)
while (str.good()) {
std::getline(str, line);
if (!line.empty()) {
for (auto& ch : line) {
if (ch >= 'a' && ch <= 'z')
ch = ch - 'a' + 'A';
}
if (line == "BYE")
if (sforth::isequal(line, "bye"))
return true;
try {

@ -31,7 +31,7 @@ struct native_word : public word_base
func body;
constexpr const func *get_ct(std::string_view name) const {
if (name == std::string_view{namebuf.data()})
if (isequal(name, std::string_view{namebuf.data()}))
return &body;
else if constexpr (Prev != nullptr)
return Prev->get_ct(name);

@ -51,6 +51,26 @@ using daddr = __uint128;
struct word_base;
constexpr bool isequal(std::string_view a, std::string_view b)
{
if (a.size() != b.size())
return false;
for (unsigned i = 0; i < a.size(); i++) {
auto ac = a[i];
if (ac >= 'A' && ac <= 'Z')
ac += 32;
auto bc = b[i];
if (bc >= 'A' && bc <= 'Z')
bc += 32;
if (ac != bc)
return false;
}
return true;
}
template<typename T>
constexpr std::optional<T> from_chars(std::string_view sv, int base = 10)
{
@ -132,7 +152,7 @@ struct word_base : public word_list
std::optional<const word_base *> word_list::get(std::string_view sv) const
{
for (auto lt = next; lt; lt = lt->next) {
if (sv == lt->name())
if (isequal(sv, lt->name()))
return lt;
}

Loading…
Cancel
Save