Browse Source

* Synchronize API for AnsiString/Unicode string, keep string where possible.

Michael VAN CANNEYT 2 years ago
parent
commit
78374bf772

+ 4 - 1
rtl/amicommon/sysutils.pp

@@ -25,8 +25,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/atari/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 5 - 0
rtl/embedded/sysutils.pp

@@ -15,7 +15,12 @@
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
+
 unit sysutils;
 
 interface

+ 4 - 1
rtl/emx/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 0
rtl/freertos/sysutils.pp

@@ -15,7 +15,11 @@
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 unit sysutils;
 
 interface

+ 4 - 1
rtl/gba/sysutils.pp

@@ -26,8 +26,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 5 - 2
rtl/go32v2/sysutils.pp

@@ -20,9 +20,12 @@ unit sysutils;
 interface
 
 {$MODE objfpc}
-{$MODESWITCH out}
-{ force ansistrings }
+{$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 5 - 2
rtl/macos/sysutils.pp

@@ -21,9 +21,12 @@ unit sysutils;
 interface
 
 {$MODE objfpc}
-{$modeswitch out}
-{ force ansistrings }
+{$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 5 - 2
rtl/msdos/sysutils.pp

@@ -20,9 +20,12 @@ unit sysutils;
 interface
 
 {$MODE objfpc}
-{$MODESWITCH out}
-{ force ansistrings }
+{$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 {$hugecode on}

+ 4 - 1
rtl/nativent/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/nds/sysutils.pp

@@ -26,8 +26,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/netware/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/netwlibc/sysutils.pp

@@ -18,8 +18,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 136 - 100
rtl/objpas/sysutils/dati.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     *********************************************************************
     Copyright (C) 1997, 1998 Gertjan Schouten
@@ -371,15 +372,15 @@ end;
     if S does not represent a valid date value
     an EConvertError will be raised   }
 
-function IntStrToDate(Out ErrorMsg : AnsiString; const S: PAnsiChar; Len : integer; const useformat : string; const defs:TFormatSettings; separator : AnsiChar = #0): TDateTime;
+function IntStrToDate(Out ErrorMsg : String; const S: PChar; Len : integer; const useformat : string; const defs:TFormatSettings; separator : Char = #0): TDateTime;
 
 const SInvalidDateFormat = '"%s" is not a valid date format';
 
-procedure FixErrorMsg(const errm :ansistring;const errmarg : ansistring);
+  procedure FixErrorMsg(const errm :string;const errmarg : string);
 
-begin
-  errormsg:=format(errm,[errmarg]);
-end;
+  begin
+    errormsg:=format(errm,[errmarg]);
+  end;
 
 var
    df:string;
@@ -391,6 +392,7 @@ var
    values:array[0..3] of longint;
    LocalTime:tsystemtime;
    YearMoreThenTwoDigits : boolean;
+
 begin
   ErrorMsg:='';   Result:=0;
   While (Len>0) and (S[Len-1] in [' ',#8,#9,#10,#12,#13]) do
@@ -527,10 +529,10 @@ begin
     errormsg:='Invalid date';
 end;
 
-function StrToDate(const S: PAnsiChar; Len : integer; const useformat : string; separator : AnsiChar = #0): TDateTime;
+function StrToDate(const S: PChar; Len : integer; const useformat : string; separator : Char = #0): TDateTime;
 
 Var
-  MSg : AnsiString;
+  MSg : String;
 
 begin
   Result:=IntStrToDate(Msg,S,Len,useFormat,DefaultFormatSettings,Separator);
@@ -540,44 +542,52 @@ end;
 
 function StrToDate(const S: string; FormatSettings: TFormatSettings): TDateTime;
 var
-  Msg: AnsiString;
+  Msg: String;
 begin
-  Result:=IntStrToDate(Msg,PAnsiChar(S),Length(S),FormatSettings.ShortDateFormat,FormatSettings);
+  Result:=IntStrToDate(Msg,PChar(S),Length(S),FormatSettings.ShortDateFormat,FormatSettings);
   if Msg<>'' then
     raise EConvertError.Create(Msg);
 end;
 
-function StrToDate(const S: ShortString; const useformat : string; separator : AnsiChar = #0): TDateTime;
+function StrToDate(const S: ShortString; const useformat : string; separator : Char = #0): TDateTime;
+
+Var
+  SS : String;
+
 begin
-  // S[1] always exists for shortstring. Length 0 will trigger an error.
-  result := StrToDate(@S[1],Length(s),UseFormat,separator);
+  SS:=S;
+  result := StrToDate(@SS[1],Length(SS),UseFormat,separator);
 end;
 
-function StrToDate(const S: AnsiString; const useformat : string; separator : AnsiChar = #0): TDateTime;
+function StrToDate(const S: String; const useformat : string; separator : Char = #0): TDateTime;
 begin
-  result := StrToDate(PAnsiChar(S),Length(s),UseFormat,separator);
+  result := StrToDate(PChar(S),Length(s),UseFormat,separator);
 end;
 
-function StrToDate(const S: ShortString; separator : AnsiChar): TDateTime;
+function StrToDate(const S: ShortString; separator : Char): TDateTime;
 begin
-  // S[1] always exists for shortstring. Length 0 will trigger an error.
-  result := StrToDate(@S[1],Length(s),DefaultFormatSettings.ShortDateFormat,separator)
+  result:=StrToDate(S,DefaultFormatSettings.ShortDateFormat,Separator)
 end;
 
 function StrToDate(const S: ShortString): TDateTime;
+
+Var
+  SS : String;
+
 begin
   // S[1] always exists for shortstring. Length 0 will trigger an error.
-  result := StrToDate(@S[1],Length(s),DefaultFormatSettings.ShortDateFormat,#0);
+  SS:=S;
+  result := StrToDate(@SS[1],Length(SS),DefaultFormatSettings.ShortDateFormat,#0);
 end;
 
-function StrToDate(const S: AnsiString; separator : AnsiChar): TDateTime;
+function StrToDate(const S: String; separator : Char): TDateTime;
 begin
-    result := StrToDate(PAnsiChar(S),Length(s),DefaultFormatSettings.ShortDateFormat,separator)
+  result := StrToDate(PChar(S),Length(s),DefaultFormatSettings.ShortDateFormat,separator)
 end;
 
-function StrToDate(const S: AnsiString): TDateTime;
+function StrToDate(const S: String): TDateTime;
 begin
-  result := StrToDate(PAnsiChar(S),Length(s),DefaultFormatSettings.ShortDateFormat,#0);
+  result := StrToDate(PChar(S),Length(s),DefaultFormatSettings.ShortDateFormat,#0);
 end;
 
 {   StrToTime converts the string S to a TDateTime value
@@ -585,7 +595,8 @@ end;
     EConvertError will be raised   }
 
 
-function IntStrToTime(Out ErrorMsg : AnsiString; const S: PAnsiChar; Len : integer;const defs:TFormatSettings; separator : AnsiChar = #0): TDateTime;
+function IntStrToTime(Out ErrorMsg : String; const S: PChar; Len : integer;const defs:TFormatSettings; separator : Char = #0): TDateTime;
+
 const
   AMPM_None = 0;
   AMPM_AM = 1;
@@ -600,13 +611,13 @@ var
    AmPm: integer;
    TimeValues: TTimeValues;
 
-    function StrPas(Src : PAnsiChar; len: integer = 0) : ShortString;
+    function StrPas(Src : PChar; len: integer = 0) : String;
     begin
         //this is unsafe for len > 255, it will trash memory (I tested this)
         //reducing it is safe, since whenever we use this a string > 255 is invalid anyway
         if len > 255 then len := 255;
         SetLength(Result, len);
-        move(src[0],result[1],len);
+        move(Src[0],Result[1],len*sizeOf(Char));
     end;
 
    function SplitElements(out TimeValues: TTimeValues; out AmPm: Integer): Boolean;
@@ -617,8 +628,8 @@ var
       Cur, Offset, ElemLen, Err, TimeIndex, FirstSignificantDigit: Integer;
       Value: Word;
       DigitPending, MSecPending: Boolean;
-      AmPmStr: ShortString;
-      CurChar: AnsiChar;
+      AmPmStr: String;
+      CurChar: Char;
    begin
      Result := False;
      AmPm := AMPM_None; //No Am or PM in string found yet
@@ -700,16 +711,21 @@ var
          ElemLen := 1 + Cur - OffSet;
          //writeln('  S[Offset] = ',S[Offset], ' S[Cur] = ',S[Cur],' ElemLen = ',ElemLen,' -> ', StrPas(S + Offset, ElemLen));
          //writeln('  Cur = ',Cur);
-         AmPmStr := StrPas(S + OffSet, ElemLen);
+         AmPmStr := StrPas(PChar(S + OffSet), ElemLen);
 
          //writeln('AmPmStr = ',ampmstr,' (',length(ampmstr),')');
          //We must compare to TimeAMString before hardcoded 'AM' for delphi compatibility
          //Also it is perfectly legal, though insane to have TimeAMString = 'PM' and vice versa
-         if (AnsiCompareText(AmPmStr, defs.TimeAMString) = 0) then AmPm := AMPM_AM
-         else if (AnsiCompareText(AmPmStr, defs.TimePMString) = 0) then AmPm := AMPM_PM
-         else if (CompareText(AmPmStr, 'AM') = 0) then AmPm := AMPM_AM
-         else if (CompareText(AmPmStr, 'PM') = 0) then AmPm := AMPM_PM
-         else Exit; //If text does not match any of these, timestring must be wrong;
+         if (AnsiCompareText(AmPmStr, defs.TimeAMString) = 0) then
+           AmPm := AMPM_AM
+         else if (AnsiCompareText(AmPmStr, defs.TimePMString) = 0) then
+           AmPm := AMPM_PM
+         else if (CompareText(AmPmStr, 'AM') = 0) then
+           AmPm := AMPM_AM
+         else if (CompareText(AmPmStr, 'PM') = 0) then
+           AmPm := AMPM_PM
+         else
+           Exit; //If text does not match any of these, timestring must be wrong;
          //if AM/PM is at beginning of string, then a digit is mandatory after it
          if (TimeIndex = tiHour) then
          begin
@@ -749,10 +765,10 @@ begin
     ErrorMsg:=Format(SErrInvalidTimeFormat,[StrPas(S, Len)]);
 end ;
 
-function StrToTime(const S: PAnsiChar; Len : integer; separator : AnsiChar = #0): TDateTime;
+function StrToTime(const S: PChar; Len : integer; separator : Char = #0): TDateTime;
 
 Var
-  Msg : AnsiString;
+  Msg : String;
 
 begin
   Result:=IntStrToTime(Msg,S,Len,DefaultFormatSettings,Separator);
@@ -762,40 +778,48 @@ end;
 
 function StrToTime(const S: string; FormatSettings : TFormatSettings): TDateTime;
 Var
-  Msg : AnsiString;
+  Msg : String;
 begin
-  Result:=IntStrToTime(Msg, PAnsiChar(S), length(S), FormatSettings, #0);
+  Result:=IntStrToTime(Msg, PChar(S), length(S), FormatSettings, #0);
   If (Msg<>'') then
     Raise EConvertError.Create(Msg);
 end;
 
-function StrToTime(const s: ShortString; separator : AnsiChar): TDateTime;
+function StrToTime(const s: ShortString; separator : Char): TDateTime;
+
+Var
+  SS : String;
+
 begin
-  // S[1] always exists for shortstring. Length 0 will trigger an error.
-  result := StrToTime(@s[1], length(s), separator);
+  SS:=S;
+  result := StrToTime(PChar(SS),length(SS), separator);
 end;
 
-function StrToTime(const s: AnsiString; separator : AnsiChar): TDateTime;
+function StrToTime(const s: String; separator : Char): TDateTime;
 begin
-   result := StrToTime(PAnsiChar(S), length(s), separator);
+  result := StrToTime(PChar(S), length(s), separator);
 end;
 
 function StrToTime(const s: ShortString): TDateTime;
+
+Var
+  SS : String;
+
 begin
-  // S[1] always exists for shortstring. Length 0 will trigger an error.
-   result := StrToTime(@s[1], length(s), #0);
+  SS:=S;
+  result := StrToTime(@SS[1], length(SS), #0);
 end;
 
-function StrToTime(const s: AnsiString): TDateTime;
+function StrToTime(const s: String): TDateTime;
 begin
-   result:= StrToTime(PAnsiChar(s), length(s), #0);
+  result:= StrToTime(PChar(s), length(s), #0);
 end;
 
 {   StrToDateTime converts the string S to a TDateTime value
     if S does not represent a valid date and/or time value
     an EConvertError will be raised   }
 
-function SplitDateTimeStr(DateTimeStr: AnsiString; const FS: TFormatSettings; out DateStr, TimeStr: AnsiString): Integer;
+function SplitDateTimeStr(DateTimeStr: String; const FS: TFormatSettings; out DateStr, TimeStr: String): Integer;
 
 { Helper function for StrToDateTime
   Pre-condition
@@ -870,9 +894,9 @@ begin
 end; 
 
 
-function StrToDateTime(const s: AnsiString; const FormatSettings : TFormatSettings): TDateTime;
+function StrToDateTime(const s: String; const FormatSettings : TFormatSettings): TDateTime;
 var
-  TimeStr, DateStr: AnsiString;
+  TimeStr, DateStr: String;
   PartsFound: Integer;
 begin
   PartsFound := SplitDateTimeStr(S, FormatSettings, DateStr, TimeStr);
@@ -887,7 +911,7 @@ begin
   end;
 end;
 
-function StrToDateTime(const s: AnsiString): TDateTime;
+function StrToDateTime(const s: String): TDateTime;
 begin
   Result:=StrToDateTime(S,DefaultFormatSettings);
 end;
@@ -895,7 +919,8 @@ end;
 function StrToDateTime(const s: ShortString; const FormatSettings : TFormatSettings): TDateTime;
 
 var
-  A : AnsiString;
+  A : String;
+
 begin
   A:=S;
   Result:=StrToDateTime(A,FormatSettings);
@@ -925,8 +950,8 @@ procedure DateTimeToString(out Result: string; const FormatStr: string; const Da
   const FormatSettings: TFormatSettings; Options : TFormatDateTimeOptions = []);
 var
   ResultLen: integer;
-  ResultBuffer: array[0..255] of AnsiChar;
-  ResultCurrent: PAnsiChar;
+  ResultBuffer: array[0..255] of Char;
+  ResultCurrent: PChar;
 {$if defined(win32) or defined(win64)}
   isEnable_E_Format : Boolean;
   isEnable_G_Format : Boolean;
@@ -964,13 +989,15 @@ var
   end;
 {$endif win32 or win64}
 
-  procedure StoreStr(Str: PAnsiChar; Len: Integer);
+
+  procedure StoreStr(Str: PChar; Len: Integer);
+
   begin
     if ResultLen + Len < SizeOf(ResultBuffer) then
     begin
-      StrMove(ResultCurrent, Str, Len);
-      ResultCurrent := ResultCurrent + Len;
-      ResultLen := ResultLen + Len;
+      StrMove(ResultCurrent, PChar(Str), Len);
+      Inc(ResultCurrent,Len);
+      Inc(ResultLen,Len);
     end;
   end;
 
@@ -978,17 +1005,17 @@ var
   var Len: integer;
   begin
    Len := Length(Str);
-   if ResultLen + Len < SizeOf(ResultBuffer) then
+   if ResultLen + Len < High(ResultBuffer) then
      begin
-       StrMove(ResultCurrent, PAnsiChar(Str), Len);
-       ResultCurrent := ResultCurrent + Len;
-       ResultLen := ResultLen + Len;
+       StrMove(ResultCurrent, PChar(Str), Len);
+       Inc(ResultCurrent,Len);
+       Inc(ResultLen,Len);
      end;
   end;
 
   procedure StoreInt(Value, Digits: Integer);
   var
-    S: string[16];
+    S: string;
     Len: integer;
   begin
     System.Str(Value:Digits, S);
@@ -999,7 +1026,7 @@ var
       else
         Break;
     end;
-    StoreStr(PAnsiChar(@S[1]), Length(S));
+    StoreStr(PChar(S), Length(S));
   end ;
 
 var
@@ -1015,12 +1042,12 @@ var
 
   procedure StoreFormat(const FormatStr: string; Nesting: Integer; TimeFlag: Boolean);
   var
-    Token, lastformattoken, prevlasttoken: AnsiChar;
-    FormatCurrent: PAnsiChar;
-    FormatEnd: PAnsiChar;
+    Token, lastformattoken, prevlasttoken: Char;
+    FormatCurrent: PChar;
+    FormatEnd: PChar;
     Count: integer;
     Clock12: boolean;
-    P: PAnsiChar;
+    P: PChar;
     tmp: integer;
     isInterval: Boolean;
 
@@ -1028,7 +1055,7 @@ var
     if Nesting > 1 then  // 0 is original string, 1 is included FormatString
       Exit;
 
-    FormatCurrent := PAnsiChar(FormatStr);
+    FormatCurrent := PChar(FormatStr);
     FormatEnd := FormatCurrent + Length(FormatStr);
     Clock12 := false;
     isInterval := false;
@@ -1251,13 +1278,14 @@ begin
   DecodeDateFully(DateTime, Year, Month, Day, DayOfWeek);
   DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
   ResultLen := 0;
+  FillChar(ResultBuffer,0,SizeOf(ResultBuffer));
   ResultCurrent := @ResultBuffer[0];
   if FormatStr <> '' then
     StoreFormat(FormatStr, 0, False)
   else
     StoreFormat('C', 0, False);
   ResultBuffer[ResultLen] := #0;
-  result := StrPas(@ResultBuffer[0]);
+  result := StrPas(@ResultBuffer);
   if (DateTime < 0) and (fdoInterval in Options) then
     result := '-' + result;
 end ;
@@ -1346,69 +1374,72 @@ begin
 end;
 
 function TryStrToDate(const S: ShortString; out Value: TDateTime;
-                    const useformat : string; separator : AnsiChar = #0): Boolean;
+                    const useformat : string; separator : Char = #0): Boolean;
 
 Var
-  Msg : Ansistring;
+  Msg,SS : String;
+
 
 begin
-  // S[1] always exists for shortstring. Length 0 will trigger an error.
-  Value:=IntStrToDate(Msg,@S[1],Length(S),useformat,defaultformatsettings,separator);
+  SS:=S;
+  Value:=IntStrToDate(Msg,PChar(SS),Length(SS),useformat,defaultformatsettings,separator);
   Result:=(Msg='');
 end;
 
-function TryStrToDate(const S: AnsiString; out Value: TDateTime;
-                    const useformat : string; separator : AnsiChar = #0): Boolean;
+function TryStrToDate(const S: String; out Value: TDateTime;
+                    const useformat : string; separator : Char = #0): Boolean;
 
 Var
-  Msg : Ansistring;
+  Msg : string;
 
 begin
   Result:=Length(S)<>0;
   If Result then
     begin
-    Value:=IntStrToDate(Msg,PAnsiChar(S),Length(S),useformat,DefaultFormatSettings,Separator);
+    Value:=IntStrToDate(Msg,PChar(S),Length(S),useformat,DefaultFormatSettings,Separator);
     Result:=(Msg='');
     end;
 end;
 
-function TryStrToDate(const S: ShortString; out Value: TDateTime; separator : AnsiChar): Boolean;
+function TryStrToDate(const S: ShortString; out Value: TDateTime; separator : Char): Boolean;
 begin
   Result:=TryStrToDate(S,Value,DefaultFormatSettings.ShortDateFormat,Separator);
 end;
 
 
-function TryStrToDate(const S: AnsiString; out Value: TDateTime): Boolean;
+function TryStrToDate(const S: String; out Value: TDateTime): Boolean;
 begin
   Result:=TryStrToDate(S,Value,DefaultFormatSettings.ShortDateFormat,#0);
 end;
 
-function TryStrToDate(const S: AnsiString; out Value: TDateTime; separator : AnsiChar): Boolean;
+function TryStrToDate(const S: String; out Value: TDateTime; separator : Char): Boolean;
 
 begin
   Result:=TryStrToDate(S,Value,DefaultFormatSettings.ShortDateFormat,Separator);
 end;
 
 function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
+
 Var
-  Msg : Ansistring;
+  Msg : string;
 
 begin
   Result:=Length(S)<>0;
   If Result then
     begin
-      Value:=IntStrToDate(Msg,PAnsiChar(S),Length(S),FormatSettings.ShortDateFormat,FormatSettings,#0);
+      Value:=IntStrToDate(Msg,PChar(S),Length(S),FormatSettings.ShortDateFormat,FormatSettings,#0);
       Result:=(Msg='');
     end;
 end;
 
-function TryStrToTime(const S: ShortString; out Value: TDateTime; separator : AnsiChar): Boolean;
+function TryStrToTime(const S: ShortString; out Value: TDateTime; separator : Char): Boolean;
 
 Var
-  Msg : AnsiString;
+  SS,Msg : String;
+
 begin
-  // S[1] always exists for shortstring. Length 0 will trigger an error.
-  Value:=IntStrToTime(Msg,@S[1],Length(S),DefaultFormatSettings,Separator);
+  SS:=S;
+  Value:=IntStrToTime(Msg,Pchar(SS),Length(SS),DefaultFormatSettings,Separator);
   result:=(Msg='');
 end;
 
@@ -1417,30 +1448,35 @@ begin
   Result := TryStrToTime(S,Value,#0);
 end;
 
-function TryStrToTime(const S: AnsiString; out Value: TDateTime; separator : AnsiChar): Boolean;
+function TryStrToTime(const S: String; out Value: TDateTime; separator : Char): Boolean;
+
 Var
-  Msg : AnsiString;
+  Msg : String;
+
 begin
   Result:=Length(S)<>0;
   If Result then
     begin
-      Value:=IntStrToTime(Msg,PAnsiChar(S),Length(S),DefaultFormatSettings,Separator);
+      Value:=IntStrToTime(Msg,PChar(S),Length(S),DefaultFormatSettings,Separator);
       Result:=(Msg='');
     end;
 end;
 
-function TryStrToTime(const S: AnsiString; out Value: TDateTime): Boolean;
+function TryStrToTime(const S: String; out Value: TDateTime): Boolean;
 begin
     result := TryStrToTime(S,Value,#0);
 end;
 
 function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
-Var msg : AnsiString;
+
+Var
+  Msg : String;
+
 begin
   Result:=Length(S)<>0;
   If Result then
     begin
-      Value:=IntStrToTime(Msg,PAnsiChar(S),Length(S),FormatSettings,#0);
+      Value:=IntStrToTime(Msg,PChar(S),Length(S),FormatSettings,#0);
       Result:=(Msg='');
     end;
 end;
@@ -1450,7 +1486,7 @@ function TryStrToDateTime(const S: ShortString; out Value: TDateTime): Boolean;
     result := TryStrToDateTime(S, Value, DefaultFormatSettings);
   end;
 
-function TryStrToDateTime(const S: AnsiString; out Value: TDateTime): Boolean;
+function TryStrToDateTime(const S: String; out Value: TDateTime): Boolean;
   begin
     result := TryStrToDateTime(S, Value, DefaultFormatSettings);
   end;
@@ -1497,7 +1533,7 @@ begin
   Result:=StrToDateTimeDef(S,DefValue,DefaultFormatSettings);
 end;
 
-function StrToDateTimeDef(const S: AnsiString; const Defvalue : TDateTime; const FormatSettings: TFormatSettings): TDateTime;
+function StrToDateTimeDef(const S: String; const Defvalue : TDateTime; const FormatSettings: TFormatSettings): TDateTime;
 begin
   if not TryStrToDateTime(s,Result,FormatSettings) Then
     result:=defvalue;
@@ -1515,29 +1551,29 @@ begin
     result:=defvalue;
 end;
 
-function StrToDateDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;
+function StrToDateDef(const S: String; const Defvalue : TDateTime): TDateTime;
 begin
    result := StrToDateDef(S,DefValue,#0);
 end;
 
-function StrToTimeDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;
+function StrToTimeDef(const S: String; const Defvalue : TDateTime): TDateTime;
 begin
    result := StrToTimeDef(S,DefValue,#0);
 end;
 
-function StrToDateTimeDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;
+function StrToDateTimeDef(const S:  String; const Defvalue : TDateTime): TDateTime;
 begin
   if not TryStrToDateTime(s,Result) Then
     result:=defvalue;
 end;
 
-function StrToDateDef(const S: AnsiString; const Defvalue : TDateTime; separator : AnsiChar): TDateTime;
+function StrToDateDef(const S: String; const Defvalue : TDateTime; separator : Char): TDateTime;
 begin
-  if not TryStrToDate(s,Result, separator) Then
+  if not TryStrToDate(S,Result, separator) Then
     result:=defvalue;
 end;
 
-function StrToTimeDef(const S: AnsiString; const Defvalue : TDateTime; separator : AnsiChar): TDateTime;
+function StrToTimeDef(const S: String; const Defvalue : TDateTime; separator : Char): TDateTime;
 begin
   if not TryStrToTime(s,Result, separator) Then
     result:=defvalue;

+ 30 - 31
rtl/objpas/sysutils/datih.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     *********************************************************************
     Copyright (C) 1997, 1998 Gertjan Schouten
@@ -139,22 +140,22 @@ function TimeToStr(Time: TDateTime; const FormatSettings: TFormatSettings): stri
 function DateTimeToStr(DateTime: TDateTime; ForceTimeIfZero : Boolean = False): string;
 function DateTimeToStr(DateTime: TDateTime; const FormatSettings: TFormatSettings; ForceTimeIfZero : Boolean = False): string;
 function StrToDate(const S: ShortString): TDateTime;                  {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDate(const S: Ansistring): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDate(const S: ShortString; separator : AnsiChar): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDate(const S: AnsiString; separator : AnsiChar): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDate(const S: string; FormatSettings : TFormatSettings): TDateTime;
+function StrToDate(const S: String): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDate(const S: ShortString; separator : Char): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDate(const S: String; separator : Char): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDate(const S: String; FormatSettings : TFormatSettings): TDateTime;
 function StrToTime(const S: Shortstring): TDateTime;                  {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToTime(const S: Ansistring): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToTime(const S: ShortString; separator : AnsiChar): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToTime(const S: AnsiString; separator : AnsiChar): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToTime(const S: string; FormatSettings : TFormatSettings): TDateTime;
-function StrToDate(const S: ShortString; const useformat : string; separator : AnsiChar = #0): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDate(const S: AnsiString; const useformat : string; separator : AnsiChar = #0): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToTime(const S: PAnsiChar; Len : integer; separator : AnsiChar = #0): TDateTime;
-function StrToDate(const S: PAnsiChar; Len : integer; const useformat : string; separator : AnsiChar = #0): TDateTime;
-function StrToDateTime(const S: AnsiString): TDateTime;
+function StrToTime(const S: String): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToTime(const S: ShortString; separator : Char): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToTime(const S: String; separator : Char): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToTime(const S: String; FormatSettings : TFormatSettings): TDateTime;
+function StrToDate(const S: ShortString; const useformat : string; separator : Char = #0): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDate(const S: String; const useformat : string; separator : Char = #0): TDateTime;{$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToTime(const S: PChar; Len : integer; separator : Char = #0): TDateTime;
+function StrToDate(const S: PChar; Len : integer; const useformat : string; separator : Char = #0): TDateTime;
+function StrToDateTime(const S: String): TDateTime;
 function StrToDateTime(const s: ShortString; const FormatSettings : TFormatSettings): TDateTime;
-function StrToDateTime(const s: AnsiString; const FormatSettings : TFormatSettings): TDateTime;
+function StrToDateTime(const s: String; const FormatSettings : TFormatSettings): TDateTime;
 function FormatDateTime(const FormatStr: string; DateTime: TDateTime; Options : TFormatDateTimeOptions = []): string;
 function FormatDateTime(const FormatStr: string; DateTime: TDateTime; const FormatSettings: TFormatSettings; Options : TFormatDateTimeOptions = []): string;
 procedure DateTimeToString(out Result: string; const FormatStr: string; const DateTime: TDateTime; Options : TFormatDateTimeOptions = []);
@@ -164,19 +165,17 @@ Function UniversalToFileDate(DateTime : TDateTime) : int64;
 Function FileDateToDateTime (Filedate : Int64) :TDateTime;
 Function FileDateToUniversal (Filedate : Int64) :TDateTime;
 function TryStrToDate(const S: ShortString; out Value: TDateTime): Boolean;                         {$ifdef SYSUTILSINLINE}inline;{$endif}
-function TryStrToDate(const S: AnsiString; out Value: TDateTime): Boolean;                         {$ifdef SYSUTILSINLINE}inline;{$endif}
-function TryStrToDate(const S: ShortString; out Value: TDateTime; separator : AnsiChar): Boolean;
-function TryStrToDate(const S: AnsiString; out Value: TDateTime; separator : AnsiChar): Boolean;
+function TryStrToDate(const S: String; out Value: TDateTime): Boolean;                         {$ifdef SYSUTILSINLINE}inline;{$endif}
+function TryStrToDate(const S: ShortString; out Value: TDateTime; separator : Char): Boolean;
+function TryStrToDate(const S: String; out Value: TDateTime; separator : Char): Boolean;
 function TryStrToTime(const S: ShortString; out Value: TDateTime): Boolean;                         {$ifdef SYSUTILSINLINE}inline;{$endif}
-function TryStrToTime(const S: AnsiString; out Value: TDateTime): Boolean;                         {$ifdef SYSUTILSINLINE}inline;{$endif}
-function TryStrToTime(const S: ShortString; out Value: TDateTime; separator : AnsiChar): Boolean;
-function TryStrToTime(const S: AnsiString; out Value: TDateTime; separator : AnsiChar): Boolean;
-function TryStrToDate(const S: ShortString; out Value: TDateTime;
-                        const useformat : string; separator : AnsiChar = #0): Boolean;
-function TryStrToDate(const S: AnsiString; out Value: TDateTime;
-                        const useformat : string; separator : AnsiChar = #0): Boolean;
+function TryStrToTime(const S: String; out Value: TDateTime): Boolean;                         {$ifdef SYSUTILSINLINE}inline;{$endif}
+function TryStrToTime(const S: ShortString; out Value: TDateTime; separator : Char): Boolean;
+function TryStrToTime(const S: String; out Value: TDateTime; separator : Char): Boolean;
+function TryStrToDate(const S: ShortString; out Value: TDateTime;  const useformat : string; separator : Char = #0): Boolean;
+function TryStrToDate(const S: String; out Value: TDateTime; const useformat : string; separator : Char = #0): Boolean;
 function TryStrToDateTime(const S: ShortString; out Value: TDateTime): Boolean;
-function TryStrToDateTime(const S: AnsiString; out Value: TDateTime): 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;
@@ -188,12 +187,12 @@ function StrToTimeDef(const S: ShortString; const Defvalue : TDateTime): TDateTi
 function StrToTimeDef(const S: ShortString; const Defvalue : TDateTime; separator : AnsiChar): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
 function StrToDateTimeDef(const S: ShortString; const Defvalue : TDateTime): TDateTime;               {$ifdef SYSUTILSINLINE}inline;{$endif}
 
-function StrToDateDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDateDef(const S: AnsiString; const Defvalue : TDateTime; separator : AnsiChar): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToTimeDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToTimeDef(const S: AnsiString; const Defvalue : TDateTime; separator : AnsiChar): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDateTimeDef(const S: AnsiString; const Defvalue : TDateTime): TDateTime;               {$ifdef SYSUTILSINLINE}inline;{$endif}
-function StrToDateTimeDef(const S: AnsiString; const Defvalue : TDateTime; const FormatSettings: TFormatSettings): TDateTime;               {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDateDef(const S: String; const Defvalue : TDateTime): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDateDef(const S: String; const Defvalue : TDateTime; separator : Char): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToTimeDef(const S: String; const Defvalue : TDateTime): TDateTime;                   {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToTimeDef(const S: String; const Defvalue : TDateTime; separator : Char): TDateTime; {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDateTimeDef(const S: String; const Defvalue : TDateTime): TDateTime;               {$ifdef SYSUTILSINLINE}inline;{$endif}
+function StrToDateTimeDef(const S: String; const Defvalue : TDateTime; const FormatSettings: TFormatSettings): TDateTime;               {$ifdef SYSUTILSINLINE}inline;{$endif}
 
 function CurrentYear:Word;
 { FPC Extra }

+ 2 - 1
rtl/objpas/sysutils/fmtflt.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 function IntFloatToTextFmt(Buf: FPChar; const Value; ValueType: TFloatValue; Format: FPChar; const AFormatSettings: TFormatSettings): Integer;
 
 Type
@@ -10,7 +11,7 @@ var
   // Input in usable format
   E : Extended;              // Value as extended.
   FV: TFloatRec;             // Value as floatrec.
-  Section : String;          // Format can contain 3 sections, semicolon separated: Pos;Neg;Zero. This is the one to use.
+  Section : FString;         // Format can contain 3 sections, semicolon separated: Pos;Neg;Zero. This is the one to use.
   SectionLength : Integer;   // Length of section.
   // Calculated based on section. Static during output
   ThousandSep: Boolean;      // Thousands separator detected in format ?

+ 2 - 1
rtl/objpas/sysutils/osutilsh.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     This file is part of the Free Pascal run time library.
     Copyright (c) 1999-2000 by Michael Van Canneyt
@@ -25,7 +26,7 @@ procedure CheckOSError(LastError: Integer);platform;{$ifdef SYSTEMINLINE}inline;
 
 Function GetEnvironmentVariable(Const EnvVar : AnsiString) : AnsiString; overload;
 Function GetEnvironmentVariable(Const EnvVar : UnicodeString) : UnicodeString; overload;
-Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
+Function GetEnvironmentString(Index : Integer) : RTLString;
 Function GetEnvironmentVariableCount : Integer;
 {$IFDEF HAS_SLEEP}
 procedure Sleep(milliseconds: Cardinal);

+ 8 - 7
rtl/objpas/sysutils/sysencoding.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     *********************************************************************
     Copyright (C) 2012 Paul Ishenin,
@@ -35,7 +36,7 @@ begin
   Result := FStandardEncodings[seAnsi];
 end;
 
-function TEncoding.GetAnsiBytes(const S: string): TBytes;
+function TEncoding.GetAnsiBytes(const S: ansistring): TBytes;
 begin
   if S='' then
     Result := nil
@@ -43,13 +44,13 @@ begin
     Result := GetAnsiBytes(S, 1, Length(S));
 end;
 
-function TEncoding.GetAnsiBytes(const S: string; CharIndex, CharCount: Integer
+function TEncoding.GetAnsiBytes(const S: ansistring; CharIndex, CharCount: Integer
   ): TBytes;
 begin
   Result := GetAnsiBytes(Pointer(@S[CharIndex]), CharCount);
 end;
 
-function TEncoding.GetAnsiString(const Bytes: TBytes): string;
+function TEncoding.GetAnsiString(const Bytes: TBytes): ansistring;
 begin
   if Length(Bytes)=0 then
     Result := ''
@@ -58,7 +59,7 @@ begin
 end;
 
 function TEncoding.GetAnsiString(const Bytes: TBytes; ByteIndex,
-  ByteCount: Integer): string;
+  ByteCount: Integer): ansistring;
 begin
   Result := GetAnsiString(Pointer(@Bytes[ByteIndex]), ByteCount);
   SetCodePage(RawByteString(Result), DefaultSystemCodePage, False);
@@ -572,7 +573,7 @@ begin
     Move(S[1], Result[0], Length(S));
 end;
 
-function TMBCSEncoding.GetAnsiString(Bytes: PByte; ByteCount: Integer): string;
+function TMBCSEncoding.GetAnsiString(Bytes: PByte; ByteCount: Integer): ansistring;
 begin
   SetString(Result, Pointer(Bytes), ByteCount);
   SetCodePage(RawByteString(Result), GetCodePage, False);
@@ -735,7 +736,7 @@ begin
 end;
 
 function TUnicodeEncoding.GetAnsiString(Bytes: PByte; ByteCount: Integer
-  ): string;
+  ): ansistring;
 begin
   widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Bytes), RawByteString(Result), DefaultSystemCodePage, ByteCount div SizeOf(UnicodeChar));
 end;
@@ -819,7 +820,7 @@ begin
 end;
 
 function TBigEndianUnicodeEncoding.GetAnsiString(Bytes: PByte;
-  ByteCount: Integer): string;
+  ByteCount: Integer): ansistring;
 var
   B: TBytes;
 begin

+ 9 - 8
rtl/objpas/sysutils/sysencodingh.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     *********************************************************************
     Copyright (C) 2012 Paul Ishenin,
@@ -52,7 +53,7 @@ type
     function GetCharCount(Bytes: PByte; ByteCount: Integer): Integer; overload; virtual; abstract;
     function GetChars(Bytes: PByte; ByteCount: Integer; Chars: PUnicodeChar; CharCount: Integer): Integer; overload; virtual; abstract;
     function GetAnsiBytes(Chars: PAnsiChar; CharCount: Integer): TBytes; virtual; abstract;
-    function GetAnsiString(Bytes: PByte; ByteCount: Integer): string; virtual; abstract;
+    function GetAnsiString(Bytes: PByte; ByteCount: Integer): ansistring; virtual; abstract;
     function GetCodePage: Cardinal; virtual; abstract;
     function GetEncodingName: UnicodeString; virtual; abstract;
   public
@@ -87,10 +88,10 @@ type
     function GetPreamble: TBytes; virtual; abstract;
     function GetString(const Bytes: TBytes): UnicodeString; overload;
     function GetString(const Bytes: TBytes; ByteIndex, ByteCount: Integer): UnicodeString; overload;
-    function GetAnsiBytes(const S: string): TBytes; overload;
-    function GetAnsiBytes(const S: string; CharIndex, CharCount: Integer): TBytes; overload;
-    function GetAnsiString(const Bytes: TBytes): string; overload;
-    function GetAnsiString(const Bytes: TBytes; ByteIndex, ByteCount: Integer): string; overload;
+    function GetAnsiBytes(const S: Ansistring): TBytes; overload;
+    function GetAnsiBytes(const S: Ansistring; CharIndex, CharCount: Integer): TBytes; overload;
+    function GetAnsiString(const Bytes: TBytes): ansistring; overload;
+    function GetAnsiString(const Bytes: TBytes; ByteIndex, ByteCount:  Integer):ansistring; overload;
 
     property CodePage: Cardinal read GetCodePage;
     property EncodingName: UnicodeString read GetEncodingName;
@@ -119,7 +120,7 @@ type
     function GetCharCount(Bytes: PByte; ByteCount: Integer): Integer; overload; override;
     function GetChars(Bytes: PByte; ByteCount: Integer; Chars: PUnicodeChar; CharCount: Integer): Integer; overload; override;
     function GetAnsiBytes(Chars: PAnsiChar; CharCount: Integer): TBytes; override;
-    function GetAnsiString(Bytes: PByte; ByteCount: Integer): string; override;
+    function GetAnsiString(Bytes: PByte; ByteCount: Integer): ansistring; override;
     function GetCodePage: Cardinal; override;
     function GetEncodingName: UnicodeString; override;
   public
@@ -162,7 +163,7 @@ type
     function GetCharCount(Bytes: PByte; ByteCount: Integer): Integer; overload; override;
     function GetChars(Bytes: PByte; ByteCount: Integer; Chars: PUnicodeChar; CharCount: Integer): Integer; overload; override;
     function GetAnsiBytes(Chars: PAnsiChar; CharCount: Integer): TBytes; override;
-    function GetAnsiString(Bytes: PByte; ByteCount: Integer): string; override;
+    function GetAnsiString(Bytes: PByte; ByteCount: Integer): ansistring; override;
     function GetCodePage: Cardinal; override;
     function GetEncodingName: UnicodeString; override;
   public
@@ -181,7 +182,7 @@ type
     function GetBytes(Chars: PUnicodeChar; CharCount: Integer; Bytes: PByte; ByteCount: Integer): Integer; overload; override;
     function GetChars(Bytes: PByte; ByteCount: Integer; Chars: PUnicodeChar; CharCount: Integer): Integer; overload; override;
     function GetAnsiBytes(Chars: PAnsiChar; CharCount: Integer): TBytes; override;
-    function GetAnsiString(Bytes: PByte; ByteCount: Integer): string; override;
+    function GetAnsiString(Bytes: PByte; ByteCount: Integer): ansistring; override;
     function GetCodePage: Cardinal; override;
     function GetEncodingName: UnicodeString; override;
   public

+ 6 - 5
rtl/objpas/sysutils/sysinth.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     This file is part of the Free Pascal run time library.
     Copyright (c) 1999-2000 by the Free Pascal development team
@@ -33,12 +34,12 @@ type
   TFormatSettings = record
     CurrencyFormat: Byte;
     NegCurrFormat: Byte;
-    ThousandSeparator: AnsiChar;
-    DecimalSeparator: AnsiChar;
+    ThousandSeparator: Char;
+    DecimalSeparator: Char;
     CurrencyDecimals: Byte;
-    DateSeparator: AnsiChar;
-    TimeSeparator: AnsiChar;
-    ListSeparator: AnsiChar;
+    DateSeparator: Char;
+    TimeSeparator: Char;
+    ListSeparator: Char;
     CurrencyString: string;
     ShortDateFormat: string;
     LongDateFormat: string;

+ 29 - 0
rtl/objpas/sysutils/syssb.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 { TGenericStringBuilder }
 
 constructor TGenericStringBuilder.Create;
@@ -218,6 +219,29 @@ begin
   Result:=Self;
 end;
 
+{$IFDEF SBUNICODE}
+function TGenericStringBuilder.Append(const AValue: AnsiChar): TGenericStringBuilder;
+begin
+  DoAppend(WideChar(AValue));
+  Result:=Self;
+end;
+{$ELSE}
+function TGenericStringBuilder.Append(const AValue: WideChar): TGenericStringBuilder;
+begin
+  // We don't know what the target encoding is ?
+  DoAppend(AnsiChar(AValue));
+  Result:=Self;
+end;
+
+function TGenericStringBuilder.Append(const AValue: UnicodeString): TGenericStringBuilder;
+begin
+  // We don't know what the target encoding is ?
+  DoAppend(AnsiString(AValue));
+  Result:=Self;
+end;
+
+{$ENDIF}
+
 function TGenericStringBuilder.Append(const AValue: Currency): TGenericStringBuilder;
 begin
   DoAppend(CurrToStr(AValue));
@@ -630,7 +654,12 @@ begin
 end;
 
 
+{$IFDEF UNICODERTL}
+function TGenericStringBuilder.ToString: RTLString;
+{$ELSE}
 function TGenericStringBuilder.ToString: SBString;
+{$ENDIF}
+
 begin
   Result:=ToString(0,Length);
 end;

+ 9 - 4
rtl/objpas/sysutils/syssbh.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 
   { TGenericStringBuilder }
 
@@ -55,6 +56,10 @@
 {$IFDEF SBUNICODE}
     // Do not use SBRawstring, we need 2 versions in case of unicode
     Function Append(const AValue: SBString): TGenericStringBuilder;
+    Function Append(const AValue: AnsiChar): TGenericStringBuilder;
+{$ELSE}
+    Function Append(const AValue: UnicodeString): TGenericStringBuilder;
+    Function Append(const AValue: UnicodeChar): TGenericStringBuilder;
 {$ENDIF}
     Function Append(const AValue: RawByteString): TGenericStringBuilder;
     Function Append(const AValue: SBChar; RepeatCount: Integer): TGenericStringBuilder;
@@ -96,10 +101,10 @@
     Function Replace(const OldChar, NewChar: SBChar; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
     Function Replace(const OldValue, NewValue: SBRawString): TGenericStringBuilder;
     Function Replace(const OldValue, NewValue: SBRawString; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
-{$IFDEF SBUNICODE}
-    Function ToString: SBString;
-{$ELSE}
-    Function ToString: SBString; override;
+{$IFDEF UNICODERTL}
+    Function ToString: RTLString; override;
+{$ELSE}    
+    Function ToString: SBString; {$IFNDEF SBUNICODE} override; {$ELSE}  reintroduce; {$ENDIF}
 {$ENDIF}
     Function ToString(aStartIndex: Integer; aLength: Integer): SBString; reintroduce;
 

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

@@ -1413,6 +1413,69 @@ Begin
   Result:=(E=0);
 End;
 
+{$IF SIZEOF(CHAR)=2}
+
+Function TextToFloat(Buffer: PAnsiChar; Out Value; ValueType: TFloatValue): Boolean;
+
+begin
+  Result:=TextToFloat(Buffer,Value,ValueType,DefaultFormatSettings);
+end;
+
+Function TextToFloat(Buffer: PAnsiChar; Out Value; ValueType: TFloatValue; Const FormatSettings: TFormatSettings): Boolean;
+
+Var
+  E,P : Integer;
+  S : AnsiString;
+
+Begin
+  S:=StrPas(Buffer);
+  //ThousandSeparator not allowed as by Delphi specs
+  if (FormatSettings.ThousandSeparator <> FormatSettings.DecimalSeparator) and
+     (Pos(FormatSettings.ThousandSeparator, S) <> 0) then
+    begin
+      Result := False;
+      Exit;
+    end;
+  if (FormatSettings.DecimalSeparator <> '.') and
+     (Pos('.', S) <>0) then
+    begin
+      Result := False;
+      Exit;
+    end;
+
+  P:=Pos(FormatSettings.DecimalSeparator,S);
+  If (P<>0) Then
+    S[P] := '.';
+  s:=Trim(s);
+  try
+    case ValueType of
+      fvCurrency:
+        Val(S,Currency(Value),E);
+      fvExtended:
+        Val(S,Extended(Value),E);
+      fvDouble:
+        Val(S,Double(Value),E);
+      fvSingle:
+        Val(S,Single(Value),E);
+      fvComp:
+        Val(S,Comp(Value),E);
+      fvReal:
+        Val(S,Real(Value),E);
+    end;
+  { on x87, a floating point exception may be pending in case of an invalid
+    input value -> trigger it now }
+{$if defined(cpui386) or (defined(cpux86_64) and not(defined(win64))) or defined(cpui8086)}
+    asm
+      fwait
+    end;
+{$endif}
+  except
+    E:=1;
+  end;
+  Result:=(E=0);
+End;
+{$ENDIF}
+
 
 Function TryStrToFloat(Const S : String; Out Value: Single): Boolean;
 

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

@@ -212,6 +212,10 @@ Function TextToFloat(Buffer: PChar; Out Value: Extended): Boolean;
 Function TextToFloat(Buffer: PChar; Out Value: Extended; Const FormatSettings: TFormatSettings): Boolean;
 Function TextToFloat(Buffer: PChar; Out Value; ValueType: TFloatValue): Boolean;
 Function TextToFloat(Buffer: PChar; Out Value; ValueType: TFloatValue; Const FormatSettings: TFormatSettings): Boolean;
+{$IF SIZEOF(CHAR)=2}
+Function TextToFloat(Buffer: PAnsiChar; Out Value; ValueType: TFloatValue): Boolean;
+Function TextToFloat(Buffer: PAnsiChar; Out Value; ValueType: TFloatValue; Const FormatSettings: TFormatSettings): Boolean;
+{$ENDIF}
 Function FloatToText(Buffer: PWideChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer): Longint;
 Function FloatToText(Buffer: PWideChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer; Const FormatSettings: TFormatSettings): Longint;
 Function FloatToText(Buffer: PAnsiChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer): Longint;

+ 5 - 4
rtl/objpas/sysutils/sysuintf.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     *********************************************************************
     Copyright (C) 2002 Peter Vreman,
@@ -88,7 +89,7 @@ end;
 function TryStringToGUID(const S: string; out Guid: TGUID): Boolean;
 var
   e: Boolean;
-  p: PAnsiChar;
+  p: PChar;
 
   function rb: Byte;
   begin
@@ -101,7 +102,7 @@ var
     Inc(p);
   end;
 
-  procedure nextChar(c: AnsiChar); inline;
+  procedure nextChar(c: Char); inline;
   begin
     if p^ <> c then
       e := False;
@@ -111,7 +112,7 @@ var
 begin
   if Length(S)<>38 then Exit(False);
   e := True;
-  p := PAnsiChar(S);
+  p := PChar(S);
   nextChar('{');
   Guid.D1 := rb shl 28 or rb shl 24 or rb shl 20 or rb shl 16 or rb shl 12 or rb shl 8 or rb shl 4 or rb;
   nextChar('-');
@@ -155,7 +156,7 @@ end;
 function GUIDToString(const GUID: TGUID): string;
 begin
   SetLength(Result, 38);
-  StrLFmt(PAnsiChar(Result), 38,'{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}',
+  StrLFmt(PChar(Result), 38,'{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}',
     [
      Longint(GUID.D1), GUID.D2, GUID.D3,
      GUID.D4[0], GUID.D4[1], GUID.D4[2], GUID.D4[3],

+ 39 - 2
rtl/objpas/sysutils/sysuni.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     *********************************************************************
     Copyright (C) 2002-2005 by Florian Klaempfl
@@ -139,6 +140,7 @@ function UnicodeSameText(const s1, s2 : UnicodeString) : Boolean;{$ifdef SYSUTIL
 Function UnicodeFormat (Const Fmt : UnicodeString; const Args : Array of const; Const FormatSettings: TFormatSettings) : UnicodeString;
 {$i sysformt.inc}
 
+
 {$undef TFormatString}
 {$undef TFormatChar}
 {$undef INWIDEFORMAT}
@@ -149,12 +151,26 @@ begin
   Result:=UnicodeFormat(Fmt,Args,DefaultFormatSettings);
 end;
 
+Function Format (Const Fmt : UnicodeString; const Args : Array of const; Const FormatSettings: TFormatSettings) : UnicodeString;
+
+begin
+  Result:=UnicodeFormat(Fmt,Args,FormatSettings);
+end;
+
+
+Function Format (Const Fmt : UnicodeString; const Args : Array of const) : UnicodeString;
+begin
+  Result:=UnicodeFormat(Fmt,Args,DefaultFormatSettings);
+end;
+
+
 
 Function UnicodeFormatBuf (Var Buffer; BufLen : Cardinal;
-                     Const Fmt; fmtLen : Cardinal;
+                     Const Fmt ; fmtLen : Cardinal;
                      Const Args : Array of const; Const FormatSettings: TFormatSettings) : Cardinal;
 Var 
   S,F : UnicodeString;
+
 begin
   Setlength(F,fmtlen);
   if fmtlen > 0 then
@@ -164,7 +180,7 @@ begin
     Result:=Length(S)
   else
     Result:=Buflen;
-  Move(S[1],Buffer,Result);
+  Move(S[1],Buffer,Result*SizeOf(UnicodeChar));
 end;
 
 Function UnicodeFormatBuf (Var Buffer; BufLen : Cardinal;
@@ -549,6 +565,15 @@ begin
   Result:=UnicodeStringReplace(S,OldPattern,NewPattern,Flags,C);
 end;
 
+Function StringReplace(const S : UnicodeString; OldPattern, NewPattern: WideChar;  Flags: TReplaceFlags): Unicodestring;
+
+Var
+  C : Integer;
+
+begin
+  Result:=UnicodeStringReplace(S,OldPattern,NewPattern,Flags,C);
+end;
+
 function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags; Out aCount : Integer): UnicodeString;
 {$i syssr.inc}
 
@@ -557,3 +582,15 @@ function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString;  F
 {$undef SRUpperCase}
 {$undef SRPCHAR}
 {$undef SRCHAR}
+
+function StringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags): UnicodeString;
+
+begin
+  Result:=UnicodeStringReplace(S,OldPattern,NewPattern,Flags);
+end;
+
+function StringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags; Out aCount : Integer): UnicodeString;
+
+begin
+  Result:=UnicodeStringReplace(S,OldPattern,NewPattern,Flags,aCount);
+end;

+ 5 - 0
rtl/objpas/sysutils/sysunih.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     *********************************************************************
     Copyright (C) 2002 by Florian Klaempfl
@@ -69,4 +70,8 @@ function WideStringOf(const Value: TBytes): UnicodeString;
 function ByteLength(const S: UnicodeString): Integer;
 function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags): UnicodeString;
 function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags; Out aCount : Integer): UnicodeString;
+function StringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags): UnicodeString;
+function StringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags; Out aCount : Integer): UnicodeString;
+// Needed to avoid "cannot determine overload"
+function StringReplace(const S : UnicodeString; OldPattern, NewPattern: WideChar;  Flags: TReplaceFlags): UnicodeString;
 

+ 6 - 5
rtl/objpas/sysutils/sysutilh.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     This file is part of the Free Pascal run time library.
     Copyright (c) 1999-2000 by Florian Klaempfl
@@ -111,15 +112,15 @@ type
     public
       constructor Create(const msg : string);
       constructor CreateFmt(const msg : string; const args : array of const);
-      constructor CreateRes(ResString: PString);
-      constructor CreateResFmt(ResString: PString; const Args: array of const);
+      constructor CreateRes(ResString: PAnsiString);
+      constructor CreateResFmt(ResString: PAnsiString; const Args: array of const);
       constructor CreateHelp(const Msg: string; AHelpContext: Longint);
       constructor CreateFmtHelp(const Msg: string; const Args: array of const;
         AHelpContext: Longint);
-      constructor CreateResHelp(ResString: PString; AHelpContext: Longint);
-      constructor CreateResFmtHelp(ResString: PString; const Args: array of const;
+      constructor CreateResHelp(ResString: PAnsiString; AHelpContext: Longint);
+      constructor CreateResFmtHelp(ResString: PAnsiString; const Args: array of const;
         AHelpContext: Longint);
-      Function ToString : String; override;
+      Function ToString : RTLString; override;
 
       function GetBaseException : Exception;virtual;
 

+ 8 - 7
rtl/objpas/sysutils/sysutils.inc

@@ -1,3 +1,4 @@
+{%MainUnit sysutils.pp}
 {
     This file is part of the Free Pascal run time library.
     Copyright (c) 1999-2000 by Florian Klaempfl
@@ -192,7 +193,7 @@ end;
       end;
 
 
-    constructor Exception.CreateRes(ResString: PString);
+    constructor Exception.CreateRes(ResString: PAnsiString);
 
       begin
          inherited create;
@@ -200,7 +201,7 @@ end;
       end;
 
 
-    constructor Exception.CreateResFmt(ResString: PString; const Args: array of const);
+    constructor Exception.CreateResFmt(ResString: PAnsiString; const Args: array of const);
 
       begin
          inherited create;
@@ -227,7 +228,7 @@ end;
     end;
 
 
-    constructor Exception.CreateResHelp(ResString: PString; AHelpContext: Longint);
+    constructor Exception.CreateResHelp(ResString: PAnsiString; AHelpContext: Longint);
 
     begin
        inherited create;
@@ -236,7 +237,7 @@ end;
     end;
 
 
-    constructor Exception.CreateResFmtHelp(ResString: PString; const Args: array of const;
+    constructor Exception.CreateResFmtHelp(ResString: PAnsiString; const Args: array of const;
       AHelpContext: Longint);
 
     begin
@@ -245,7 +246,7 @@ end;
        fhelpcontext:=AHelpContext;
     end;
 
-    Function Exception.ToString : String;
+    Function Exception.ToString : RTLString;
     begin
       Result:=ClassName+': '+Message;
     end;
@@ -351,7 +352,7 @@ type
 {$IFDEF FPC_HAS_FEATURE_RESOURCES}  // This is necessary for 2.4.4, which does not have reasources as a separate feature
     msg:  PResStringRec;
 {$else FPC_HAS_FEATURE_RESOURCES}
-    msg:  PString;
+    msg:  PAnsiString;
 {$endif FPC_HAS_FEATURE_RESOURCES}
   end;
 
@@ -411,7 +412,7 @@ Var OutOfMemory : EOutOfMemory;
 Procedure RunErrorToExcept (ErrNo : Longint; Address : CodePointer; Frame : Pointer);
 var
   E: Exception;
-  HS: PString;
+  HS: PAnsiString;
   Entry: PExceptMapEntry;
 begin
   Case Errno of

+ 4 - 1
rtl/os2/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/sinclairql/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 5 - 0
rtl/symbian/sysutils.pp

@@ -15,7 +15,12 @@
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
+
 unit sysutils;
 
 interface

+ 5 - 1
rtl/unix/sysutils.pp

@@ -18,7 +18,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{$H+} // will result in unicode string in unicode RTL
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
+{$H+}
+{$ENDIF}
 
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}

+ 5 - 2
rtl/wasi/sysutils.pp

@@ -19,9 +19,12 @@ unit sysutils;
 interface
 
 {$MODE objfpc}
-{$MODESWITCH out}
-{ force ansistrings }
+{$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 5 - 2
rtl/watcom/sysutils.pp

@@ -20,9 +20,12 @@ unit sysutils;
 interface
 
 {$MODE objfpc}
-{$modeswitch out}
-{ force ansistrings }
+{$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/wii/sysutils.pp

@@ -26,8 +26,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/win/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 5 - 2
rtl/win16/sysutils.pp

@@ -20,9 +20,12 @@ unit sysutils;
 interface
 
 {$MODE objfpc}
-{$MODESWITCH out}
-{ force ansistrings }
+{$MODESWITCH OUT}
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 

+ 4 - 1
rtl/wince/sysutils.pp

@@ -19,8 +19,11 @@ interface
 
 {$MODE objfpc}
 {$MODESWITCH OUT}
-{ force ansistrings }
+{$IFDEF UNICODERTL}
+{$MODESWITCH UNICODESTRINGS}
+{$ELSE}
 {$H+}
+{$ENDIF}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}