Browse Source

Long long code editor lines

Margers 10 months ago
parent
commit
5c215cd524
6 changed files with 518 additions and 278 deletions
  1. 5 13
      packages/ide/fpmopts.inc
  2. 13 13
      packages/ide/fpviews.pas
  3. 103 90
      packages/ide/wcedit.pas
  4. 199 140
      packages/ide/weditor.pas
  5. 9 8
      packages/ide/whlpview.pas
  6. 189 14
      packages/ide/wutils.pas

+ 5 - 13
packages/ide/fpmopts.inc

@@ -820,7 +820,7 @@ begin
             else
             else
               messagebox('Internal error: Unknown switch.',nil,mfOkButton);
               messagebox('Internal error: Unknown switch.',nil,mfOkButton);
           end;
           end;
-          e^.setcontent(directorySwitches^.getMultiStringItem(i));
+          e^.SetContent(directorySwitches^.getMultiStringItem(i));
           e^.addline(''); {Empty line so user can scroll below existing dirs.}
           e^.addline(''); {Empty line so user can scroll below existing dirs.}
           IL[i]:=nil;
           IL[i]:=nil;
         end
         end
@@ -904,14 +904,10 @@ begin
             end;
             end;
             c:=directorySwitches^.getMultiStringItem(i);
             c:=directorySwitches^.getMultiStringItem(i);
             c^.freeall;
             c^.freeall;
-            for j:=0 to e^.getlinecount-1 do
+            for j:=0 to e^.GetLineCount-1 do
               begin
               begin
-                s:=e^.getlinetext(j);
-                {Strip string.}
-                while (length(s)>0) and (s[length(s)]=' ') do
-                  dec(s[0]);
-                while (length(s)>0) and (s[1]=' ') do
-                  system.delete(s,1,1);
+                s:=e^.GetLineText(j);   { Note: AnsiString to ShortString convertino}
+                s:=Trim(s);
                 if s<>'' then
                 if s<>'' then
                   c^.insert(newstr(s));
                   c^.insert(newstr(s));
               end;
               end;
@@ -919,11 +915,7 @@ begin
         else
         else
           begin
           begin
             s:=IL[i]^.data^;
             s:=IL[i]^.data^;
-            {Strip string.}
-            while (length(s)>0) and (s[length(s)]=' ') do
-              dec(s[0]);
-            while (length(s)>0) and (s[1]=' ') do
-              system.delete(s,1,1);
+            s:=Trim(s);
             DirectorySwitches^.SetStringItem(i,s);
             DirectorySwitches^.SetStringItem(i,s);
           end;
           end;
     end;
     end;

+ 13 - 13
packages/ide/fpviews.pas

@@ -173,8 +173,8 @@ type
       procedure   DelChar; virtual;
       procedure   DelChar; virtual;
       procedure   DelSelect; virtual;
       procedure   DelSelect; virtual;
       function    InsertNewLine : Sw_integer;virtual;
       function    InsertNewLine : Sw_integer;virtual;
-      function    InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
-      procedure   AddLine(const S: string); virtual;
+      function    InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine; virtual;
+      procedure   AddLine(const S: sw_astring); virtual;
     end;
     end;
 
 
     PSourceWindow = ^TSourceWindow;
     PSourceWindow = ^TSourceWindow;
@@ -203,7 +203,7 @@ type
     TGDBSourceEditor = object(TSourceEditor)
     TGDBSourceEditor = object(TSourceEditor)
       function   InsertNewLine : Sw_integer;virtual;
       function   InsertNewLine : Sw_integer;virtual;
       function   Valid(Command: Word): Boolean; virtual;
       function   Valid(Command: Word): Boolean; virtual;
-      procedure  AddLine(const S: string); virtual;
+      procedure  AddLine(const S: sw_astring); virtual;
       procedure  AddErrorLine(const S: string); virtual;
       procedure  AddErrorLine(const S: string); virtual;
       { Syntax highlight }
       { Syntax highlight }
       function  IsReservedWord(const S: string): boolean; virtual;
       function  IsReservedWord(const S: string): boolean; virtual;
@@ -1387,7 +1387,7 @@ end;
 procedure TSourceEditor.FindMatchingDelimiter(ScanForward: boolean);
 procedure TSourceEditor.FindMatchingDelimiter(ScanForward: boolean);
 var
 var
   St,nextResWord : String;
   St,nextResWord : String;
-  LineText,LineAttr: string;
+  LineText,LineAttr: sw_astring;
   Res,found,addit : boolean;
   Res,found,addit : boolean;
   JumpPos: TPoint;
   JumpPos: TPoint;
   X,Y,lexchange,curlevel,linecount : sw_integer;
   X,Y,lexchange,curlevel,linecount : sw_integer;
@@ -1698,7 +1698,7 @@ end;
 
 
 procedure TSourceEditor.DelChar;
 procedure TSourceEditor.DelChar;
 var
 var
-  S: string;
+  S: sw_astring;
   I,CI : sw_integer;
   I,CI : sw_integer;
 {$ifndef NODEBUG}
 {$ifndef NODEBUG}
   PBStart,PBEnd : PBreakpoint;
   PBStart,PBEnd : PBreakpoint;
@@ -1802,7 +1802,7 @@ begin
 end;
 end;
 
 
 
 
-function TSourceEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
+function TSourceEditor.InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine;
 begin
 begin
   InsertLine := inherited InsertLine(LineNo,S);
   InsertLine := inherited InsertLine(LineNo,S);
 {$ifndef NODEBUG}
 {$ifndef NODEBUG}
@@ -1811,7 +1811,7 @@ begin
 {$endif NODEBUG}
 {$endif NODEBUG}
 end;
 end;
 
 
-procedure TSourceEditor.AddLine(const S: string);
+procedure TSourceEditor.AddLine(const S: sw_astring);
 begin
 begin
   inherited AddLine(S);
   inherited AddLine(S);
 {$ifndef NODEBUG}
 {$ifndef NODEBUG}
@@ -1870,7 +1870,7 @@ begin
          AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
          AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
        else
        else
          AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
          AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
-           ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
+           ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetText()+'"',0,0);
       end;
       end;
   if Core^.RedoList^.count>0 then
   if Core^.RedoList^.count>0 then
     AddToolCommand('RedoList Dump');
     AddToolCommand('RedoList Dump');
@@ -1881,7 +1881,7 @@ begin
          AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
          AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
        else
        else
          AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
          AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
-         ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
+         ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetText()+'"',0,0);
       end;
       end;
   UpdateToolMessages;
   UpdateToolMessages;
   if Assigned(MessagesWindow) then
   if Assigned(MessagesWindow) then
@@ -2213,11 +2213,11 @@ begin
   inherited Init(Bounds,AFileName,{SearchFreeWindowNo}0);
   inherited Init(Bounds,AFileName,{SearchFreeWindowNo}0);
   AutoNumber:=true;
   AutoNumber:=true;
   Options:=Options or ofTileAble;
   Options:=Options or ofTileAble;
-  GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
+  GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=15;
   New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
   New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
   GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
   GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
   New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
   New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
