Browse Source

--- Merging r14059 into '.':
U rtl/objpas/sysutils/sysuintf.inc
--- Merging r14060 into '.':
G rtl/objpas/sysutils/sysuintf.inc

# revisions: 14059,14060
------------------------------------------------------------------------
r14059 | ivost | 2009-11-05 00:02:32 +0100 (Thu, 05 Nov 2009) | 2 lines
Changed paths:
M /trunk/rtl/objpas/sysutils/sysuintf.inc

* fixed TryStringToGUID: this function throwed an exceptions

------------------------------------------------------------------------
------------------------------------------------------------------------
r14060 | ivost | 2009-11-05 00:04:30 +0100 (Thu, 05 Nov 2009) | 2 lines
Changed paths:
M /trunk/rtl/objpas/sysutils/sysuintf.inc

* removed commented code in TryStringToGUID

------------------------------------------------------------------------

git-svn-id: branches/fixes_2_4@14686 -

marco 15 years ago
parent
commit
a8ecebf996
1 changed files with 35 additions and 56 deletions
  1. 35 56
      rtl/objpas/sysutils/sysuintf.inc

+ 35 - 56
rtl/objpas/sysutils/sysuintf.inc

@@ -71,71 +71,50 @@ end;
 
 
 
 
 function TryStringToGUID(const S: string; out Guid: TGUID): Boolean;
 function TryStringToGUID(const S: string; out Guid: TGUID): Boolean;
+var
+  e: Boolean;
+  p: PChar;
 
 
-  function HexChar(c: Char): Byte;
+  function rb: Byte;
   begin
   begin
-    case c of
-      '0'..'9':
-        Result:=Byte(c) - Byte('0');
-      'a'..'f':
-        Result:=(Byte(c) - Byte('a')) + 10;
-      'A'..'F':
-        Result:=(Byte(c) - Byte('A')) + 10;
-      else
-        raise EConvertError.CreateFmt(SInvalidGUID, [s]);
-        Result:=0;
+    case p^ of
+      '0'..'9': Result := Byte(p^) - Byte('0');
+      'a'..'f': Result := Byte(p^) - Byte('a') + 10;
+      'A'..'F': Result := Byte(p^) - Byte('A') + 10;
+      else e := False;
     end;
     end;
+    Inc(p);
   end;
   end;
 
 
-  function HexByte(p: PChar): Byte;
+  procedure nextChar(c: Char); inline;
   begin
   begin
-    Result:=(HexChar(p[0]) shl 4) + HexChar(p[1]);
+    if p^ <> c then
+      e := False;
+    Inc(p);
   end;
   end;
 
 
-var
-  i: integer;
-  src: PChar;
-  dest: PByte;
 begin
 begin
-  if ((Length(S)<>38) or (s[1]<>'{')) then
-    Exit(False);
-  dest:=PByte(@Guid);
-  src:=PChar(s);
-  inc(src);
-  for i:=0 to 3 do
-    dest[i]:=HexByte(src+(3-i)*2);
-  inc(src, 8);
-  inc(dest, 4);
-  if src[0]<>'-' then
-    Exit(False);
-  inc(src);
-  for i:=0 to 1 do
-   begin
-     dest^:=HexByte(src+2);
-     inc(dest);
-     dest^:=HexByte(src);
-     inc(dest);
-     inc(src, 4);
-     if src[0]<>'-' then
-       Exit(False);
-     inc(src);
-   end;
-  dest^:=HexByte(src);
-  inc(dest);
-  inc(src, 2);
-  dest^:=HexByte(src);
-  inc(dest);
-  inc(src, 2);
-  if src[0]<>'-' then
-    Exit(False);
-  inc(src);
-  for i:=0 to 5 do
-   begin
-     dest^:=HexByte(src);
-     inc(dest);
-     inc(src, 2);
-   end;
-   Result := True;
+  if Length(S)<>38 then Exit(False);
+  e := True;
+  p := PChar(S);
+  nextChar('{');
+  Guid.D1 := rb shl 28 or rb shl 24 or rb shl 20 or rb shl 16 or rb shl 12 or rb shl 8 or rb shl 4 or rb;
+  nextChar('-');
+  Guid.D2 := rb shl 12 or rb shl 8 or rb shl 4 or rb;
+  nextChar('-');
+  Guid.D3 := rb shl 12 or rb shl 8 or rb shl 4 or rb;
+  nextChar('-');
+  Guid.D4[0] := rb shl 4 or rb;
+  Guid.D4[1] := rb shl 4 or rb;
+  nextChar('-');
+  Guid.D4[2] := rb shl 4 or rb;
+  Guid.D4[3] := rb shl 4 or rb;
+  Guid.D4[4] := rb shl 4 or rb;
+  Guid.D4[5] := rb shl 4 or rb;
+  Guid.D4[6] := rb shl 4 or rb;
+  Guid.D4[7] := rb shl 4 or rb;
+  nextChar('}');
+  Result := e;
 end;
 end;