Procházet zdrojové kódy

change StrParamxxx to be 0-base

KngStr před 3 roky
rodič
revize
b5477df5c6
1 změnil soubory, kde provedl 7 přidání a 5 odebrání
  1. 7 5
      Source/ksString.pas

+ 7 - 5
Source/ksString.pas

@@ -80,7 +80,7 @@ function IsChineseMobileNumber(S: string; AOnlyNum: Boolean = False): Boolean;
 }
 
 /// <summary>
-/// 获取指定参数, one-base
+/// 获取指定参数, 0-base
 /// </summary>
 /// <remarks>
 /// 按命令行拆分方式
@@ -88,7 +88,7 @@ function IsChineseMobileNumber(S: string; AOnlyNum: Boolean = False): Boolean;
 function StrParamStr(Command: string; Index: Integer): string; overload;
 function StrParamStr(Command: PChar; Index: Integer): string; overload;
 /// <summary>
-/// 获取参数个数
+/// 获取参数个数, 包含第一个参数
 /// </summary>
 /// <remarks>
 /// 按命令行拆分方式
@@ -400,7 +400,7 @@ var
   Z: String;
 begin
   PCount := StrParamCount(Command);
-  for I := 1 to PCount do
+  for I := 0 to PCount - 1 do
   begin
     Z := StrParamStr(Command, I);
     if (StrLIComp(PChar(Z), PChar('/' + Param + '='), Length(Param) + 2) = 0)
@@ -425,11 +425,13 @@ var
   P: PChar;
   S: String;
 begin
-  P := GetStrParamStr(Command, S);
   Result := 0;
+  P := Command;
+  while (P^ <> #0) and (P^ <= ' ') do
+    Inc(P);
   while P^ <> #0 do begin
-    Inc(Result);
     P := GetStrParamStr(P, S);
+    Inc(Result);
   end;
 end;