-  GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
+  GetExtent(R); R.A.X:=3; R.B.X:=15; R.A.Y:=R.B.Y-1;
   New(Indicator, Init(R));
   New(Indicator, Init(R));
   Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
   Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
   Insert(Indicator);
   Insert(Indicator);
@@ -2419,7 +2419,7 @@ begin
   Valid:=OK;
   Valid:=OK;
 end;
 end;
 
 
-procedure  TGDBSourceEditor.AddLine(const S: string);
+procedure  TGDBSourceEditor.AddLine(const S: sw_astring);
 begin
 begin
    if Silent or (IgnoreStringAtEnd and (S=LastCommand)) then exit;
    if Silent or (IgnoreStringAtEnd and (S=LastCommand)) then exit;
    inherited AddLine(S);
    inherited AddLine(S);
@@ -2696,7 +2696,7 @@ end;
 
 
 procedure  TDisassemblyEditor.AddSourceLine(const AFileName: string;line : longint);
 procedure  TDisassemblyEditor.AddSourceLine(const AFileName: string;line : longint);
 var
 var
-  S : String;
+  S : sw_astring;
 begin
 begin
    if AFileName<>CurrentSource then
    if AFileName<>CurrentSource then
      begin
      begin

+ 103 - 90
packages/ide/wcedit.pas

@@ -47,7 +47,11 @@ type
     PLine = ^TLine;
     PLine = ^TLine;
     TLine = object(TCustomLine)
     TLine = object(TCustomLine)
     public { internal use only! }
     public { internal use only! }
-      Text        : PString;
+{$if sizeof(sw_astring)>8}
+      Text      : PString;    { ShortString version }
+{$else}
+      Text      : sw_AString; { AnsiString version  }
+{$endif}
       DefaultEditorInfo : PEditorLineInfo;
       DefaultEditorInfo : PEditorLineInfo;
       EditorInfos : PEditorLineInfoCollection;
       EditorInfos : PEditorLineInfoCollection;
       Flags       : longint;
       Flags       : longint;
@@ -55,9 +59,9 @@ type
       procedure AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor); virtual;
       procedure AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor); virtual;
       procedure RemoveEditorInfo(AEditor: PCustomCodeEditor); virtual;
       procedure RemoveEditorInfo(AEditor: PCustomCodeEditor); virtual;
     public
     public
-      constructor Init(AOwner: PCustomCodeEditorCore; const AText: string; AFlags: longint);
-      function    GetText: string; virtual;
-      procedure   SetText(const AText: string); virtual;
+      constructor Init(AOwner: PCustomCodeEditorCore; const AText: sw_AString; AFlags: longint);
+      function    GetText: sw_AString; virtual;
+      procedure   SetText(const AText: sw_AString); virtual;
       function    GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo; virtual;
       function    GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo; virtual;
       function    GetFlags: longint; virtual;
       function    GetFlags: longint; virtual;
       procedure   SetFlags(AFlags: longint); virtual;
       procedure   SetFlags(AFlags: longint); virtual;
@@ -98,26 +102,26 @@ type
     protected
     protected
       { Text & info storage abstraction }
       { Text & info storage abstraction }
       procedure   ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean); virtual;
       procedure   ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean); virtual;
-      procedure   IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string); virtual;
-      function    IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string; virtual;
-      procedure   ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string); virtual;
+      procedure   IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:sw_astring); virtual;
+      function    IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): sw_astring; virtual;
+      procedure   ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring); virtual;
     public
     public
       { Text & info storage abstraction }
       { Text & info storage abstraction }
       function    GetLineCount: sw_integer; virtual;
       function    GetLineCount: sw_integer; virtual;
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
-      function    GetLineText(LineNo: sw_integer): string; virtual;
-      procedure   SetDisplayText(I: sw_integer;const S: string); virtual;
-      function    GetDisplayText(I: sw_integer): string; virtual;
-      procedure   SetLineText(I: sw_integer;const S: string); virtual;
+      function    GetLineText(LineNo: sw_integer): sw_AString; virtual;
+      procedure   SetDisplayText(I: sw_integer;const S: sw_astring); virtual;
+      function    GetDisplayText(I: sw_integer): sw_astring; virtual;
+      procedure   SetLineText(I: sw_integer;const S: sw_AString); virtual;
       procedure   DeleteAllLines; virtual;
       procedure   DeleteAllLines; virtual;
       procedure   DeleteLine(I: sw_integer); virtual;
       procedure   DeleteLine(I: sw_integer); virtual;
-      function    InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
-      procedure   AddLine(const S: string); virtual;
+      function    InsertLine(LineNo: sw_integer; const S: sw_AString): PCustomLine; virtual;
+      procedure   AddLine(const S: sw_AString); virtual;
       procedure   GetContent(ALines: PUnsortedStringCollection); virtual;
       procedure   GetContent(ALines: PUnsortedStringCollection); virtual;
       procedure   SetContent(ALines: PUnsortedStringCollection); virtual;
       procedure   SetContent(ALines: PUnsortedStringCollection); virtual;
    public
    public
      { Undo info storage }
      { Undo info storage }
-      procedure   AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
+      procedure   AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint); virtual;
       procedure   AddGroupedAction(AAction : byte); virtual;
       procedure   AddGroupedAction(AAction : byte); virtual;
       procedure   CloseGroupedAction(AAction : byte); virtual;
       procedure   CloseGroupedAction(AAction : byte); virtual;
       function    GetUndoActionCount: sw_integer; virtual;
       function    GetUndoActionCount: sw_integer; virtual;
@@ -180,17 +184,17 @@ type
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
       function    CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
       function    CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
       function    LinePosToCharIdx(Line,X: sw_integer): sw_integer; virtual;
       function    LinePosToCharIdx(Line,X: sw_integer): sw_integer; virtual;
-      function    GetLineText(I: sw_integer): string; virtual;
-      procedure   SetDisplayText(I: sw_integer;const S: string); virtual;
-      function    GetDisplayText(I: sw_integer): string; virtual;
-      procedure   SetLineText(I: sw_integer;const S: string); virtual;
-      procedure   GetDisplayTextFormat(I: sw_integer;var DT,DF:string); virtual;
-      function    GetLineFormat(I: sw_integer): string; virtual;
-      procedure   SetLineFormat(I: sw_integer;const S: string); virtual;
+      function    GetLineText(I: sw_integer): sw_AString; virtual;
+      procedure   SetDisplayText(I: sw_integer;const S: sw_astring); virtual;
+      function    GetDisplayText(I: sw_integer): sw_astring; virtual;
+      procedure   SetLineText(I: sw_integer;const S: sw_AString); virtual;
+      procedure   GetDisplayTextFormat(I: sw_integer;var DT,DF:sw_astring); virtual;
+      function    GetLineFormat(I: sw_integer): sw_astring; virtual;
+      procedure   SetLineFormat(I: sw_integer;const S: sw_astring); virtual;
       procedure   DeleteAllLines; virtual;
       procedure   DeleteAllLines; virtual;
       procedure   DeleteLine(I: sw_integer); virtual;
       procedure   DeleteLine(I: sw_integer); virtual;
