Explorar el Código

* datetotime-def functions (but not yet FormatSettings) + ansidequotedstr (turned
out to be extractquotestr wrapper).

git-svn-id: trunk@5032 -

marco hace 19 años
padre
commit
304be38ec1

+ 19 - 1
rtl/objpas/sysutils/dati.inc

@@ -768,7 +768,7 @@ begin
 end;
 {$endif unix}
 
-
+// ieuw. These should  be written to work without exceptions?
 function TryStrToDate(const S: string; out Value: TDateTime): Boolean;
   begin
     result:=true;
@@ -814,3 +814,21 @@ function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
 // function TryStrToDateTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
 
 
+function StrToDateDef(const S: string; const Defvalue : TDateTime): TDateTime;
+begin
+  if not TryStrToDate(s,Result) Then
+    result:=defvalue;
+end;
+
+function StrToTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
+begin
+  if not TryStrToTime(s,Result) Then
+    result:=defvalue;
+end;
+
+function StrToDateTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
+begin
+  if not TryStrToDateTime(s,Result) Then
+    result:=defvalue;
+end;
+

+ 8 - 2
rtl/objpas/sysutils/datih.inc

@@ -124,11 +124,17 @@ procedure DateTimeToString(out Result: string; const FormatStr: string; const Da
 Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
 Function FileDateToDateTime (Filedate : Longint) :TDateTime;
 function TryStrToDate(const S: string; out Value: TDateTime): Boolean;
-// function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
 function TryStrToTime(const S: string; out Value: TDateTime): Boolean;
-// function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
 function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
+
+// function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+// function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
 // function TryStrToDateTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+
+function StrToDateDef(const S: string; const Defvalue : TDateTime): TDateTime;
+function StrToTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
+function StrToDateTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
+
 function CurrentYear:Word;
 { FPC Extra }
 Procedure GetLocalTime(var SystemTime: TSystemTime);

+ 11 - 0
rtl/objpas/sysutils/sysstr.inc

@@ -1336,6 +1336,17 @@ begin
   Result:=FloatToStrF(Value,ffNumber,15,2);
 end;
 
+function AnsiDequotedStr(const S: string; AQuote: Char): string; 
+
+var p : pchar;
+
+begin
+  p:=pchar(s); // work around CONST
+  result:=AnsiExtractquotedStr(p,AQuote);
+  if result='' Then
+    result:=s;
+end;
+
 function StrToCurr(const S: string): Currency;
 begin
   if not TextToFloat(PChar(S), Result, fvCurrency) then

+ 1 - 0
rtl/objpas/sysutils/sysstrh.inc

@@ -94,6 +94,7 @@ function TrimLeft(const S: string): string;
 function TrimRight(const S: string): string;
 function QuotedStr(const S: string): string;
 function AnsiQuotedStr(const S: string; Quote: char): string;
+function AnsiDequotedStr(const S: string; AQuote: Char): string; 
 function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
 function AdjustLineBreaks(const S: string): string;
 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle): string;