123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- {
- *********************************************************************
- $Id$
- Copyright (C) 1997, 1998 Gertjan Schouten
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *********************************************************************
- System Utilities For Free Pascal
- }
- {==============================================================================}
- { standard functions }
- {==============================================================================}
- type
- PString = ^String;
- { For FloatToText }
- TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
- TFloatValue = (fvExtended, fvCurrency, fvSingle, fvReal, fvDouble, fvComp);
- TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
- TFloatRec = Record
- Exponent: Integer;
- Negative: Boolean;
- Digits: Array[0..18] Of Char;
- End;
- const
- { For floattodatetime }
- MinDateTime: TDateTime = -657434.0; { 01/01/0100 12:00:00.000 AM }
- MaxDateTime: TDateTime = 2958465.99999; { 12/31/9999 11:59:59.999 PM }
- {$ifndef VER1_0}
- {$if defined(FPC_HAS_TYPE_EXTENDED) or defined(FPC_HAS_TYPE_FLOAT128)}
- MinCurrency: Currency = -922337203685477.5807;
- MaxCurrency: Currency = 922337203685477.5807;
- {$else}
- MinCurrency: Currency = -922337203685477.0000;
- MaxCurrency: Currency = 922337203685477.0000;
- {$endif}
- {$endif VER1_0}
- Type
- TTextLineBreakStyle = (tlbsLF, tlbsCRLF,tlbsCR); // Must move to system unit, and add Mac tlbsCR too ?
- Const
- DefaultTextLineBreakStyle: TTextLineBreakStyle =
- {$ifdef unix} tlbsLF {$else} {$ifdef macos} tlbsCR {$else} tlbsCRLF {$endif} {$endif} ;
- Const
- LeadBytes: set of Char = [];
- EmptyStr : string = '';
- NullStr : PString = @EmptyStr;
- {$IFDEF VIRTUALPASCAL}
- EmptyWideStr : AnsiString = '';
- NullWideStr : PString = @EmptyWideStr;
- {$ELSE}
- EmptyWideStr : WideString = '';
- // NullWideStr : PWideString = @EmptyWideStr;
- {$ENDIF}
- function NewStr(const S: string): PString;
- procedure DisposeStr(S: PString);
- procedure AssignStr(var P: PString; const S: string);
- procedure AppendStr(var Dest: String; const S: string);
- function UpperCase(const s: string): string;
- function LowerCase(const s: string): string; overload;
- function CompareStr(const S1, S2: string): Integer;
- function CompareMemRange(P1, P2: Pointer; Length: cardinal): integer;
- function CompareMem(P1, P2: Pointer; Length: cardinal): Boolean;
- function CompareText(const S1, S2: string): integer;
- function SameText(const s1,s2:String):Boolean;
- function AnsiUpperCase(const s: string): string;
- function AnsiLowerCase(const s: string): string;
- function AnsiCompareStr(const S1, S2: string): integer;
- function AnsiCompareText(const S1, S2: string): integer;
- function AnsiSameText(const s1,s2:String):Boolean;
- function AnsiSameStr(const s1,s2:String):Boolean;
- function AnsiStrComp(S1, S2: PChar): integer;
- function AnsiStrIComp(S1, S2: PChar): integer;
- function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;
- function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;
- function AnsiStrLower(Str: PChar): PChar;
- function AnsiStrUpper(Str: PChar): PChar;
- function AnsiLastChar(const S: string): PChar;
- function AnsiStrLastChar(Str: PChar): PChar;
- function Trim(const S: string): string;
- 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 AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
- function AdjustLineBreaks(const S: string): string;
- function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle): string;
- function IsValidIdent(const Ident: string): boolean;
- function IntToStr(Value: integer): string;
- {$IFNDEF VIRTUALPASCAL}
- function IntToStr(Value: Int64): string;
- {$ENDIF}
- function IntToStr(Value: QWord): string;
- function IntToHex(Value: integer; Digits: integer): string;
- function IntToHex(Value: Int64; Digits: integer): string;
- function StrToInt(const s: string): integer;
- function TryStrToInt(const s: string; var i : integer) : boolean;
- {$IFNDEF VIRTUALPASCAL}
- function StrToInt64(const s: string): int64;
- function TryStrToInt64(const s: string; var i : int64) : boolean;
- {$ENDIF}
- function StrToIntDef(const S: string; Default: integer): integer;
- {$IFNDEF VIRTUALPASCAL}
- function StrToInt64Def(const S: string; Default: int64): int64;
- {$ENDIF}
- function LoadStr(Ident: integer): string;
- // function FmtLoadStr(Ident: integer; const Args: array of const): string;
- Function Format (Const Fmt : String; const Args : Array of const) : String;
- Function FormatBuf (Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardinal; Const Args : Array of const) : Cardinal;
- Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
- Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args: Array of const) : Pchar;
- Procedure FmtStr(Var Res: String; Const Fmt : String; Const args: Array of const);
- Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
- Function FloatToStr(Value: Extended): String;
- Function StrToFloat(Const S : String) : Extended;
- Function StrToFloatDef(Const S: String; Const Default: Extended): Extended;
- Function TryStrToFloat(Const S : String; Var Value: Single): Boolean;
- Function TryStrToFloat(Const S : String; Var Value: Double): Boolean;
- {$ifdef FPC_HAS_TYPE_EXTENDED}
- Function TryStrToFloat(Const S : String; Var Value: Extended): Boolean;
- {$endif FPC_HAS_TYPE_EXTENDED}
- Function TextToFloat(Buffer: PChar; Var Value: Extended): Boolean;
- Function TextToFloat(Buffer: PChar; Var Value; ValueType: TFloatValue): Boolean;
- Function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer): Longint;
- Function FloatToDateTime (Const Value : Extended) : TDateTime;
- Function FloattoCurr (Const Value : Extended) : Currency;
- function TryFloatToCurr(const Value: Extended; var AResult: Currency): Boolean;
- Function CurrToStr(Value: Currency): string;
- function StrToCurr(const S: string): Currency;
- function StrToCurrDef(const S: string; Default : Currency): Currency;
- function StrToBool(const S: string): Boolean;
- function BoolToStr(B: Boolean): string;
- function LastDelimiter(const Delimiters, S: string): Integer;
- function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
- Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
- Procedure FloatToDecimal(Var Result: TFloatRec; Value: Extended; Precision, Decimals : integer);
- Function FormatFloat(Const Format : String; Value : Extended) : String;
- Function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
- {// MBCS Functions. No MBCS yet, so mostly these are calls to the regular counterparts.}
- Type
- TMbcsByteType = (mbSingleByte, mbLeadByte, mbTrailByte);
- Function ByteType(const S: string; Index: Integer): TMbcsByteType;
- Function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType;
- Function ByteToCharLen(const S: string; MaxLen: Integer): Integer;
- Function CharToByteLen(const S: string; MaxLen: Integer): Integer;
- Function ByteToCharIndex(const S: string; Index: Integer): Integer;
- const
- {$ifndef unix}
- SwitchChars = ['/','-'];
- {$else}
- SwitchChars = ['-'];
- {$endif}
- Type
- TSysCharSet = Set of char;
- Function FindCmdLineSwitch(const Switch: string; const Chars: TSysCharSet;IgnoreCase: Boolean): Boolean;
- Function FindCmdLineSwitch(const Switch: string; IgnoreCase: Boolean): Boolean;
- Function FindCmdLineSwitch(const Switch: string): Boolean;
- function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet; MaxCol: Integer): string;
- function WrapText(const Line: string; MaxCol: Integer): string;
- {==============================================================================}
- { extra functions }
- {==============================================================================}
- function LeftStr(const S: string; Count: integer): string;
- function RightStr(const S: string; Count: integer): string;
- function BCDToInt(Value: integer): integer;
- {
- $Log$
- Revision 1.13 2005-01-17 18:38:48 peter
- * extended overload disabled for powerpc
- Revision 1.12 2005/01/16 17:53:27 michael
- + Patch from Colin Western to implemenet TryStrToFLoat
- Revision 1.11 2004/12/19 17:55:38 michael
- + Implemented wraptext
- Revision 1.10 2004/11/16 18:30:36 marco
- * updated ansiexctractquotedstring (more delphi compat, both interface and code)
- Revision 1.9 2004/08/30 13:07:03 michael
- + Added MACOS linebreakstyle (tlbsCR)
- Revision 1.8 2004/08/07 16:56:28 florian
- + TryStrToInt* added
- Revision 1.7 2004/06/20 20:42:37 florian
- * fixed bootstrapping problems
- Revision 1.6 2004/06/13 10:49:50 florian
- * fixed some bootstrapping problems as well as some 64 bit stuff
- Revision 1.5 2004/06/12 13:23:17 michael
- + Fixed currency<->string conversion support
- Revision 1.4 2004/02/26 08:46:21 michael
- + Added AnsiSameStr
- Revision 1.3 2003/11/26 22:17:42 michael
- + Merged fixbranch fixes, missing in main branch
- Revision 1.2 2003/10/07 12:02:47 marco
- * sametext and ansisametext added. (simple (ansi)comparetext wrappers)
- Revision 1.1 2003/10/06 21:01:06 peter
- * moved classes unit to rtl
- Revision 1.17 2003/09/06 21:22:08 marco
- * More objpas fixes
- Revision 1.16 2002/12/24 23:33:37 peter
- * export StrToFloatDef
- Revision 1.15 2002/12/23 23:12:34 florian
- + TextToFloat: D6 compatibility added
- Revision 1.14 2002/11/28 22:26:30 michael
- + Fixed float<>string conversion routines
- Revision 1.13 2002/11/28 20:29:26 michael
- + made it compile again
- Revision 1.12 2002/09/07 16:01:22 peter
- * old logs removed and tabs fixed
- Revision 1.1.2.6 2002/11/28 22:25:01 michael
- + Fixed float<>string conversion routines
- Revision 1.1.2.5 2002/11/28 20:24:12 michael
- + merged some fixes from mainbranch
- Revision 1.1.2.4 2002/10/29 23:41:06 michael
- + Added lots of D4 functions
- Revision 1.11 2002/01/24 18:33:58 peter
- * overload for lowercase()
- Revision 1.10 2002/01/24 12:33:54 jonas
- * adapted ranges of native types to int64 (e.g. high cardinal is no
- longer longint($ffffffff), but just $fffffff in psystem)
- * small additional fix in 64bit rangecheck code generation for 32 bit
- processors
- * adaption of ranges required the matching talgorithm used for selecting
- which overloaded procedure to call to be adapted. It should now always
- select the closest match for ordinal parameters.
- + inttostr(qword) in sysstr.inc/sysstrh.inc
- + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
- fixes were required to be able to add them)
- * is_in_limit() moved from ncal to types unit, should always be used
- instead of direct comparisons of low/high values of orddefs because
- qword is a special case
- }
|