-      function    InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
-      procedure   AddLine(const S: string); virtual;
+      function    InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine; virtual;
+      procedure   AddLine(const S: sw_astring); virtual;
       function    GetErrorMessage: string; virtual;
       function    GetErrorMessage: string; virtual;
       procedure   SetErrorMessage(const S: string); virtual;
       procedure   SetErrorMessage(const S: string); virtual;
       procedure   GetContent(ALines: PUnsortedStringCollection); virtual;
       procedure   GetContent(ALines: PUnsortedStringCollection); virtual;
@@ -211,7 +215,7 @@ type
    {a}function    UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
    {a}function    UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
    public
    public
      { Undo info storage }
      { Undo info storage }
-      procedure   AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
+      procedure   AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint); virtual;
       procedure   AddGroupedAction(AAction : byte); virtual;
       procedure   AddGroupedAction(AAction : byte); virtual;
       procedure   CloseGroupedAction(AAction : byte); virtual;
       procedure   CloseGroupedAction(AAction : byte); virtual;
       function    GetUndoActionCount: sw_integer; virtual;
       function    GetUndoActionCount: sw_integer; virtual;
@@ -290,7 +294,7 @@ const
   );
   );
 {$endif}
 {$endif}
 
 
-constructor TLine.Init(AOwner: PCustomCodeEditorCore; const AText: string; AFlags: longint);
+constructor TLine.Init(AOwner: PCustomCodeEditorCore; const AText: sw_AString; AFlags: longint);
 begin
 begin
   inherited Init(AText,AFlags);
   inherited Init(AText,AFlags);
   // New(EditorInfos, Init(10,10));
   // New(EditorInfos, Init(10,10));
@@ -321,14 +325,22 @@ begin
     EditorInfos^.Free(E);
     EditorInfos^.Free(E);
 end;
 end;
 
 
-function TLine.GetText: string;
+function TLine.GetText: sw_AString;
 begin
 begin
+{$if sizeof(sw_astring)>8}
   GetText:=GetStr(Text);
   GetText:=GetStr(Text);
+{$else}
+  GetText:=Text;
+{$endif}
 end;
 end;
 
 
-procedure TLine.SetText(const AText: string);
+procedure TLine.SetText(const AText: sw_AString);
 begin
 begin
+{$if sizeof(sw_astring)>8}
   SetStr(Text,AText);
   SetStr(Text,AText);
+{$else}
+  Text:=AText;
+{$endif}
 end;
 end;
 
 
 function TLine.GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo;
 function TLine.GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo;
@@ -357,9 +369,14 @@ end;
 
 
 destructor TLine.Done;
 destructor TLine.Done;
 begin
 begin
+{$if sizeof(sw_astring)>8}
+  { ShortString version }
   if Assigned(Text) then
   if Assigned(Text) then
     DisposeStr(Text);
     DisposeStr(Text);
   Text:=nil;
   Text:=nil;
+{$else}
+  Text:='';   { AnsiString version  }
+{$endif}
   if Assigned(EditorInfos) then
   if Assigned(EditorInfos) then
     Dispose(EditorInfos, Done);
     Dispose(EditorInfos, Done);
   EditorInfos:=nil;
   EditorInfos:=nil;
@@ -477,7 +494,7 @@ procedure TCodeEditorCore.GetContent(ALines: PUnsortedStringCollection);
 procedure AddIt(P: PCustomLine);
 procedure AddIt(P: PCustomLine);
 begin
 begin
   if Assigned(P) then
   if Assigned(P) then
-    ALines^.Insert(NewStr(P^.GetText));
+    ALines^.Insert(NewStr(P^.GetText)); {  Note: AnsiString to ShortString convertion }
 end;
 end;
 begin
 begin
   if Assigned(Lines) then
   if Assigned(Lines) then
@@ -487,7 +504,7 @@ end;
 procedure TCodeEditorCore.SetContent(ALines: PUnsortedStringCollection);
 procedure TCodeEditorCore.SetContent(ALines: PUnsortedStringCollection);
 procedure AddIt(P: PString);
 procedure AddIt(P: PString);
 begin
 begin
-  AddLine(GetStr(P));
+  AddLine(GetStr(P));  { Note: ShortString to AnsiString convertion }
 end;
 end;
 begin
 begin
   DeleteAllLines;
   DeleteAllLines;
@@ -523,7 +540,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TCodeEditorCore.GetLineText(LineNo: sw_integer): string;
+function TCodeEditorCore.GetLineText(LineNo: sw_integer): sw_AString;
 var
 var
   L : PCustomLine;
   L : PCustomLine;
 begin
 begin
@@ -549,7 +566,7 @@ begin
   Lines^.AtInsert(Idx,Line);
   Lines^.AtInsert(Idx,Line);
 end;
 end;
 
 
-procedure TCodeEditorCore.SetLineText(I: sw_integer;const S: string);
+procedure TCodeEditorCore.SetLineText(I: sw_integer;const S: sw_AString);
 var
 var
   L : PCustomLine;
   L : PCustomLine;
   AddCount : Sw_Integer;
   AddCount : Sw_Integer;
@@ -567,12 +584,12 @@ begin
   ContentsChanged;
   ContentsChanged;
 end;
 end;
 
 
-function TCodeEditorCore.GetDisplayText(I: sw_integer): string;
+function TCodeEditorCore.GetDisplayText(I: sw_integer): sw_astring;
 begin
 begin
   GetDisplayText:=ExtractTabs(GetLineText(I),GetTabSize);
   GetDisplayText:=ExtractTabs(GetLineText(I),GetTabSize);
 end;
 end;
 
 
-procedure TCodeEditorCore.SetDisplayText(I: sw_integer;const S: string);
+procedure TCodeEditorCore.SetDisplayText(I: sw_integer;const S: sw_astring);
 begin
 begin
   { I disagree here
   { I disagree here
     I don't want the editor to change the position of the tabs
     I don't want the editor to change the position of the tabs
@@ -584,7 +601,7 @@ begin
    SetLineText(I,S);
    SetLineText(I,S);
 end;
 end;
 
 
-procedure TCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string);
+procedure TCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:sw_astring);
 var
 var
   L : PCustomLine;
   L : PCustomLine;
   P,PAdd : SW_Integer;
   P,PAdd : SW_Integer;
@@ -606,18 +623,18 @@ begin
          begin
          begin
            PAdd:=TabSize-((p-1) mod TabSize);
            PAdd:=TabSize-((p-1) mod TabSize);
            if DF<>'' then
            if DF<>'' then
-            DF:=copy(DF,1,P-1)+CharStr(DF[p],PAdd)+copy(DF,P+1,High(DF));
-           DT:=copy(DT,1,P-1)+CharStr(' ',PAdd)+copy(DT,P+1,High(DF));
+             DF:=copy(DF,1,P-1)+CharStr(DF[p],PAdd)+copy(DF,P+1,Length(DF));
+           DT:=copy(DT,1,P-1)+CharStr(' ',PAdd)+copy(DT,P+1,Length(DT));
            inc(P,PAdd-1);
            inc(P,PAdd-1);
          end;
          end;
       end;
       end;
    end;
    end;
 end;
 end;
 
 
