浏览代码

* Refactored, replaced case for if, nested if for and, removed needless
comparision
* Removed a Fillchar to clear the statetable, I don't see it's use

git-svn-id: trunk@16534 -

joost 14 年之前
父节点
当前提交
e6e02a6176
共有 1 个文件被更改,包括 18 次插入20 次删除
  1. 18 20
      packages/regexpr/src/regex.pp

+ 18 - 20
packages/regexpr/src/regex.pp

@@ -458,15 +458,17 @@ begin
   for i := 0 to FStateCount-1 do begin
   for i := 0 to FStateCount-1 do begin
     with FStateTable[i] do begin
     with FStateTable[i] do begin
       if (sdMatchType = mtClass) or
       if (sdMatchType = mtClass) or
-         (sdMatchType = mtNegClass) then
-        if (sdClass <> nil) then
+         (sdMatchType = mtNegClass) and
+         (sdClass <> nil) then
         begin
         begin
           for j := i+1 to FStateCount-1 do
           for j := i+1 to FStateCount-1 do
            if (FStateTable[j].sdClass = sdClass) then
            if (FStateTable[j].sdClass = sdClass) then
              FStateTable[j].sdClass := nil;
              FStateTable[j].sdClass := nil;
           FreeMem(sdClass, sizeof(TCharSet));
           FreeMem(sdClass, sizeof(TCharSet));
         end;
         end;
-      FillChar(FStateTable[i],SizeOf(FStateTable[i]),#0);
+      // I am not sure if the next line is necessary. rcAddState set all values, so
+      // it shouldn't be necessary to clear its contents?
+      // FillChar(FStateTable[i],SizeOf(FStateTable[i]),#0);
     end;
     end;
   end;
   end;
   {clear the state transition table}
   {clear the state transition table}
@@ -742,22 +744,19 @@ begin
       end;
       end;
     '\' :
     '\' :
       begin
       begin
-        case (FPosn+1)^ of
-          'd','D','s','S','w','W':
-            begin
-              New(CharClass);
-              CharClass^ := [];
-              if not rcParseCharRange(CharClass) then begin
-                Dispose(CharClass);
-                Result := ErrorState;
-                Exit;
-              end;
-              Result := rcAddState(mtClass, #0, CharClass,
+        if (FPosn+1)^ in ['d','D','s','S','w','W'] then begin
+          New(CharClass);
+          CharClass^ := [];
+          if not rcParseCharRange(CharClass) then begin
+            Dispose(CharClass);
+            Result := ErrorState;
+            Exit;
+          end;
+          Result := rcAddState(mtClass, #0, CharClass,
                                NewFinalState, UnusedState);
                                NewFinalState, UnusedState);
-            end;
-          else
-            Result := rcParseChar;
-        end;
+        end
+        else
+          Result := rcParseChar;
       end;
       end;
   else
   else
     {otherwise parse a single character}
     {otherwise parse a single character}
@@ -816,8 +815,7 @@ begin
     begin
     begin
     inc(FPosn);
     inc(FPosn);
     ch := rcReturnEscapeChar;
     ch := rcReturnEscapeChar;
-      if (FRegexType <> rtRegEx) then
-        FRegexType := rtRegEx;
+    FRegexType := rtRegEx;
     end
     end
   else
   else
     ch :=FPosn^;
     ch :=FPosn^;