]> code.bitgloo.com Git - clyne/sforth.git/commitdiff
fix case testing
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 19 Dec 2024 22:04:19 +0000 (17:04 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 19 Dec 2024 22:04:19 +0000 (17:04 -0500)
main.cpp
sforth/native_word.hpp
sforth/types.hpp

index be00744254085082030f1438989cfe7a4c4947bd..83c3a81a16c744193454d24c1c83c00566409bd4 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -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 {
index 5a98614ecbcf253e071787988f1a33269586e96d..a329a72d5eeaa075b647506d901fb052c472fee7 100644 (file)
@@ -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);
index 7950664049365929b0c27883d0e2db6e2cf68f51..3cb76ba872630d1ebe8828408edf548f08dda464 100644 (file)
@@ -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;
     }