-function TCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string;
+function TCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): sw_astring;
 var P: PCustomLine;
 var P: PCustomLine;
     LI: PEditorLineInfo;
     LI: PEditorLineInfo;
-    S: string;
+    S: sw_astring;
 begin
 begin
   if (0<=LineNo) and (LineNo<GetLineCount) then
   if (0<=LineNo) and (LineNo<GetLineCount) then
     P:=GetLine(LineNo)
     P:=GetLine(LineNo)
@@ -629,7 +646,7 @@ begin
   IGetLineFormat:=S;
   IGetLineFormat:=S;
 end;
 end;
 
 
-procedure TCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string);
+procedure TCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring);
 var P: PCustomLine;
 var P: PCustomLine;
     LI: PEditorLineInfo;
     LI: PEditorLineInfo;
 begin
 begin
@@ -662,7 +679,7 @@ begin
     end;
     end;
 end;
 end;
 
 
-function TCodeEditorCore.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
+function TCodeEditorCore.InsertLine(LineNo: sw_integer; const S: sw_AString): PCustomLine;
 var L: PLine;
 var L: PLine;
 begin
 begin
   L:=New(PLine, Init(@Self,S,0));
   L:=New(PLine, Init(@Self,S,0));
@@ -670,16 +687,16 @@ begin
   InsertLine:=L;
   InsertLine:=L;
 end;
 end;
 
 
-procedure TCodeEditorCore.AddLine(const S: string);
+procedure TCodeEditorCore.AddLine(const S: sw_AString);
 begin
 begin
   LinesInsert(-1,New(PLine, Init(@Self,S,0)));
   LinesInsert(-1,New(PLine, Init(@Self,S,0)));
 end;
 end;
 
 
-procedure TCodeEditorCore.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint);
+procedure TCodeEditorCore.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint);
 var
 var
   ActionIntegrated : boolean;
   ActionIntegrated : boolean;
   pa : PEditorAction;
   pa : PEditorAction;
-  S : String;
+  S : Sw_AString;
 begin
 begin
   if (UndoList=nil) or (not StoreUndo) then Exit;
   if (UndoList=nil) or (not StoreUndo) then Exit;
   ActionIntegrated:=false;
   ActionIntegrated:=false;
@@ -700,14 +717,12 @@ begin
          then
          then
         begin
         begin
           pa^.EndPos:=AEndPos;
           pa^.EndPos:=AEndPos;
-          S:=GetStr(pa^.text);
-          if S<>'' then
-           DisposeStr(pa^.text);
+          S:=pa^.GetText;
           if (AAction=eaDeleteText) and
           if (AAction=eaDeleteText) and
              (AStartPos.X>AEndPos.X) then
              (AStartPos.X>AEndPos.X) then
-            pa^.text:=NewStr(AText+S)
+            pa^.SetText(AText+S)
           else
           else
-            pa^.text:=NewStr(S+AText);
+            pa^.SetText(S+AText);
           ActionIntegrated:=true;
           ActionIntegrated:=true;
         end;
         end;
     end;
     end;
@@ -1008,37 +1023,37 @@ begin
   LinePosToCharIdx:=Core^.LinePosToCharIdx(Line,X);
   LinePosToCharIdx:=Core^.LinePosToCharIdx(Line,X);
 end;
 end;
 
 
-function TCodeEditor.GetLineText(I: sw_integer): string;
+function TCodeEditor.GetLineText(I: sw_integer): sw_astring;
 begin
 begin
   GetLineText:=Core^.GetLineText(I);
   GetLineText:=Core^.GetLineText(I);
 end;
 end;
 
 
-procedure TCodeEditor.SetDisplayText(I: sw_integer;const S: string);
+procedure TCodeEditor.SetDisplayText(I: sw_integer;const S: sw_astring);
 begin
 begin
   Core^.SetDisplayText(I,S);
   Core^.SetDisplayText(I,S);
 end;
 end;
 
 
-function TCodeEditor.GetDisplayText(I: sw_integer): string;
+function TCodeEditor.GetDisplayText(I: sw_integer): sw_astring;
 begin
 begin
   GetDisplayText:=Core^.GetDisplayText(I);
   GetDisplayText:=Core^.GetDisplayText(I);
 end;
 end;
 
 
-procedure TCodeEditor.SetLineText(I: sw_integer;const S: string);
+procedure TCodeEditor.SetLineText(I: sw_integer;const S: sw_AString);
 begin
 begin
   Core^.SetLineText(I,S);
   Core^.SetLineText(I,S);
 end;
 end;
 
 
-procedure TCodeEditor.GetDisplayTextFormat(I: sw_integer;var DT,DF:string);
+procedure TCodeEditor.GetDisplayTextFormat(I: sw_integer;var DT,DF:sw_astring);
 begin
 begin
   Core^.GetDisplayTextFormat(@Self,I,DT,DF);
   Core^.GetDisplayTextFormat(@Self,I,DT,DF);
 end;
 end;
 
 
-function TCodeEditor.GetLineFormat(I: sw_integer): string;
+function TCodeEditor.GetLineFormat(I: sw_integer): sw_astring;
 begin
 begin
   GetLineFormat:=Core^.GetLineFormat(@Self,I);
   GetLineFormat:=Core^.GetLineFormat(@Self,I);
 end;
 end;
 
 
-procedure TCodeEditor.SetLineFormat(I: sw_integer;const S: string);
+procedure TCodeEditor.SetLineFormat(I: sw_integer;const S: sw_astring);
 begin
 begin
   Core^.SetLineFormat(@Self,I,S);
   Core^.SetLineFormat(@Self,I,S);
 end;
 end;
@@ -1053,12 +1068,12 @@ begin
   Core^.DeleteLine(I);
   Core^.DeleteLine(I);
 end;
 end;
 
 
-function TCodeEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
+function TCodeEditor.InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine;
 begin
 begin
   InsertLine:=Core^.InsertLine(LineNo,S);
   InsertLine:=Core^.InsertLine(LineNo,S);
 end;
 end;
 
 
-procedure TCodeEditor.AddLine(const S: string);
+procedure TCodeEditor.AddLine(const S: sw_astring);
 begin
 begin
   Core^.AddLine(S);
   Core^.AddLine(S);
 end;
 end;
@@ -1283,7 +1298,7 @@ var
   UndoTime : longint;
   UndoTime : longint;
   WasInserting,WasAutoBrackets,IsGrouped,HadefNoIndent : boolean;
   WasInserting,WasAutoBrackets,IsGrouped,HadefNoIndent : boolean;
   MaxY,MinY : sw_integer;
   MaxY,MinY : sw_integer;
-  Line : String;
+  Line, uText : Sw_AString;
 
 
   procedure SetMinMax(y : sw_integer);
   procedure SetMinMax(y : sw_integer);
     begin
     begin
@@ -1321,6 +1336,7 @@ begin
         begin
         begin
           if not IsGrouped then
           if not IsGrouped then
             UndoTime:=TimeStamp;
             UndoTime:=TimeStamp;
