Browse Source

LibRegex: Partially implement string compare for Utf32View

Ali Mohammad Pur 4 years ago
parent
commit
052004f92d
1 changed files with 16 additions and 2 deletions
  1. 16 2
      Userland/Libraries/LibRegex/RegexByteCode.cpp

+ 16 - 2
Userland/Libraries/LibRegex/RegexByteCode.cpp

@@ -529,6 +529,11 @@ ALWAYS_INLINE void OpCode_Compare::compare_char(const MatchInput& input, MatchSt
 
 
 ALWAYS_INLINE bool OpCode_Compare::compare_string(const MatchInput& input, MatchState& state, const char* str, size_t length, bool& had_zero_length_match)
 ALWAYS_INLINE bool OpCode_Compare::compare_string(const MatchInput& input, MatchState& state, const char* str, size_t length, bool& had_zero_length_match)
 {
 {
+    if (length == 0) {
+        had_zero_length_match = true;
+        return true;
+    }
+
     if (input.view.is_u8_view()) {
     if (input.view.is_u8_view()) {
         auto str_view1 = StringView(str, length);
         auto str_view1 = StringView(str, length);
         auto str_view2 = StringView(&input.view.u8view()[state.string_position], length);
         auto str_view2 = StringView(&input.view.u8view()[state.string_position], length);
@@ -541,8 +546,17 @@ ALWAYS_INLINE bool OpCode_Compare::compare_string(const MatchInput& input, Match
 
 
         if (string_equals) {
         if (string_equals) {
             state.string_position += length;
             state.string_position += length;
-            if (length == 0)
-                had_zero_length_match = true;
+            return true;
+        }
+    } else {
+        bool equals;
+        if (input.regex_options & AllFlags::Insensitive)
+            TODO();
+        else
+            equals = __builtin_memcmp(str, &input.view.u32view().code_points()[state.string_position], length) == 0;
+
+        if (equals) {
+            state.string_position += length;
             return true;
             return true;
         }
         }
     }
     }