Browse Source

tweak size functions

KngStr 3 years ago
parent
commit
3242660b51
1 changed files with 10 additions and 5 deletions
  1. 10 5
      Source/ksString.pas

+ 10 - 5
Source/ksString.pas

@@ -237,13 +237,14 @@ const
   Units: array [0 .. 6] of Char = ('b', 'k', 'm', 'g', 't', 'p', 'e');
 var
   I: Integer;
+  LUnit: Char;
 begin
   Result := 1;
-
+  LUnit := LowerCase(AUnit);
   for I := Low(Units) to High(Units) do begin
     if (I > 0) then
       Result := Result * 1024;
-    if AUnit = Units[I] then
+    if LUnit = Units[I] then
       Exit;
   end;
 
@@ -278,13 +279,16 @@ begin
   p := PChar(ASize);
   while p^ <> #0 do
     case p^ of
-      'b', 'k', 'm', 'g', 't', 'p', 'e':
+      'b', 'k', 'm', 'g', 't', 'p', 'e',
+      'B', 'K', 'M', 'G', 'T', 'P', 'E':
         begin
+          if s = '' then
+            Exit;
           if c <> #0 then
             Exit;
           c := p^;
           Inc(p);
-          if p^ = 'b' then
+          if (p^ = 'b') or (p^ = 'B') then
             Inc(p);
         end;
       '0' .. '9':
@@ -306,7 +310,8 @@ begin
       Exit;
     end;
 
-  Result := StrToUInt64Def(s, Result) * SizeUnitToInt(c);
+  if s <> '' then
+    Result := StrToUInt64Def(s, Result) * SizeUnitToInt(c);
 end;
 
 end.