+          uText:=GetText;
           case action of
           case action of
             eaMoveCursor :
             eaMoveCursor :
               begin
               begin
@@ -1330,9 +1346,8 @@ begin
             eaInsertText :
             eaInsertText :
               begin
               begin
                 SetCurPtr(StartPos.X,StartPos.Y);
                 SetCurPtr(StartPos.X,StartPos.Y);
-                if assigned(text) then
-                  for Temp := 1 to length(Text^) do
-                    DelChar;
+                for Temp := 1 to length(uText) do
+                  DelChar;
                 SetMinMax(StartPos.Y);
                 SetMinMax(StartPos.Y);
               end;
               end;
             eaDeleteText :
             eaDeleteText :
@@ -1343,9 +1358,8 @@ begin
                 SetInsertMode(true);
                 SetInsertMode(true);
                 WasAutoBrackets:=GetAutoBrackets;
                 WasAutoBrackets:=GetAutoBrackets;
                 SetAutoBrackets(false);
                 SetAutoBrackets(false);
-                if assigned(text) then
-                  for Temp := 1 to length(Text^) do
-                    AddChar(Text^[Temp]);
+                for Temp := 1 to length(uText) do
+                  AddChar(uText[Temp]);
                 SetAutoBrackets(WasAutoBrackets);
                 SetAutoBrackets(WasAutoBrackets);
                 SetInsertMode(WasInserting);
                 SetInsertMode(WasInserting);
                 SetMinMax(EndPos.Y);
                 SetMinMax(EndPos.Y);
@@ -1359,15 +1373,14 @@ begin
                 SetInsertMode(false);
                 SetInsertMode(false);
                 WasAutoBrackets:=GetAutoBrackets;
                 WasAutoBrackets:=GetAutoBrackets;
                 SetAutoBrackets(false);
                 SetAutoBrackets(false);
-                if assigned(text) then
-                  for Temp := 1 to length(Text^) do
-                    begin
-                      AddChar(Text^[Temp]);
-                      if StartPos.X+Temp>Length(Line) then
-                        Text^[Temp]:=' '
-                      else
-                        Text^[Temp]:=Line[StartPos.X+Temp];
-                    end;
+                for Temp := 1 to length(uText) do
+                  begin
+                    AddChar(uText[Temp]);
+                    if StartPos.X+Temp>Length(Line) then
+                      uText[Temp]:=' '
+                    else
+                      uText[Temp]:=Line[StartPos.X+Temp];
+                  end;
                 SetAutoBrackets(WasAutoBrackets);
                 SetAutoBrackets(WasAutoBrackets);
                 SetInsertMode(WasInserting);
                 SetInsertMode(WasInserting);
                 SetMinMax(EndPos.Y);
                 SetMinMax(EndPos.Y);
@@ -1378,7 +1391,7 @@ begin
                 SetCurPtr(EndPos.X,EndPos.Y);
                 SetCurPtr(EndPos.X,EndPos.Y);
                 Line:=Copy(GetDisplayText(StartPos.Y),1,StartPos.X);
                 Line:=Copy(GetDisplayText(StartPos.Y),1,StartPos.X);
                 If Length(Line)<StartPos.X then
                 If Length(Line)<StartPos.X then
-                  Line:=Line+CharStr(' ',StartPos.X-length(Line))+GetStr(Text);
+                  Line:=Line+CharStr(' ',StartPos.X-length(Line))+uText;
                 SetDisplayText(StartPos.Y,Line+Copy(GetDisplayText(EndPos.Y),EndPos.X+1,255));
                 SetDisplayText(StartPos.Y,Line+Copy(GetDisplayText(EndPos.Y),EndPos.X+1,255));
                 SetMinMax(EndPos.Y);
                 SetMinMax(EndPos.Y);
                 SetCurPtr(0,EndPos.Y);
                 SetCurPtr(0,EndPos.Y);
@@ -1392,7 +1405,7 @@ begin
                 WasInserting:=GetInsertMode;
                 WasInserting:=GetInsertMode;
                 SetInsertMode(true);
                 SetInsertMode(true);
                 SetFlags(GetFlags or efNoIndent);
                 SetFlags(GetFlags or efNoIndent);
-                InsertLine(StartPos.Y,GetStr(Text));
+                InsertLine(StartPos.Y,uText);
                 SetInsertMode(WasInserting);
                 SetInsertMode(WasInserting);
                 if not HadefNoIndent then
                 if not HadefNoIndent then
                   SetFlags(GetFlags and not efNoIndent);
                   SetFlags(GetFlags and not efNoIndent);
@@ -1455,7 +1468,7 @@ var
   Temp,Idx,i,Last,Count : Longint;
   Temp,Idx,i,Last,Count : Longint;
   StoredFlags : longint;
   StoredFlags : longint;
   WasInserting,WasAutoBrackets,IsGrouped,ShouldInsertText : boolean;
   WasInserting,WasAutoBrackets,IsGrouped,ShouldInsertText : boolean;
-  Line : String;
+  Line,uText : sw_aString;
   MaxY,MinY : sw_integer;
   MaxY,MinY : sw_integer;
   procedure SetMinMax(y : sw_integer);
   procedure SetMinMax(y : sw_integer);
     begin
     begin
@@ -1490,6 +1503,7 @@ begin
     for Idx:=Last downto Last-Count+1 do
     for Idx:=Last downto Last-Count+1 do
     with Core^.RedoList^.At(Idx)^ do
     with Core^.RedoList^.At(Idx)^ do
     begin
     begin
+      uText:=GetText;
       case action of
       case action of
         eaMoveCursor :
         eaMoveCursor :
           begin
           begin
@@ -1499,13 +1513,13 @@ begin
         eaInsertText :
         eaInsertText :
           begin
           begin
             SetCurPtr(startpos.x,startpos.y);
             SetCurPtr(startpos.x,startpos.y);
-            InsertText(GetStr(Text));
+            InsertText(uText);
             SetMinMax(StartPos.Y);
             SetMinMax(StartPos.Y);
           end;
           end;
         eaDeleteText :
         eaDeleteText :
           begin
           begin
             SetCurPtr(EndPos.X,EndPos.Y);
             SetCurPtr(EndPos.X,EndPos.Y);
-            for Temp := 1 to length(GetStr(Text)) do
+            for Temp := 1 to length(uText) do
               DelChar;
               DelChar;
             SetMinMax(EndPos.Y);
             SetMinMax(EndPos.Y);
           end;
           end;
@@ -1517,15 +1531,14 @@ begin
             SetInsertMode(false);
             SetInsertMode(false);
             WasAutoBrackets:=GetAutoBrackets;
             WasAutoBrackets:=GetAutoBrackets;
             SetAutoBrackets(false);
             SetAutoBrackets(false);
