Browse Source

sysutils: added function DeQuoteString

mattias 6 years ago
parent
commit
8e84c3d709
2 changed files with 29 additions and 23 deletions
  1. 0 20
      packages/rtl/classes.pas
  2. 29 3
      packages/rtl/sysutils.pas

+ 0 - 20
packages/rtl/classes.pas

@@ -1541,26 +1541,6 @@ end;
 
 
 { //!! is used to mark unsupported things. }
 { //!! is used to mark unsupported things. }
 
 
-(*
-Function QuoteString (Const S : String; Const Quote : String) : String;
-Var
-  I,J : Integer;
-begin
-  J:=0;
-  Result:=S;
-  for i:=1 to length(s) do
-   begin
-     inc(j);
-     if S[i]=Quote then
-      begin
-        Insert(Quote,Result,J);
-        inc(j);
-      end;
-   end;
-  Result:=Quote+Result+Quote;
-end;
-*)
-
 {
 {
   For compatibility we can't add a Constructor to TSTrings to initialize
   For compatibility we can't add a Constructor to TSTrings to initialize
   the special characters. Therefore we add a routine which is called whenever
   the special characters. Therefore we add a routine which is called whenever

+ 29 - 3
packages/rtl/sysutils.pas

@@ -208,9 +208,10 @@ Type
   TStringReplaceFlags = set of TStringReplaceFlag;
   TStringReplaceFlags = set of TStringReplaceFlag;
   TReplaceFlags = TStringReplaceFlags;
   TReplaceFlags = TStringReplaceFlags;
 
 
-function StringReplace(aOriginal, aSearch, aReplace : string; Flags : TStringReplaceFlags) : String;
-function QuoteString(aOriginal : String; AQuote : Char) : String;
-function QuotedStr(const s: string; QuoteChar : Char = ''''): string;
+function StringReplace(aOriginal, aSearch, aReplace: string; Flags: TStringReplaceFlags): String;
+function QuoteString(aOriginal: String; AQuote: Char): String;
+function QuotedStr(const s: string; QuoteChar: Char = ''''): string;
+function DeQuoteString(aQuoted: String; AQuote: Char): String;
 function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
 function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
 function AdjustLineBreaks(const S: string): string;
 function AdjustLineBreaks(const S: string): string;
 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle): string;
 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle): string;
@@ -2083,6 +2084,31 @@ begin
   Result:=QuoteString(S,QuoteChar);
   Result:=QuoteString(S,QuoteChar);
 end;
 end;
 
 
+function DeQuoteString(aQuoted: String; AQuote: Char): String;
+var
+  i: Integer;
+begin
+  Result:=aQuoted;
+  if TJSString(Result).substr(0,1)<>AQuote then exit;
+  Result:=TJSString(Result).slice(1);
+  i:=1;
+  while i<=length(Result) do
+    begin
+    if Result[i]=AQuote then
+      begin
+      if (i=length(Result)) or (Result[i+1]<>AQuote) then
+        begin
+        Result:=TJSString(Result).slice(0,i-1);
+        exit;
+        end
+      else
+        Result:=TJSString(Result).slice(0,i-1)+TJSString(Result).slice(i);
+      end
+    else
+      inc(i);
+    end;
+end;
+
 function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
 function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
 begin
 begin
   Result:=False;
   Result:=False;