-            if assigned(text) then
-              for Temp := 1 to length(Text^) do
-                begin
-                  AddChar(Text^[Temp]);
-                  if StartPos.X+Temp>Length(Line) then
-                    Text^[Temp]:=' '
-                  else
-                    Text^[Temp]:=Line[StartPos.X+Temp];
-                end;
+            for Temp := 1 to length(uText) do
+              begin
+                AddChar(uText[Temp]);
+                if StartPos.X+Temp>Length(Line) then
+                  uText[Temp]:=' '
+                else
+                  uText[Temp]:=Line[StartPos.X+Temp];
+              end;
             SetAutoBrackets(WasAutoBrackets);
             SetAutoBrackets(WasAutoBrackets);
             SetInsertMode(WasInserting);
             SetInsertMode(WasInserting);
             SetCurPtr(EndPos.X,EndPos.Y);
             SetCurPtr(EndPos.X,EndPos.Y);
@@ -1538,7 +1551,7 @@ begin
             SetFlags(Flags);
             SetFlags(Flags);
             InsertNewLine;
             InsertNewLine;
             SetCurPtr(0,EndPos.Y);
             SetCurPtr(0,EndPos.Y);
-            Line:=GetStr(Text);
+            Line:=uText;
             ShouldInsertText:=false;
             ShouldInsertText:=false;
             for I:=1 to Length(Line) do
             for I:=1 to Length(Line) do
               if Line[I]<>' ' then
               if Line[I]<>' ' then
@@ -1557,7 +1570,7 @@ begin
             if EndPos.Y=StartPos.Y-1 then
             if EndPos.Y=StartPos.Y-1 then
             SetDisplayText(EndPos.Y,RExpand(
             SetDisplayText(EndPos.Y,RExpand(
               copy(GetDisplayText(EndPos.Y),1,EndPos.X),EndPos.X)
               copy(GetDisplayText(EndPos.Y),1,EndPos.X),EndPos.X)
-              +GetStr(Text));
+              +uText);
             SetCurPtr(EndPos.X,EndPos.Y);
             SetCurPtr(EndPos.X,EndPos.Y);
             SetMinMax(StartPos.Y);
             SetMinMax(StartPos.Y);
             SetMinMax(EndPos.Y);
             SetMinMax(EndPos.Y);
@@ -1722,7 +1735,7 @@ begin
   UpdateAttrsRange:=Core^.UpdateAttrsRange(FromLine,ToLine,Attrs);
   UpdateAttrsRange:=Core^.UpdateAttrsRange(FromLine,ToLine,Attrs);
 end;
 end;
 
 
-procedure TCodeEditor.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint);
+procedure TCodeEditor.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint);
 begin
 begin
   Core^.AddAction(AAction,AStartPos,AEndPos,AText,AFlags);
   Core^.AddAction(AAction,AStartPos,AEndPos,AText,AFlags);
 end;
 end;

File diff suppressed because it is too large
+ 199 - 140
packages/ide/weditor.pas


+ 9 - 8
packages/ide/whlpview.pas

@@ -154,8 +154,8 @@ type
         procedure   SetCurPtr(X,Y: sw_integer); virtual;
         procedure   SetCurPtr(X,Y: sw_integer); virtual;
         function    GetLineCount: sw_integer; virtual;
         function    GetLineCount: sw_integer; virtual;
         function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
         function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
-        function    GetLineText(Line: sw_integer): string; virtual;
-        function    GetDisplayText(I: sw_integer): string; virtual;
+        function    GetLineText(Line: sw_integer): sw_astring; virtual;
+        function    GetDisplayText(I: sw_integer): sw_astring; virtual;
         function    GetLinkCount: sw_integer; virtual;
         function    GetLinkCount: sw_integer; virtual;
         procedure   GetLinkBounds(Index: sw_integer; var R: TRect); virtual;
         procedure   GetLinkBounds(Index: sw_integer; var R: TRect); virtual;
         function    GetLinkFileID(Index: sw_integer): word; virtual;
         function    GetLinkFileID(Index: sw_integer): word; virtual;
@@ -828,13 +828,13 @@ begin
   {Abstract; used in wcedit unit ! }
   {Abstract; used in wcedit unit ! }
   GetLine:=nil;
   GetLine:=nil;
 end;
 end;
-function THelpViewer.GetDisplayText(I: sw_integer): string;
+function THelpViewer.GetDisplayText(I: sw_integer): sw_astring;
 begin
 begin
   GetDisplayText:=ExtractTabs(GetLineText(I),DefaultTabSize);
   GetDisplayText:=ExtractTabs(GetLineText(I),DefaultTabSize);
 end;
 end;
 
 
-function THelpViewer.GetLineText(Line: sw_integer): string;
-var S: string;
+function THelpViewer.GetLineText(Line: sw_integer): sw_astring;
+var S: sw_astring;
 begin
 begin
   if HelpTopic=nil then S:='' else S:=HelpTopic^.GetLineText(Line);
   if HelpTopic=nil then S:='' else S:=HelpTopic^.GetLineText(Line);
   GetLineText:=S;
   GetLineText:=S;
@@ -887,7 +887,7 @@ begin
   begin
   begin
     if Y=R.A.Y then StartX:=R.A.X else StartX:=Margin;
     if Y=R.A.Y then StartX:=R.A.X else StartX:=Margin;
     if Y=R.B.Y then EndX:=R.B.X else EndX:=High(S);
     if Y=R.B.Y then EndX:=R.B.X else EndX:=High(S);
-    S:=S+copy(GetLineText(Y),StartX+1,EndX-StartX+1);
+    S:=S+copy(GetLineText(Y),StartX+1,EndX-StartX+1);   { Note: AnsiString to ShortString convertino}
     Inc(Y);
     Inc(Y);
   end;
   end;
   GetLinkText:=S;
   GetLinkText:=S;
@@ -1219,7 +1219,7 @@ var NormalColor, LinkColor,
     B: TDrawBuffer;
     B: TDrawBuffer;
     DX,DY,X,Y,I,MinX,MaxX,ScreenX: sw_integer;
     DX,DY,X,Y,I,MinX,MaxX,ScreenX: sw_integer;
     LastLinkDrawn,LastColorAreaDrawn: sw_integer;
     LastLinkDrawn,LastColorAreaDrawn: sw_integer;
-    S: string;
+    S: sw_astring;
     R: TRect;
     R: TRect;
     SelR : TRect;
     SelR : TRect;
     C,Mask: word;
     C,Mask: word;
@@ -1244,7 +1244,8 @@ begin
     MoveChar(B,' ',NormalColor,Size.X);
     MoveChar(B,' ',NormalColor,Size.X);
     if Y<GetLineCount then
     if Y<GetLineCount then
     begin
     begin
-      S:=copy(GetLineText(Y),Delta.X+1,High(S));
+      S:=GetLineText(Y);
+      S:=copy(S,Delta.X+1,Length(S));
       S:=copy(S,1,MaxViewWidth);
       S:=copy(S,1,MaxViewWidth);
       MoveStr(B,S,NormalColor);
       MoveStr(B,S,NormalColor);
 
 

+ 189 - 14
packages/ide/wutils.pas

@@ -46,11 +46,14 @@ const
   TempExt       = '.tmp';
   TempExt       = '.tmp';
   TempNameLen   = 8;
   TempNameLen   = 8;
 
 
-  { Get DirSep and EOL from System unit, instead of redefining 
+  { Get DirSep and EOL from System unit, instead of redefining
     here with tons of $ifdefs (KB) }
     here with tons of $ifdefs (KB) }
   DirSep : AnsiChar = System.DirectorySeparator;
   DirSep : AnsiChar = System.DirectorySeparator;
   EOL : String[2] = System.LineEnding;
   EOL : String[2] = System.LineEnding;
 
 
+type
+  Sw_AString = AnsiString;      { long lines in editor }
+  {Sw_AString = ShortString;}     { 255 char lines in editor }
 
 
 type
 type
   PByteArray = ^TByteArray;
   PByteArray = ^TByteArray;
@@ -99,7 +102,8 @@ type
   TFastBufStream = object(TBufStream)
   TFastBufStream = object(TBufStream)
     constructor Init (FileName: FNameStr; Mode, Size: Word);
     constructor Init (FileName: FNameStr; Mode, Size: Word);
     procedure   Seek(Pos: Longint); virtual;
     procedure   Seek(Pos: Longint); virtual;
-    procedure Readline(var s:string;var linecomplete,hasCR : boolean);
+    procedure Readline(var S:ShortString;var linecomplete,hasCR : boolean);
+    procedure Readline(var S:AnsiString;var linecomplete,hasCR : boolean);
   private
   private
     BasePos: longint;
     BasePos: longint;
   end;
   end;
@@ -119,7 +123,8 @@ type
     function  AtInt(Index: sw_integer): ptrint;
     function  AtInt(Index: sw_integer): ptrint;
   end;
   end;
 
 
-procedure ReadlnFromStream(Stream: PStream; var s:string;var linecomplete,hasCR : boolean);
+procedure ReadlnFromStream(Stream: PStream; var s:ShortString;var linecomplete,hasCR : boolean);
+procedure ReadlnFromStream(Stream: PStream; var s:AnsiString;var linecomplete,hasCR : boolean);
 function eofstream(s: pstream): boolean;
 function eofstream(s: pstream): boolean;
 procedure ReadlnFromFile(var f : file; var S:string;
 procedure ReadlnFromFile(var f : file; var S:string;
            var linecomplete,hasCR : boolean;
            var linecomplete,hasCR : boolean;
@@ -128,15 +133,20 @@ procedure ReadlnFromFile(var f : file; var S:string;
 function Min(A,B: longint): longint;
 function Min(A,B: longint): longint;
 function Max(A,B: longint): longint;
 function Max(A,B: longint): longint;
 
 
-function CharStr(C: AnsiChar; Count: integer): string;
+function CharStr(C: AnsiChar; Count: sw_integer): Sw_AString;
 function UpcaseStr(const S: string): string;
 function UpcaseStr(const S: string): string;
+function UpcaseStr(const S: AnsiString): AnsiString;
 function LowCase(C: AnsiChar): AnsiChar;
 function LowCase(C: AnsiChar): AnsiChar;
 function LowcaseStr(S: string): string;
 function LowcaseStr(S: string): string;
-function RExpand(const S: string; MinLen: byte): string;
+function LowcaseStr(S: AnsiString): AnsiString;
+function RExpand(const S: Sw_AString; MinLen: sw_integer): Sw_AString;
 function LExpand(const S: string; MinLen: byte): string;
 function LExpand(const S: string; MinLen: byte): string;
 function LTrim(const S: string): string;
 function LTrim(const S: string): string;
+function LTrim(const S: AnsiString): AnsiString;
 function RTrim(const S: string): string;
 function RTrim(const S: string): string;
+function RTrim(const S: AnsiString): AnsiString;
 function Trim(const S: string): string;
 function Trim(const S: string): string;
+function Trim(const S: AnsiString): AnsiString;
 function IntToStr(L: longint): string;
 function IntToStr(L: longint): string;
 function IntToStrL(L: longint; MinLen: sw_integer): string;
 function IntToStrL(L: longint; MinLen: sw_integer): string;
 function IntToStrZ(L: longint; MinLen: sw_integer): string;
 function IntToStrZ(L: longint; MinLen: sw_integer): string;
@@ -232,10 +242,11 @@ begin
   eofstream:=(s^.getpos>=s^.getsize);
   eofstream:=(s^.getpos>=s^.getsize);
 end;
 end;
 
 
-procedure ReadlnFromStream(Stream: PStream; var S:string;var linecomplete,hasCR : boolean);
+procedure ReadlnFromStream(Stream: PStream; var S:ShortString;var linecomplete,hasCR : boolean);
   var
   var
     c : AnsiChar;
     c : AnsiChar;
     i,pos : longint;
     i,pos : longint;
+    CurLen : longword;
   begin
   begin
     linecomplete:=false;
     linecomplete:=false;
     c:=#0;
     c:=#0;
@@ -269,12 +280,54 @@ procedure ReadlnFromStream(Stream: PStream; var S:string;var linecomplete,hasCR
         if c<>#10 then
         if c<>#10 then
           stream^.seek(pos);
           stream^.seek(pos);
       end;
       end;
+    if (c=#10) or eofstream(stream) then
+      linecomplete:=true;
+    if (c=#10) then
+      hasCR:=true;
+    setlength(s,i);
+  end;
 
 
+procedure ReadlnFromStream(Stream: PStream; var S:AnsiString;var linecomplete,hasCR : boolean);
+  var
+    c : AnsiChar;
+    i,pos : longint;
+    CurLen : longword;
+  begin
+    linecomplete:=false;
+    c:=#0;
+    i:=0;
+    CurLen:=256;
+    SetLength(S,CurLen);
+    { this created problems for lines longer than 255 characters
+      now those lines are cutted into pieces without warning PM }
+    { changed implicit 255 to High(S), so it will be automatically extended
+      when longstrings eventually become default - Gabor }
+    while (not eofstream(stream)) and (c<>#10) {and (i<High(S))} do
+     begin
+       stream^.read(c,sizeof(c));
+       if c<>#10 then
+        begin
+          inc(i);
+          s[i]:=c;
+          if (i mod 256)=0 then
+          begin
+            CurLen:=CurLen+256;
+            SetLength(S,CurLen);
+          end;
+        end;
+     end;
+    { if there was a CR LF then remove the CR Dos newline style }
+    if (i>0) and (s[i]=#13) then
+      begin
+        dec(i);
+      end;
+    if (c=#13) and (not eofstream(stream)) then
+      stream^.read(c,sizeof(c));
     if (c=#10) or eofstream(stream) then
     if (c=#10) or eofstream(stream) then
       linecomplete:=true;
       linecomplete:=true;
     if (c=#10) then
     if (c=#10) then
       hasCR:=true;
       hasCR:=true;
-    setlength(s,i);  
+    setlength(s,i);
   end;
   end;
 
 
 procedure ReadlnFromFile(var f : file; var S:string;
 procedure ReadlnFromFile(var f : file; var S:string;
@@ -329,7 +382,7 @@ procedure ReadlnFromFile(var f : file; var S:string;
            (LastSpacePos>1) then
            (LastSpacePos>1) then
           begin
           begin
 {$ifdef DEBUG}
 {$ifdef DEBUG}
-            setlength(s,i); 
+            setlength(s,i);
             filename:=strpas(@(filerec(f).Name));
             filename:=strpas(@(filerec(f).Name));
             DebugMessage(filename,'s='+s,1,1);
             DebugMessage(filename,'s='+s,1,1);
 {$endif DEBUG}
 {$endif DEBUG}
@@ -372,16 +425,18 @@ begin
   if A<B then Min:=A else Min:=B;
   if A<B then Min:=A else Min:=B;
 end;
 end;
 
 
-function CharStr(C: AnsiChar; Count: integer): string;
+function CharStr(C: AnsiChar; Count: sw_integer): Sw_AString;
 begin
 begin
   if Count<=0 then
   if Count<=0 then
     begin
     begin
       CharStr:='';
       CharStr:='';
       exit;
       exit;
     end
     end
+{$if sizeof(sw_astring)>8  only if ShortString}
   else if Count>255 then
   else if Count>255 then
     Count:=255;
     Count:=255;
-  setlength(CharStr,Count);
+{$endif};
+  SetLength(CharStr,Count);
   FillChar(CharStr[1],Count,C);
   FillChar(CharStr[1],Count,C);
 end;
 end;
 
 
@@ -397,7 +452,19 @@ begin
   Setlength(UpcaseStr,length(s));
   Setlength(UpcaseStr,length(s));
 end;
 end;
 
 
-function RExpand(const S: string; MinLen: byte): string;
+function UpcaseStr(const S: AnsiString): AnsiString;
+var
+  I: Longint;
+begin
+  Setlength(UpcaseStr,length(s));
+  for I:=1 to length(S) do
+    if S[I] in ['a'..'z'] then
+      UpCaseStr[I]:=chr(ord(S[I])-32)
+    else
+      UpCaseStr[I]:=S[I];
+end;
+
+function RExpand(const S: Sw_AString; MinLen: sw_integer): Sw_AString;
 begin
 begin
   if length(S)<MinLen then
   if length(S)<MinLen then
     RExpand:=S+CharStr(' ',MinLen-length(S))
     RExpand:=S+CharStr(' ',MinLen-length(S))
@@ -446,6 +513,39 @@ begin
   Trim:=Copy(S,i,j-i+1);
   Trim:=Copy(S,i,j-i+1);
 end;
 end;
 
 
+function LTrim(const S: AnsiString): AnsiString;
+var
+  i : longint;
+begin
+  i:=1;
+  while (i<length(s)) and (s[i]=' ') do
+   inc(i);
+  LTrim:=Copy(s,i,length(S));
+end;
+
+function RTrim(const S: AnsiString): AnsiString;
+var
+  i : longint;
+begin
+  i:=length(s);
+  while (i>0) and (s[i]=' ') do
+   dec(i);
+  RTrim:=Copy(s,1,i);
+end;
+
+function Trim(const S: AnsiString): AnsiString;
+var
+  i,j : longint;
+begin
+  i:=1;
+  while (i<length(s)) and (s[i]=' ') do
+   inc(i);
+  j:=length(s);
+  while (j>0) and (s[j]=' ') do
+   dec(j);
+  Trim:=Copy(S,i,j-i+1);
+end;
+
 function IntToStr(L: longint): string;
 function IntToStr(L: longint): string;
 var S: string;
 var S: string;
 begin
 begin
@@ -666,6 +766,14 @@ begin
   LowcaseStr:=S;
   LowcaseStr:=S;
 end;
 end;
 
 
+function LowcaseStr(S: AnsiString): AnsiString;
+var I: Longint;
+begin
+  SetLength(LowcaseStr,length(S));
+  for I:=1 to length(S) do
+      LowcaseStr[I]:=Lowcase(S[I]);
+end;
+
 
 
 function BoolToStr(B: boolean; const TrueS, FalseS: string): string;
 function BoolToStr(B: boolean; const TrueS, FalseS: string): string;
 begin
 begin
@@ -849,7 +957,7 @@ begin
     end;
     end;
 end;
 end;
 
 
-procedure TFastBufStream.Readline(var s:string;var linecomplete,hasCR : boolean);
+procedure TFastBufStream.Readline(var S:ShortString;var linecomplete,hasCR : boolean);
   var
   var
     c : AnsiChar;
     c : AnsiChar;
     i,pos,StartPos : longint;
     i,pos,StartPos : longint;
@@ -914,11 +1022,78 @@ procedure TFastBufStream.Readline(var s:string;var linecomplete,hasCR : boolean)
     if (c=#10) or (getpos>=getsize) then
     if (c=#10) or (getpos>=getsize) then
       linecomplete:=true;
       linecomplete:=true;
     if (c=#10) then
     if (c=#10) then
-      hasCR:=true; 
-    setlength(s,i);    
+      hasCR:=true;
+    setlength(s,i);
   end;
   end;
 
 
+procedure TFastBufStream.Readline(var S:AnsiString;var linecomplete,hasCR : boolean);
+  var
+    c : char;
+    i,pos,StartPos : longint;
+    charsInS : boolean;
+    Len,Idx : sw_integer;
+  begin
+    linecomplete:=false;
+    c:=#0;
+    i:=0;
+
+    CharsInS:=false;
+    Len:=bufend-bufptr;
+    Idx:=-1;
+    if Len>0 then
+      Idx:=IndexByte(buffer^[bufptr],Len, 10)+1; {find end of line}
+    Len:=Min(Idx,Len);
+
+    SetLength(S,Len);
+    if (Len > 0) and (GetPos+Len<GetSize) then
+    begin
+      StartPos:=GetPos;
+      system.move(buffer^[bufptr],S[1],Len); {get full line}
+      charsInS:=true;
+    end;
 
 
+    while (CharsInS or not (getpos>=getsize)) and (c<>#10) do
+     begin
+       if CharsInS then
+         c:=s[i+1]
+       else
+         read(c,sizeof(c));
+       if c<>#10 then
+        begin
+          inc(i);
+          if not CharsInS then
+          begin
+            if i > Len then
+            begin
+              Len:=Len+256; {constant grow}
+              SetLength(S,Len);
+            end;
+            s[i]:=c;
+          end;
+        end;
+     end;
+    if CharsInS then
+      begin
+        if c=#10 then
+          Seek(StartPos+i+1)
+        else
+          Seek(StartPos+i);
+      end;
+    { if there was a CR LF then remove the CR Dos newline style }
+    if (i>0) and (s[i]=#13) then
+      begin
+        dec(i);
+      end;
+    if (c=#13) and (not (getpos>=getsize)) then
+      begin
+        read(c,sizeof(c));
+      end;
+    if (c=#10) or (getpos>=getsize) then
+      linecomplete:=true;
+    if (c=#10) then
+      hasCR:=true;
+    setlength(s,i);
+  end;
 
 
 function TTextCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
 function TTextCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
 var K1: PString absolute Key1;
 var K1: PString absolute Key1;

Some files were not shown because too many files changed in this diff