LazUtils: Move string manipulation functions from IDEProcs to LazStringUtils.

git-svn-id: trunk@58632 -
This commit is contained in:
juha 2018-07-25 13:39:06 +00:00
parent 5c561fabd8
commit 6d3f9bd7a7
28 changed files with 836 additions and 864 deletions

View File

@ -16,10 +16,52 @@ unit LazStringUtils;
interface
uses
Classes, SysUtils;
Classes, SysUtils,
// LazUtils
LazUTF8, LazLoggerBase, LazTracer;
type
// comments
TCommentType = (
comtDefault, // decide automatically
comtNone, // no comment
comtPascal, // {}
comtDelphi, // //
comtTurboPascal,// (* *)
comtCPP, // /* */
comtPerl, // #
comtHtml // <!-- -->
);
TCommentTypes = set of TCommentType;
const
EndOfLine: shortstring = LineEnding;
function LineEndingCount(const Txt: string; var LengthOfLastLine: integer): integer;
function ChangeLineEndings(const s, NewLineEnding: string): string;
function TabsToSpaces(const s: string; TabWidth: integer; UseUTF8: boolean): string;
//function CommentLines(const s: string): string;
function CommentText(const s: string; CommentType: TCommentType): string;
//function UncommentLines(const s: string): string;
//function CrossReplaceChars(const Src: string; PrefixChar: char;
// const SpecialChars: string): string;
function SimpleSyntaxToRegExpr(const Src: string): string;
function BinaryStrToText(const s: string): string;
function SplitString(const s: string; Delimiter: char): TStrings;
procedure SplitString(const s: string; Delimiter: char; AddTo: TStrings;
ClearList: boolean = true);
function SpecialCharsToSpaces(const s: string; FixUTF8: boolean): string;
function SpecialCharsToHex(const s: string): string;
function LineBreaksToSystemLineBreaks(const s: string): string;
function LineBreaksToDelimiter(const s: string; Delimiter: char): string;
function StringListToText(List: TStrings; const Delimiter: string;
IgnoreEmptyLines: boolean = false): string;
function StringListPartToText(List: TStrings; FromIndex, ToIndex: integer;
const Delimiter: string;
IgnoreEmptyLines: boolean = false): string;
function StringListToString(List: TStrings; FromIndex, ToIndex: integer;
IgnoreEmptyLines: boolean = false): string;
procedure StringToStringList(const s: string; List: TStrings);
implementation
@ -101,5 +143,742 @@ begin
//if Src-1<>@s[length(s)] then RaiseGDBException('');
end;
function TabsToSpaces(const s: string; TabWidth: integer; UseUTF8: boolean): string;
// Convert all tabs to TabWidth number of spaces.
function ConvertTabsToSpaces(const Src: string; var Dest: string): integer;
var
SrcLen: Integer;
SrcPos: Integer;
PhysicalX: Integer;
CurTabWidth: Integer;
i: Integer;
CharLen: Integer;
DestPos: Integer;
begin
//DebugLn('ConvertTabsToSpaces ',dbgs(length(Dest)));
SrcLen:=length(Src);
SrcPos:=1;
DestPos:=1;
PhysicalX:=1;
while (SrcPos<=SrcLen) do begin
if (SrcPos and $fffff)=0 then
DebugLn('ConvertTabsToSpaces ',dbgs(SrcPos));
case Src[SrcPos] of
#9:
begin
CurTabWidth:=TabWidth - ((PhysicalX-1) mod TabWidth);
for i:=1 to CurTabWidth do begin
if Dest<>'' then
Dest[DestPos]:=' ';
inc(DestPos);
end;
inc(PhysicalX,CurTabWidth);
inc(SrcPos);
end;
#10,#13:
begin
if Dest<>'' then
Dest[DestPos]:=Src[SrcPos];
inc(SrcPos);
inc(DestPos);
if (SrcPos<=SrcLen) and (s[SrcPos] in [#10,#13])
and (s[SrcPos-1]<>s[SrcPos]) then
inc(SrcPos);
PhysicalX:=1;
end;
else
begin
if Dest<>'' then
Dest[DestPos]:=Src[SrcPos];
inc(PhysicalX);
if UseUTF8 then
CharLen:=UTF8CodepointSize(@s[SrcPos])
else
CharLen:=1;
for i:=1 to CharLen do begin
if Dest<>'' then
Dest[DestPos]:=Src[SrcPos];
inc(DestPos);
inc(SrcPos);
end;
end;
end;
end;
Result:=DestPos-1;
end;
var
NewLen: LongInt;
begin
Result:='';
NewLen:=ConvertTabsToSpaces(s,Result);
if NewLen=length(s) then
Result:=s
else begin
SetLength(Result,NewLen);
ConvertTabsToSpaces(s,Result);
end;
//DebugLn('TabsToSpaces ',dbgs(length(Result)));
end;
{
function CommentLines(const s: string): string;
// Comment every line with a Delphicomment //
var
CurPos: integer;
Dest: string;
procedure FindLineEnd;
begin
while (CurPos<=length(Dest))
and (not (Dest[CurPos] in [#10,#13])) do
inc(CurPos);
end;
procedure CommentLine;
begin
Dest:=LeftStr(Dest,CurPos-1)+'//'+RightStr(Dest,length(Dest)-CurPos+1);
FindLineEnd;
end;
begin
Dest:=s;
CurPos:=1;
// find code start in line
while (CurPos<=length(Dest)) do begin
case Dest[CurPos] of
' ',#9:
// skip space
inc(CurPos);
#10,#13:
// line end found -> skip
inc(CurPos);
else
// code start found
CommentLine;
end;
end;
Result:=Dest;
end;
}
function CommentText(const s: string; CommentType: TCommentType): string;
// Comment s.
procedure GetTextInfo(out Len, LineCount: integer; out LastLineEmpty: boolean);
var
p: integer;
begin
Len:=length(s);
LineCount:=1;
p:=1;
while p<=Len do
if not (s[p] in [#10,#13]) then begin
inc(p);
end else begin
inc(p);
inc(LineCount);
if (p<=Len) and (s[p] in [#10,#13]) and (s[p]<>s[p-1]) then
inc(p);
end;
LastLineEmpty:=(Len=0) or (s[Len] in [#10,#13]);
end;
procedure DoCommentBlock(const FirstLineStart, LineStart, LastLine: string);
var
OldLen, NewLen, LineCount, OldPos, NewPos: integer;
LastLineEmpty: boolean;
begin
GetTextInfo(OldLen,LineCount,LastLineEmpty);
NewLen:=OldLen+length(FirstLineStart)
+(LineCount-1)*length(LineStart);
if LastLineEmpty then
dec(NewLen,length(LineStart))
else
inc(NewLen,length(EndOfLine));
if (LastLine<>'') then begin
inc(NewLen,length(LastLine)+length(EndOfLine));
end;
SetLength(Result,NewLen);
NewPos:=1;
OldPos:=1;
// add first line start
if FirstLineStart<>'' then begin
System.Move(FirstLineStart[1],Result[NewPos],length(FirstLineStart));
inc(NewPos,length(FirstLineStart));
end;
// copy all lines and add new linestart
while (OldPos<=OldLen) do begin
if (not (s[OldPos] in [#10,#13])) then begin
Result[NewPos]:=s[OldPos];
inc(OldPos);
inc(NewPos);
end else begin
Result[NewPos]:=s[OldPos];
inc(OldPos);
inc(NewPos);
if (OldPos<=OldLen) and (s[OldPos] in [#10,#13])
and (s[OldPos]<>s[OldPos-1]) then begin
Result[NewPos]:=s[OldPos];
inc(OldPos);
inc(NewPos);
end;
// start new line
if (LineStart<>'') and (OldPos<OldLen) then begin
System.Move(LineStart[1],Result[NewPos],length(LineStart));
inc(NewPos,length(LineStart));
end;
end;
end;
if not LastLineEmpty then begin
System.Move(EndOfLine[1],Result[NewPos],length(EndOfLine));
inc(NewPos,length(EndOfLine));
end;
// add last line
if LastLine<>'' then begin
System.Move(LastLine[1],Result[NewPos],length(LastLine));
inc(NewPos,length(LastLine));
System.Move(EndOfLine[1],Result[NewPos],length(EndOfLine));
inc(NewPos,length(EndOfLine));
end;
if NewPos<>NewLen+1 then
raise Exception.Create('IDEProcs.CommentText ERROR: '
+IntToStr(NewPos-1)+'<>'+IntToStr(NewLen));
end;
begin
Result:=s;
if CommentType=comtNone then exit;
if CommentType=comtDefault then CommentType:=comtPascal;
case CommentType of
comtPascal: DoCommentBlock('{ ',' ','}');
comtDelphi: DoCommentBlock('// ','// ','');
comtTurboPascal: DoCommentBlock('(* ',' * ',' *)');
comtCPP: DoCommentBlock('/* ',' * ',' */');
comtPerl: DoCommentBlock('# ','# ','');
comtHtml: DoCommentBlock('<!-- ',' ','-->');
end;
end;
{
function UncommentLines(const s: string): string;
// Uncomment every line with a Delphicomment //
var
CurPos: integer;
Dest: string;
procedure FindLineEnd;
begin
while (CurPos<=length(Dest))
and (not (Dest[CurPos] in [#10,#13])) do
inc(CurPos);
end;
procedure UncommentLine;
begin
Dest:=LeftStr(Dest,CurPos-1)+RightStr(Dest,length(Dest)-CurPos-1);
FindLineEnd;
end;
begin
Dest:=s;
CurPos:=1;
// find Delphi comment line
while (CurPos<=length(Dest)) do begin
case Dest[CurPos] of
' ',#9:
// skip space
inc(CurPos);
#10,#13:
// line end found -> skip
inc(CurPos);
else
// code start found
if (Dest[CurPos]='/') and (CurPos<length(Dest)) and (Dest[CurPos+1]='/')
then
UncommentLine;
FindLineEnd;
end;
end;
Result:=Dest;
end;
function CrossReplaceChars(const Src: string; PrefixChar: char;
const SpecialChars: string): string;
var
SrcLen, SrcPos: Integer;
DestLen: Integer;
c: Char;
NeedsChange: boolean;
DestPos: Integer;
begin
Result:=Src;
SrcLen:=length(Src);
SrcPos:=1;
DestLen:=SrcLen;
NeedsChange:=false;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
if (c<>PrefixChar) then begin
if System.Pos(c,SpecialChars)>=1 then begin
// in front of each SpecialChar will be a PrefixChar inserted
inc(DestLen);
NeedsChange:=true;
end;
inc(SrcPos);
end else begin
inc(SrcPos);
if (SrcPos<=SrcLen) and (System.Pos(Src[SrcPos],SpecialChars)>=1) then
begin
// each prefixed SpecialChars will be reduced
dec(DestLen);
NeedsChange:=true;
end;
inc(SrcPos);
end;
end;
if not NeedsChange then exit;
SetLength(Result,DestLen);
SrcPos:=1;
DestPos:=1;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
if (c<>PrefixChar) then begin
if System.Pos(c,SpecialChars)>=1 then begin
// in front of each SpecialChars will be PrefixChar inserted
Result[DestPos]:=PrefixChar;
inc(DestPos);
end;
Result[DestPos]:=c;
inc(SrcPos);
inc(DestPos);
end else begin
inc(SrcPos);
if SrcPos<=SrcLen then begin
if (System.Pos(Src[SrcPos],SpecialChars)<1) then begin
Result[DestPos]:=c;
inc(DestPos);
end;
Result[DestPos]:=Src[SrcPos];
inc(DestPos);
inc(SrcPos);
end else begin
Result[DestPos]:=c;
inc(DestPos);
end;
end;
end;
end;
}
function SimpleSyntaxToRegExpr(const Src: string): string;
// * -> .*
// ? -> .
// , -> |
// ; -> |
// Backslash characters .+
// Finally enclose by ^( )$
var
SrcLen, SrcPos: Integer;
DestLen: Integer;
c: Char;
DestPos: Integer;
begin
Result:=Src;
SrcLen:=length(Src);
SrcPos:=1;
DestLen:=SrcLen+4;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
case c of
'\': inc(SrcPos);
'*','.','+':
inc(DestLen);
end;
inc(SrcPos);
end;
SetLength(Result,DestLen);
SrcPos:=1;
Result[1]:='^';
Result[2]:='(';
DestPos:=3;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
case c of
'\':
begin
Result[DestPos]:=c;
inc(DestPos);
inc(SrcPos);
Result[DestPos]:=Src[SrcPos];
inc(DestPos);
end;
'.','+':
begin
Result[DestPos]:='\';
inc(DestPos);
Result[DestPos]:=c;
inc(DestPos);
end;
'*':
begin
Result[DestPos]:='.';
inc(DestPos);
Result[DestPos]:='*';
inc(DestPos);
end;
'?':
begin
Result[DestPos]:='.';
inc(DestPos);
end;
',',';':
begin
Result[DestPos]:='|';
inc(DestPos);
end;
else
Result[DestPos]:=Src[SrcPos];
inc(DestPos);
end;
inc(SrcPos);
end;
Result[DestPos]:=')';
inc(DestPos);
Result[DestPos]:='$';
end;
function BinaryStrToText(const s: string): string;
// Replaces special chars (<#32) into pascal char constants #xxx.
var
i, OldLen, NewLen, OldPos, NewPos: integer;
begin
OldLen:=length(s);
NewLen:=OldLen;
for i:=1 to OldLen do begin
if s[i]<' ' then begin
inc(NewLen); // one additional char for #
if ord(s[i])>9 then inc(NewLen);
if ord(s[i])>99 then inc(NewLen);
end;
end;
if OldLen=NewLen then begin
Result:=s;
exit;
end;
SetLength(Result,NewLen);
OldPos:=1;
NewPos:=1;
while OldPos<=OldLen do begin
if s[OldPos]>=' ' then begin
Result[NewPos]:=s[OldPos];
end else begin
Result[NewPos]:='#';
inc(NewPos);
i:=ord(s[OldPos]);
if i>99 then begin
Result[NewPos]:=chr((i div 100)+ord('0'));
inc(NewPos);
i:=i mod 100;
end;
if i>9 then begin
Result[NewPos]:=chr((i div 10)+ord('0'));
inc(NewPos);
i:=i mod 10;
end;
Result[NewPos]:=chr(i+ord('0'));
end;
inc(NewPos);
inc(OldPos);
end;
if NewPos-1<>NewLen then
RaiseGDBException('ERROR: BinaryStrToText: '+IntToStr(NewLen)+'<>'+IntToStr(NewPos-1));
end;
function SplitString(const s: string; Delimiter: char): TStrings;
begin
Result:=TStringList.Create;
SplitString(s,Delimiter,Result,false);
end;
procedure SplitString(const s: string; Delimiter: char; AddTo: TStrings;
ClearList: boolean);
var
SLen: Integer;
StartPos: Integer;
EndPos: Integer;
begin
if ClearList then
AddTo.Clear;
SLen:=length(s);
StartPos:=1;
EndPos:=1;
repeat
if (EndPos<=sLen) and (s[EndPos]<>Delimiter) then
inc(EndPos)
else begin
if EndPos>StartPos then
AddTo.Add(copy(s,StartPos,EndPos-StartPos));
StartPos:=EndPos+1;
if StartPos>sLen then exit;
inc(EndPos);
end;
until false;
end;
function SpecialCharsToSpaces(const s: string; FixUTF8: boolean): string;
// Converts illegal characters to spaces. Trim leading and trailing spaces.
var
i: Integer;
p: LongInt;
begin
Result:=s;
if Result='' then exit;
// convert line breaks to single spaces
i:=length(Result);
while (i>=1) do begin
if Result[i] in [#10,#13] then begin
Result[i]:=' ';
p:=i;
while (i>1) and (Result[i-1] in [#10,#13]) do dec(i);
if p>i then
System.Delete(Result,i,p-i);
end;
dec(i);
end;
// convert special characters to spaces
for i:=1 to length(Result) do
if Result[i] in [#0..#31,#127] then Result[i]:=' ';
if Result='' then exit;
if FixUTF8 then
UTF8FixBroken(Result);
Result:=UTF8Trim(Result);
end;
function SpecialCharsToHex(const s: string): string;
var
i: Integer;
begin
Result:=s;
if Result='' then exit;
for i:=length(Result) downto 1 do
if Result[i]<' ' then
Result:=copy(Result,1,i-1)
+'#'+Format('%d',[ord(Result[i])])
+copy(Result,i+1,length(Result));
end;
function LineBreaksToSystemLineBreaks(const s: string): string;
begin
Result:=ChangeLineEndings(s,LineEnding);
end;
function LineBreaksToDelimiter(const s: string; Delimiter: char): string;
var
p: Integer;
StartPos: LongInt;
begin
Result:=s;
p:=1;
while (p<=length(Result)) do begin
if Result[p] in [#10,#13] then begin
StartPos:=p;
repeat
inc(p);
until (p>length(Result)) or (not (Result[p] in [#10,#13]));
if p<=length(Result) then
Result:=copy(Result,1,StartPos-1)+Delimiter+copy(Result,p,length(Result))
else
Result:=copy(Result,1,StartPos-1);
end else begin
inc(p);
end;
end;
end;
function StringListToText(List: TStrings; const Delimiter: string;
IgnoreEmptyLines: boolean): string;
begin
if List=nil then
Result:=''
else
Result:=StringListPartToText(List,0,List.Count-1,Delimiter,IgnoreEmptyLines);
end;
function StringListPartToText(List: TStrings; FromIndex, ToIndex: integer;
const Delimiter: string; IgnoreEmptyLines: boolean): string;
var
i: Integer;
s: string;
Size: Integer;
p: Integer;
begin
if (List=nil) or (FromIndex>ToIndex) or (FromIndex>=List.Count) then begin
Result:='';
exit;
end;
if FromIndex<0 then FromIndex:=0;
if ToIndex>=List.Count then ToIndex:=List.Count-1;
// calculate size
Size:=0;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if Size>0 then
inc(Size,length(Delimiter));
inc(Size,length(s));
end;
// build string
SetLength(Result,Size);
p:=1;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if (p>1) and (Delimiter<>'') then begin
System.Move(Delimiter[1],Result[p],length(Delimiter));
inc(p,length(Delimiter));
end;
if s<>'' then begin
System.Move(s[1],Result[p],length(s));
inc(p,length(s));
end;
end;
end;
function StringListToString(List: TStrings; FromIndex, ToIndex: integer;
IgnoreEmptyLines: boolean): string;
// concatenates strings with #10 characters
// and quotes strings containing #10 with '
var
Size: PtrInt;
i: PtrInt;
s: string;
j: PtrInt;
p: PtrInt;
begin
if (List=nil) or (FromIndex>ToIndex) or (FromIndex>=List.Count) then begin
Result:='';
exit;
end;
if FromIndex<0 then FromIndex:=0;
if ToIndex>=List.Count then ToIndex:=List.Count-1;
// calculate size
Size:=0;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if Size>0 then
inc(Size);// adding #10 as delimiter
inc(Size,length(s));
if System.Pos(#10,s)>0 then begin
inc(Size,2);
for j:=1 to length(s) do begin
if s[j]='''' then
inc(Size);
end;
end;
end;
// build string
SetLength(Result,Size);
p:=1;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if p>1 then begin
Result[p]:=#10;
inc(p);
end;
if System.Pos(#10,s)<1 then begin
// just copy the string
if s<>'' then begin
System.Move(s[1],Result[p],length(s));
inc(p,length(s));
end;
end else begin
// quote
Result[p]:='''';
inc(p);
for j:=1 to length(s) do begin
if s[p]='''' then begin
Result[p]:='''';
inc(p);
end;
Result[p]:=s[j];
inc(p);
end;
Result[p]:='''';
inc(p);
end;
end;
//DebugLn(['StringListToString ',dbgstr(Result),' ',Size,' ',p]);
if Size<>p-1 then
RaiseGDBException('StringListToString');
end;
procedure StringToStringList(const s: string; List: TStrings);
var
p: PtrInt;
LineStartPos: PtrInt;
Size: PtrInt;
DstPos: PtrInt;
Line: string;
begin
if s='' then exit;
p:=1;
while true do begin
if s[p]='''' then begin
// quoted
Size:=0;
inc(p);
LineStartPos:=p;
while p<=length(s) do begin
if (s[p]='''') then begin
inc(p);
if (p>length(s)) or (s[p]<>'''') then break;
end;
inc(Size);
inc(p);
end;
SetLength(Line,Size);
p:=LineStartPos;
DstPos:=1;
while p<=length(s) do begin
if (s[p]='''') then begin
inc(p);
if (p>length(s)) or (s[p]<>'''') then break;
end;
Line[DstPos]:=s[p];
inc(DstPos);
inc(p);
end;
List.Add(Line);
// skip line end
if p>length(s) then exit;
if s[p]=#10 then
inc(p);
end else begin
// just copy the string
LineStartPos:=p;
while (p<=length(s)) and (s[p]<>#10) do inc(p);
List.Add(copy(s,LineStartPos,p-LineStartPos));
// skip line end
if p>length(s) then exit;
inc(p);
end;
if p>length(s) then begin
List.Add('');
exit;
end;
end;
end;
end.

View File

@ -37,7 +37,7 @@ uses
// CodeTools
CodeCache, CodeToolManager, FileProcs,
// LazUtils
LConvEncoding, LazFileUtils, LazFileCache, AvgLvlTree,
LConvEncoding, LazFileUtils, LazFileCache, LazStringUtils, AvgLvlTree,
// IDEIntf
IDEWindowIntf, SrcEditorIntf, IDEHelpIntf, IDEImagesIntf,
// IDE

View File

@ -39,7 +39,8 @@ uses
// CodeTools
CodeToolManager, DefineTemplates, CodeCache, LinkScanner, FileProcs,
// LazUtils
LConvEncoding, FileUtil, LazFileUtils, LazUTF8, LazUTF8Classes, AvgLvlTree,
LConvEncoding, FileUtil, LazFileUtils, LazUTF8, LazUTF8Classes, LazStringUtils,
AvgLvlTree,
// IDEIntf
ComponentReg, IDEDialogs, LazIDEIntf, PackageIntf, ProjectIntf,
IDEExternToolIntf, IDEOptEditorIntf,

View File

@ -11,13 +11,13 @@ uses
// LCL
LCLProc, LCLType, Forms, Controls, Graphics, ComCtrls, Dialogs, StdCtrls, ButtonPanel,
// LazUtils
LazFileUtils,
LazFileUtils, LazStringUtils,
// CodeTools
BasicCodeTools,
// IdeIntf
IDEHelpIntf, MacroDefIntf, LazIDEIntf, IDEUtils,
// IDE
IDEProcs, InputHistory, LazarusIDEStrConsts, EnvironmentOpts, TransferMacros;
InputHistory, LazarusIDEStrConsts, EnvironmentOpts, TransferMacros;
type

View File

@ -31,19 +31,21 @@ unit CheckLFMDlg;
interface
uses
// FCL+LCL
// FCL
Classes, SysUtils, Math, TypInfo, contnrs,
LCLProc, LResources, Forms, Controls,
Dialogs, Buttons, StdCtrls, ExtCtrls,
// components
SynHighlighterLFM, SynEdit, BasicCodeTools, CodeCache, CodeToolManager,
SynEditMiscClasses, LFMTrees,
// LCL
LCLProc, LResources, Forms, Controls, Dialogs, Buttons, StdCtrls, ExtCtrls,
// LazUtils
LazStringUtils,
// CodeTools
BasicCodeTools, CodeCache, CodeToolManager, LFMTrees,
// SynEdit
SynHighlighterLFM, SynEdit, SynEditMiscClasses,
// IDEIntf
IDEExternToolIntf, PackageIntf, IDEWindowIntf, PropEdits, PropEditUtils,
IDEMsgIntf, IDEDialogs, ComponentReg,
IDEMsgIntf, IDEImagesIntf, IDEDialogs, ComponentReg,
// IDE
CustomFormEditor, LazarusIDEStrConsts, IDEImagesIntf,
IDEProcs, EditorOptions, SourceMarks, JITForms;
CustomFormEditor, LazarusIDEStrConsts, EditorOptions, SourceMarks, JITForms;
type

View File

@ -34,12 +34,12 @@ uses
// LCL
LCLProc, Forms, Controls, Graphics, Dialogs, StdCtrls, ButtonPanel,
// LazUtils
FileUtil, LazFileUtils, Laz2_XMLCfg,
FileUtil, LazFileUtils, Laz2_XMLCfg, LazStringUtils,
// IdeIntf
IDEWindowIntf, IDEHelpIntf, IDEDialogs,
// IDE
LazarusIDEStrConsts, LazConf, TransferMacros, InputHistory,
ShowDeletingFilesDlg, IDEProcs;
IDEProcs, LazarusIDEStrConsts, LazConf, TransferMacros, InputHistory,
ShowDeletingFilesDlg;
type

View File

@ -41,6 +41,8 @@ uses
// LCL
LCLProc, LCLType, LCLIntf, LResources, LMessages, Forms, Controls,
Graphics, Dialogs, Themes, Buttons,
// LazUtils
LazStringUtils,
// SynEdit
SynEdit, SynEditKeyCmds,
// CodeTools
@ -49,7 +51,7 @@ uses
// IdeIntf
SrcEditorIntf, LazIDEIntf, IDEImagesIntf,
// IDE
IDEProcs, LazarusIDEStrConsts;
LazarusIDEStrConsts;
type

View File

@ -36,7 +36,7 @@ uses
LCLProc, Forms, Controls, Dialogs, ClipBrd, StdCtrls, ExtCtrls, Menus,
ButtonPanel, EditBtn,
// LazUtils
FileUtil, LazFileUtils, LazUTF8Classes, LazLoggerBase,
FileUtil, LazFileUtils, LazUTF8Classes, LazLoggerBase, LazStringUtils,
// synedit
SynEdit, SynHighlighterPas, SynEditAutoComplete,
// codetools
@ -44,7 +44,7 @@ uses
// IDEIntf
SrcEditorIntf, MenuIntf, IDEWindowIntf, LazIDEIntf, IDEHelpIntf, IDEDialogs,
// IDE
IDEProcs, LazarusIDEStrConsts, EditorOptions, CodeMacroSelect, CodeMacroPrompt;
LazarusIDEStrConsts, EditorOptions, CodeMacroSelect, CodeMacroPrompt;
type
TAutoCompleteOption = (

View File

@ -37,7 +37,7 @@ interface
uses
Classes, SysUtils,
// LazUtils
LazFileUtils, Laz2_XMLCfg, LazUTF8, LazUTF8Classes, LazFileCache,
LazFileUtils, Laz2_XMLCfg, LazUTF8, LazUTF8Classes, LazFileCache, LazStringUtils,
// LCL
LCLProc, LCLType,
// CodeTools
@ -45,7 +45,7 @@ uses
// IdeIntf
IDEOptionsIntf, IDEOptEditorIntf, MacroIntf,
// IDE
LazConf, LazarusIDEStrConsts, IDEProcs;
LazConf, LazarusIDEStrConsts;
const
DefaultIndentationFilename = 'laz_indentation.pas'; // in directory GetPrimaryConfigPath

View File

@ -47,6 +47,7 @@ uses
InterfaceBase, Forms, Controls,
// LazUtils
FileUtil, LazFileUtils, LazUTF8, Laz2_XMLCfg, Laz2_DOM, LazUtilities, LazTracer,
LazStringUtils,
// CodeTools
FileProcs, DefineTemplates, CodeToolsCfgScript, CodeToolManager,
KeywordFuncLists, BasicCodeTools, LinkScanner,

View File

@ -45,6 +45,7 @@ uses
Graphics, LCLProc, LResources, Forms, Dialogs, ComCtrls, LCLType,
// LazUtils
FileUtil, LazFileUtils, LazUTF8, LazClasses, LazUTF8Classes, Laz2_XMLCfg,
LazStringUtils,
// Synedit
SynEdit, SynEditAutoComplete, SynEditKeyCmds, SynEditTypes,
SynEditMiscClasses, SynBeautifier, SynEditTextTrimmer, SynEditMouseCmds,
@ -68,7 +69,7 @@ uses
IDECommands, SrcEditorIntf, IDEOptionsIntf, IDEOptEditorIntf, IDEDialogs,
EditorSyntaxHighlighterDef,
// IDE
SourceMarks, LazarusIDEStrConsts, IDEProcs, KeyMapping, LazConf;
SourceMarks, LazarusIDEStrConsts, KeyMapping, LazConf;
const
DefaultCompletionLongLineHintType = sclpExtendRightOnly;

View File

@ -39,11 +39,11 @@ uses
// LCL
Forms, Controls, Graphics, Dialogs, ExtCtrls, ButtonPanel,
// LazUtils
LazUTF8, LazTracer,
LazUTF8, LazTracer, LazStringUtils,
// CodeTools
BasicCodeTools, CodeToolManager, SourceChanger,
// IDE
LazarusIDEStrConsts, LazConf;
LazarusIDEStrConsts;
type
TEncloseSelectionType = (

View File

@ -41,7 +41,7 @@ uses
// LCL
Graphics, Controls, Forms, Dialogs, LCLProc,
// LazUtils
LazFileUtils, FileUtil, LazFileCache, LazConfigStorage, LazUTF8,
LazFileUtils, FileUtil, LazFileCache, LazConfigStorage, LazUTF8, LazStringUtils,
Laz2_XMLCfg, Laz2_DOM,
// CodeTools
FileProcs, SourceChanger, CodeCompletionTool,

View File

@ -38,7 +38,7 @@ uses
// CodeTools
FileProcs, CTUnitGraph, CodeTree, CodeCache, CodeToolManager, BasicCodeTools,
// LazUtils
LazFileUtils, LazFileCache, laz2_DOM, AvgLvlTree,
LazFileUtils, LazFileCache, laz2_DOM, LazStringUtils, AvgLvlTree,
// IdeIntf
LazIDEIntf, IDEWindowIntf, SrcEditorIntf, PackageIntf, IDEDialogs,
// IDE

View File

@ -28,10 +28,12 @@ uses
SysUtils,
// LCL
Dialogs, StdCtrls, EditBtn,
// LazUtils
LazStringUtils,
// IdeIntf
IDEOptionsIntf, IDEOptEditorIntf,
// IDE
EnvironmentOpts, LazarusIDEStrConsts, IDEProcs;
EnvironmentOpts, LazarusIDEStrConsts;
type

View File

@ -8,10 +8,12 @@ uses
SysUtils,
// LCL
Forms, Dialogs, StdCtrls, Buttons, EditBtn,
// LazUtils
LazStringUtils,
// IdeIntf
IDEOptionsIntf, IDEOptEditorIntf, IDEImagesIntf,
// IDE
Project, LazarusIDEStrConsts, IDEProcs, CodeHelp;
Project, LazarusIDEStrConsts, CodeHelp;
type

View File

@ -43,19 +43,6 @@ uses
IDECmdLine, LazConf;
type
// comments
TCommentType = (
comtDefault, // decide automatically
comtNone, // no comment
comtPascal, // {}
comtDelphi, // //
comtTurboPascal,// (* *)
comtCPP, // /* */
comtPerl, // #
comtHtml // <!-- -->
);
TCommentTypes = set of TCommentType;
// copy
TOnCopyFileMethod =
procedure(const Filename: string; var Copy: boolean;
@ -185,32 +172,6 @@ function PointToCfgStr(const Point: TPoint): string;
procedure CfgStrToPoint(const s: string; var Point: TPoint;
const DefaultPoint: TPoint);
// text conversion
function TabsToSpaces(const s: string; TabWidth: integer; UseUTF8: boolean
): string;
function CommentLines(const s: string): string;
function CommentText(const s: string; CommentType: TCommentType): string;
function UncommentLines(const s: string): string;
function CrossReplaceChars(const Src: string; PrefixChar: char;
const SpecialChars: string): string;
function SimpleSyntaxToRegExpr(const Src: string): string;
function BinaryStrToText(const s: string): string;
function SplitString(const s: string; Delimiter: char): TStrings;
procedure SplitString(const s: string; Delimiter: char; AddTo: TStrings;
ClearList: boolean = true);
function SpecialCharsToSpaces(const s: string; FixUTF8: boolean): string;
function SpecialCharsToHex(const s: string): string;
function LineBreaksToSystemLineBreaks(const s: string): string;
function LineBreaksToDelimiter(const s: string; Delimiter: char): string;
function StringListToText(List: TStrings; const Delimiter: string;
IgnoreEmptyLines: boolean = false): string;
function StringListPartToText(List: TStrings; FromIndex, ToIndex: integer;
const Delimiter: string;
IgnoreEmptyLines: boolean = false): string;
function StringListToString(List: TStrings; FromIndex, ToIndex: integer;
IgnoreEmptyLines: boolean = false): string;
procedure StringToStringList(const s: string; List: TStrings);
// environment
type
TParseString = record
@ -1444,426 +1405,6 @@ begin
Point.Y:=StrToIntDef(copy(s,p+1,length(s)-p),DefaultPoint.Y);
end;
{-------------------------------------------------------------------------------
TabsToSpaces
Params: const s: string; TabWidth: integer
Result: string
Convert all tabs to TabWidth number of spaces.
-------------------------------------------------------------------------------}
function TabsToSpaces(const s: string; TabWidth: integer; UseUTF8: boolean): string;
function ConvertTabsToSpaces(const Src: string; var Dest: string): integer;
var
SrcLen: Integer;
SrcPos: Integer;
PhysicalX: Integer;
CurTabWidth: Integer;
i: Integer;
CharLen: Integer;
DestPos: Integer;
begin
//DebugLn('ConvertTabsToSpaces ',dbgs(length(Dest)));
SrcLen:=length(Src);
SrcPos:=1;
DestPos:=1;
PhysicalX:=1;
while (SrcPos<=SrcLen) do begin
if (SrcPos and $fffff)=0 then
DebugLn('ConvertTabsToSpaces ',dbgs(SrcPos));
case Src[SrcPos] of
#9:
begin
CurTabWidth:=TabWidth - ((PhysicalX-1) mod TabWidth);
for i:=1 to CurTabWidth do begin
if Dest<>'' then
Dest[DestPos]:=' ';
inc(DestPos);
end;
inc(PhysicalX,CurTabWidth);
inc(SrcPos);
end;
#10,#13:
begin
if Dest<>'' then
Dest[DestPos]:=Src[SrcPos];
inc(SrcPos);
inc(DestPos);
if (SrcPos<=SrcLen) and (s[SrcPos] in [#10,#13])
and (s[SrcPos-1]<>s[SrcPos]) then
inc(SrcPos);
PhysicalX:=1;
end;
else
begin
if Dest<>'' then
Dest[DestPos]:=Src[SrcPos];
inc(PhysicalX);
if UseUTF8 then
CharLen:=UTF8CodepointSize(@s[SrcPos])
else
CharLen:=1;
for i:=1 to CharLen do begin
if Dest<>'' then
Dest[DestPos]:=Src[SrcPos];
inc(DestPos);
inc(SrcPos);
end;
end;
end;
end;
Result:=DestPos-1;
end;
var
NewLen: LongInt;
begin
Result:='';
NewLen:=ConvertTabsToSpaces(s,Result);
if NewLen=length(s) then
Result:=s
else begin
SetLength(Result,NewLen);
ConvertTabsToSpaces(s,Result);
end;
//DebugLn('TabsToSpaces ',dbgs(length(Result)));
end;
function SplitString(const s: string; Delimiter: char): TStrings;
begin
Result:=TStringList.Create;
SplitString(s,Delimiter,Result,false);
end;
procedure SplitString(const s: string; Delimiter: char; AddTo: TStrings;
ClearList: boolean);
var
SLen: Integer;
StartPos: Integer;
EndPos: Integer;
begin
if ClearList then
AddTo.Clear;
SLen:=length(s);
StartPos:=1;
EndPos:=1;
repeat
if (EndPos<=sLen) and (s[EndPos]<>Delimiter) then
inc(EndPos)
else begin
if EndPos>StartPos then
AddTo.Add(copy(s,StartPos,EndPos-StartPos));
StartPos:=EndPos+1;
if StartPos>sLen then exit;
inc(EndPos);
end;
until false;
end;
{-------------------------------------------------------------------------------
function SpecialCharsToSpaces(const s: string): string;
Converts illegal characters to spaces.
Trim leading and trailing spaces.
-------------------------------------------------------------------------------}
function SpecialCharsToSpaces(const s: string; FixUTF8: boolean): string;
var
i: Integer;
p: LongInt;
begin
Result:=s;
if Result='' then exit;
// convert line breaks to single spaces
i:=length(Result);
while (i>=1) do begin
if Result[i] in [#10,#13] then begin
Result[i]:=' ';
p:=i;
while (i>1) and (Result[i-1] in [#10,#13]) do dec(i);
if p>i then
System.Delete(Result,i,p-i);
end;
dec(i);
end;
// convert special characters to spaces
for i:=1 to length(Result) do
if Result[i] in [#0..#31,#127] then Result[i]:=' ';
if Result='' then exit;
if FixUTF8 then
UTF8FixBroken(Result);
Result:=UTF8Trim(Result);
end;
function SpecialCharsToHex(const s: string): string;
var
i: Integer;
begin
Result:=s;
if Result='' then exit;
for i:=length(Result) downto 1 do
if Result[i]<' ' then
Result:=copy(Result,1,i-1)
+'#'+Format('%d',[ord(Result[i])])
+copy(Result,i+1,length(Result));
end;
function LineBreaksToSystemLineBreaks(const s: string): string;
begin
Result:=ChangeLineEndings(s,LineEnding);
end;
function LineBreaksToDelimiter(const s: string; Delimiter: char): string;
var
p: Integer;
StartPos: LongInt;
begin
Result:=s;
p:=1;
while (p<=length(Result)) do begin
if Result[p] in [#10,#13] then begin
StartPos:=p;
repeat
inc(p);
until (p>length(Result)) or (not (Result[p] in [#10,#13]));
if p<=length(Result) then
Result:=copy(Result,1,StartPos-1)+Delimiter+copy(Result,p,length(Result))
else
Result:=copy(Result,1,StartPos-1);
end else begin
inc(p);
end;
end;
end;
function StringListToText(List: TStrings; const Delimiter: string;
IgnoreEmptyLines: boolean): string;
begin
if List=nil then
Result:=''
else
Result:=StringListPartToText(List,0,List.Count-1,Delimiter,IgnoreEmptyLines);
end;
function StringListPartToText(List: TStrings; FromIndex, ToIndex: integer;
const Delimiter: string; IgnoreEmptyLines: boolean): string;
var
i: Integer;
s: string;
Size: Integer;
p: Integer;
begin
if (List=nil) or (FromIndex>ToIndex) or (FromIndex>=List.Count) then begin
Result:='';
exit;
end;
if FromIndex<0 then FromIndex:=0;
if ToIndex>=List.Count then ToIndex:=List.Count-1;
// calculate size
Size:=0;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if Size>0 then
inc(Size,length(Delimiter));
inc(Size,length(s));
end;
// build string
SetLength(Result,Size);
p:=1;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if (p>1) and (Delimiter<>'') then begin
System.Move(Delimiter[1],Result[p],length(Delimiter));
inc(p,length(Delimiter));
end;
if s<>'' then begin
System.Move(s[1],Result[p],length(s));
inc(p,length(s));
end;
end;
end;
function StringListToString(List: TStrings; FromIndex, ToIndex: integer;
IgnoreEmptyLines: boolean): string;
// concatenates strings with #10 characters
// and quotes strings containing #10 with '
var
Size: PtrInt;
i: PtrInt;
s: string;
j: PtrInt;
p: PtrInt;
begin
if (List=nil) or (FromIndex>ToIndex) or (FromIndex>=List.Count) then begin
Result:='';
exit;
end;
if FromIndex<0 then FromIndex:=0;
if ToIndex>=List.Count then ToIndex:=List.Count-1;
// calculate size
Size:=0;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if Size>0 then
inc(Size);// adding #10 as delimiter
inc(Size,length(s));
if System.Pos(#10,s)>0 then begin
inc(Size,2);
for j:=1 to length(s) do begin
if s[j]='''' then
inc(Size);
end;
end;
end;
// build string
SetLength(Result,Size);
p:=1;
for i:=FromIndex to ToIndex do begin
s:=List[i];
if IgnoreEmptyLines and (s='') then continue;
if p>1 then begin
Result[p]:=#10;
inc(p);
end;
if System.Pos(#10,s)<1 then begin
// just copy the string
if s<>'' then begin
System.Move(s[1],Result[p],length(s));
inc(p,length(s));
end;
end else begin
// quote
Result[p]:='''';
inc(p);
for j:=1 to length(s) do begin
if s[p]='''' then begin
Result[p]:='''';
inc(p);
end;
Result[p]:=s[j];
inc(p);
end;
Result[p]:='''';
inc(p);
end;
end;
//DebugLn(['StringListToString ',dbgstr(Result),' ',Size,' ',p]);
if Size<>p-1 then
RaiseGDBException('StringListToString');
end;
procedure StringToStringList(const s: string; List: TStrings);
var
p: PtrInt;
LineStartPos: PtrInt;
Size: PtrInt;
DstPos: PtrInt;
Line: string;
begin
if s='' then exit;
p:=1;
while true do begin
if s[p]='''' then begin
// quoted
Size:=0;
inc(p);
LineStartPos:=p;
while p<=length(s) do begin
if (s[p]='''') then begin
inc(p);
if (p>length(s)) or (s[p]<>'''') then break;
end;
inc(Size);
inc(p);
end;
SetLength(Line,Size);
p:=LineStartPos;
DstPos:=1;
while p<=length(s) do begin
if (s[p]='''') then begin
inc(p);
if (p>length(s)) or (s[p]<>'''') then break;
end;
Line[DstPos]:=s[p];
inc(DstPos);
inc(p);
end;
List.Add(Line);
// skip line end
if p>length(s) then exit;
if s[p]=#10 then
inc(p);
end else begin
// just copy the string
LineStartPos:=p;
while (p<=length(s)) and (s[p]<>#10) do inc(p);
List.Add(copy(s,LineStartPos,p-LineStartPos));
// skip line end
if p>length(s) then exit;
inc(p);
end;
if p>length(s) then begin
List.Add('');
exit;
end;
end;
end;
{-------------------------------------------------------------------------------
function BinaryStrToText(const s: string): string;
Replaces special chars (<#32) into pascal char constants #xxx.
-------------------------------------------------------------------------------}
function BinaryStrToText(const s: string): string;
var
i, OldLen, NewLen, OldPos, NewPos: integer;
begin
OldLen:=length(s);
NewLen:=OldLen;
for i:=1 to OldLen do begin
if s[i]<' ' then begin
inc(NewLen); // one additional char for #
if ord(s[i])>9 then inc(NewLen);
if ord(s[i])>99 then inc(NewLen);
end;
end;
if OldLen=NewLen then begin
Result:=s;
exit;
end;
SetLength(Result,NewLen);
OldPos:=1;
NewPos:=1;
while OldPos<=OldLen do begin
if s[OldPos]>=' ' then begin
Result[NewPos]:=s[OldPos];
end else begin
Result[NewPos]:='#';
inc(NewPos);
i:=ord(s[OldPos]);
if i>99 then begin
Result[NewPos]:=chr((i div 100)+ord('0'));
inc(NewPos);
i:=i mod 100;
end;
if i>9 then begin
Result[NewPos]:=chr((i div 10)+ord('0'));
inc(NewPos);
i:=i mod 10;
end;
Result[NewPos]:=chr(i+ord('0'));
end;
inc(NewPos);
inc(OldPos);
end;
if NewPos-1<>NewLen then
RaiseGDBException('ERROR: BinaryStrToText: '+IntToStr(NewLen)+'<>'+IntToStr(NewPos-1));
end;
{-------------------------------------------------------------------------------
ConvertSpecialFileChars
@ -1889,207 +1430,6 @@ begin
end;
end;
{-------------------------------------------------------------------------------
function CommentLines(const s: string): string;
Comment every line with a Delphicomment //
-------------------------------------------------------------------------------}
function CommentLines(const s: string): string;
var
CurPos: integer;
Dest: string;
procedure FindLineEnd;
begin
while (CurPos<=length(Dest))
and (not (Dest[CurPos] in [#10,#13])) do
inc(CurPos);
end;
procedure CommentLine;
begin
Dest:=LeftStr(Dest,CurPos-1)+'//'+RightStr(Dest,length(Dest)-CurPos+1);
FindLineEnd;
end;
begin
Dest:=s;
CurPos:=1;
// find code start in line
while (CurPos<=length(Dest)) do begin
case Dest[CurPos] of
' ',#9:
// skip space
inc(CurPos);
#10,#13:
// line end found -> skip
inc(CurPos);
else
// code start found
CommentLine;
end;
end;
Result:=Dest;
end;
{-------------------------------------------------------------------------------
function CommentLines(const s: string; CommentType: TCommentType): string;
Comment s.
-------------------------------------------------------------------------------}
function CommentText(const s: string; CommentType: TCommentType): string;
procedure GetTextInfo(out Len, LineCount: integer; out LastLineEmpty: boolean);
var
p: integer;
begin
Len:=length(s);
LineCount:=1;
p:=1;
while p<=Len do
if not (s[p] in [#10,#13]) then begin
inc(p);
end else begin
inc(p);
inc(LineCount);
if (p<=Len) and (s[p] in [#10,#13]) and (s[p]<>s[p-1]) then
inc(p);
end;
LastLineEmpty:=(Len=0) or (s[Len] in [#10,#13]);
end;
procedure DoCommentBlock(const FirstLineStart, LineStart, LastLine: string);
var
OldLen, NewLen, LineCount, OldPos, NewPos: integer;
LastLineEmpty: boolean;
begin
GetTextInfo(OldLen,LineCount,LastLineEmpty);
NewLen:=OldLen+length(FirstLineStart)
+(LineCount-1)*length(LineStart);
if LastLineEmpty then
dec(NewLen,length(LineStart))
else
inc(NewLen,length(EndOfLine));
if (LastLine<>'') then begin
inc(NewLen,length(LastLine)+length(EndOfLine));
end;
SetLength(Result,NewLen);
NewPos:=1;
OldPos:=1;
// add first line start
if FirstLineStart<>'' then begin
System.Move(FirstLineStart[1],Result[NewPos],length(FirstLineStart));
inc(NewPos,length(FirstLineStart));
end;
// copy all lines and add new linestart
while (OldPos<=OldLen) do begin
if (not (s[OldPos] in [#10,#13])) then begin
Result[NewPos]:=s[OldPos];
inc(OldPos);
inc(NewPos);
end else begin
Result[NewPos]:=s[OldPos];
inc(OldPos);
inc(NewPos);
if (OldPos<=OldLen) and (s[OldPos] in [#10,#13])
and (s[OldPos]<>s[OldPos-1]) then begin
Result[NewPos]:=s[OldPos];
inc(OldPos);
inc(NewPos);
end;
// start new line
if (LineStart<>'') and (OldPos<OldLen) then begin
System.Move(LineStart[1],Result[NewPos],length(LineStart));
inc(NewPos,length(LineStart));
end;
end;
end;
if not LastLineEmpty then begin
System.Move(EndOfLine[1],Result[NewPos],length(EndOfLine));
inc(NewPos,length(EndOfLine));
end;
// add last line
if LastLine<>'' then begin
System.Move(LastLine[1],Result[NewPos],length(LastLine));
inc(NewPos,length(LastLine));
System.Move(EndOfLine[1],Result[NewPos],length(EndOfLine));
inc(NewPos,length(EndOfLine));
end;
if NewPos<>NewLen+1 then
raise Exception.Create('IDEProcs.CommentText ERROR: '
+IntToStr(NewPos-1)+'<>'+IntToStr(NewLen));
end;
begin
Result:=s;
if CommentType=comtNone then exit;
if CommentType=comtDefault then CommentType:=comtPascal;
case CommentType of
comtPascal: DoCommentBlock('{ ',' ','}');
comtDelphi: DoCommentBlock('// ','// ','');
comtTurboPascal: DoCommentBlock('(* ',' * ',' *)');
comtCPP: DoCommentBlock('/* ',' * ',' */');
comtPerl: DoCommentBlock('# ','# ','');
comtHtml: DoCommentBlock('<!-- ',' ','-->');
end;
end;
{-------------------------------------------------------------------------------
function CommentLines(const s: string): string;
Uncomment every line with a Delphicomment //
-------------------------------------------------------------------------------}
function UncommentLines(const s: string): string;
var
CurPos: integer;
Dest: string;
procedure FindLineEnd;
begin
while (CurPos<=length(Dest))
and (not (Dest[CurPos] in [#10,#13])) do
inc(CurPos);
end;
procedure UncommentLine;
begin
Dest:=LeftStr(Dest,CurPos-1)+RightStr(Dest,length(Dest)-CurPos-1);
FindLineEnd;
end;
begin
Dest:=s;
CurPos:=1;
// find Delphi comment line
while (CurPos<=length(Dest)) do begin
case Dest[CurPos] of
' ',#9:
// skip space
inc(CurPos);
#10,#13:
// line end found -> skip
inc(CurPos);
else
// code start found
if (Dest[CurPos]='/') and (CurPos<length(Dest)) and (Dest[CurPos+1]='/')
then
UncommentLine;
FindLineEnd;
end;
end;
Result:=Dest;
end;
function GetCurrentUserName: string;
begin
Result:=GetEnvironmentVariableUTF8('USER');
@ -2258,160 +1598,6 @@ begin
Result:=true;
end;
{------------------------------------------------------------------------------
function CrossReplaceChars(const Src: string; PrefixChar: char;
const SpecialChars: string): string;
------------------------------------------------------------------------------}
function CrossReplaceChars(const Src: string; PrefixChar: char;
const SpecialChars: string): string;
var
SrcLen, SrcPos: Integer;
DestLen: Integer;
c: Char;
NeedsChange: boolean;
DestPos: Integer;
begin
Result:=Src;
SrcLen:=length(Src);
SrcPos:=1;
DestLen:=SrcLen;
NeedsChange:=false;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
if (c<>PrefixChar) then begin
if System.Pos(c,SpecialChars)>=1 then begin
// in front of each SpecialChar will be a PrefixChar inserted
inc(DestLen);
NeedsChange:=true;
end;
inc(SrcPos);
end else begin
inc(SrcPos);
if (SrcPos<=SrcLen) and (System.Pos(Src[SrcPos],SpecialChars)>=1) then
begin
// each prefixed SpecialChars will be reduced
dec(DestLen);
NeedsChange:=true;
end;
inc(SrcPos);
end;
end;
if not NeedsChange then exit;
SetLength(Result,DestLen);
SrcPos:=1;
DestPos:=1;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
if (c<>PrefixChar) then begin
if System.Pos(c,SpecialChars)>=1 then begin
// in front of each SpecialChars will be PrefixChar inserted
Result[DestPos]:=PrefixChar;
inc(DestPos);
end;
Result[DestPos]:=c;
inc(SrcPos);
inc(DestPos);
end else begin
inc(SrcPos);
if SrcPos<=SrcLen then begin
if (System.Pos(Src[SrcPos],SpecialChars)<1) then begin
Result[DestPos]:=c;
inc(DestPos);
end;
Result[DestPos]:=Src[SrcPos];
inc(DestPos);
inc(SrcPos);
end else begin
Result[DestPos]:=c;
inc(DestPos);
end;
end;
end;
end;
{------------------------------------------------------------------------------
function SimpleSyntaxToRegExpr(const Src: string): string;
* -> .*
? -> .
, -> |
; -> |
Backslash characters .+
Finally enclose by ^( )$
------------------------------------------------------------------------------}
function SimpleSyntaxToRegExpr(const Src: string): string;
var
SrcLen, SrcPos: Integer;
DestLen: Integer;
c: Char;
DestPos: Integer;
begin
Result:=Src;
SrcLen:=length(Src);
SrcPos:=1;
DestLen:=SrcLen+4;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
case c of
'\': inc(SrcPos);
'*','.','+':
inc(DestLen);
end;
inc(SrcPos);
end;
SetLength(Result,DestLen);
SrcPos:=1;
Result[1]:='^';
Result[2]:='(';
DestPos:=3;
while (SrcPos<=SrcLen) do begin
c:=Src[SrcPos];
case c of
'\':
begin
Result[DestPos]:=c;
inc(DestPos);
inc(SrcPos);
Result[DestPos]:=Src[SrcPos];
inc(DestPos);
end;
'.','+':
begin
Result[DestPos]:='\';
inc(DestPos);
Result[DestPos]:=c;
inc(DestPos);
end;
'*':
begin
Result[DestPos]:='.';
inc(DestPos);
Result[DestPos]:='*';
inc(DestPos);
end;
'?':
begin
Result[DestPos]:='.';
inc(DestPos);
end;
',',';':
begin
Result[DestPos]:='|';
inc(DestPos);
end;
else
Result[DestPos]:=Src[SrcPos];
inc(DestPos);
end;
inc(SrcPos);
end;
Result[DestPos]:=')';
inc(DestPos);
Result[DestPos]:='$';
end;
function CompareMemStreamText(s1, s2: TMemoryStream): Boolean;
// compare text in s2, s2 ignoring line ends
var

View File

@ -29,11 +29,11 @@ uses
// LCL
Forms, Controls, StdCtrls, Menus,
// LazUtils
LazUTF8,
LazUTF8, LazStringUtils,
// CodeTools
CodeToolManager, CodeCache,
// IDE
IDEProcs, IDEOptionDefs, EnvironmentOpts, LazarusIDEStrConsts, Project, ProjectDefs;
IDEOptionDefs, EnvironmentOpts, LazarusIDEStrConsts, Project, ProjectDefs;
type

View File

@ -117,10 +117,6 @@ procedure LazConfSubstituteMacros(var s: string);
procedure AddFilenameToList(List: TStrings; const Filename: string;
SkipEmpty: boolean = true);
const
EmptyLine = LineEnding + LineEnding;
EndOfLine: shortstring = LineEnding;
const
ExitCodeRestartLazarus = 99;

View File

@ -72,6 +72,7 @@ uses
// use lazutf8, lazfileutils and lazfilecache after FileProcs and FileUtil
FileUtil, LazFileUtils, LazUtilities, LazUTF8, LazUTF8Classes, UTF8Process,
LConvEncoding, Laz2_XMLCfg, LazLoggerBase, LazLogger, LazFileCache, AvgLvlTree,
LazStringUtils,
LCLExceptionStacktrace,
// SynEdit
SynEdit, AllSynEdit, SynEditKeyCmds, SynEditMarks, SynEditHighlighter,

View File

@ -26,13 +26,13 @@ uses
LCLType, LCLProc, Forms, Controls, Buttons, StdCtrls, Dialogs, Menus, Graphics,
ButtonPanel, Clipbrd,
// LazUtils
FileUtil, LazFileUtils,
FileUtil, LazFileUtils, LazStringUtils,
// LazControls
ShortPathEdit,
// IdeIntf
MacroIntf, IDEImagesIntf,
// IDE
TransferMacros, GenericListSelect, LazarusIDEStrConsts, IDEProcs;
TransferMacros, GenericListSelect, LazarusIDEStrConsts;
type

View File

@ -37,9 +37,7 @@ interface
uses
Classes, SysUtils, RegExpr,
// LazUtils
LazFileUtils, Laz2_XMLCfg, LazLoggerBase, LazTracer,
// IDE
IDEProcs;
LazFileUtils, Laz2_XMLCfg, LazLoggerBase, LazTracer, LazStringUtils;
type
{ TPublishModuleOptions }

View File

@ -44,10 +44,11 @@ uses
// LazControls
TreeFilterEdit,
// LazUtils
LazUTF8, LazFileUtils, LazLoggerBase,
LazUTF8, LazFileUtils, LazLoggerBase, LazStringUtils,
// IdeIntf
IDEImagesIntf, IDECommands,
// IDE
IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts, InputHistory, IDEProcs,
Project, MainIntf, IDECommands, IDEImagesIntf;
IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts, InputHistory, Project, MainIntf;
type

View File

@ -39,13 +39,13 @@ uses
// LCL
Forms, Controls, Buttons, StdCtrls, ComCtrls, ExtCtrls,
// LazUtils
LazFileUtils, LazUTF8,
LazFileUtils, LazUTF8, LazStringUtils,
// CodeTools
CodeToolsCfgScript,
// IdeIntf
BaseIDEIntf, LazIDEIntf, IDEImagesIntf, CompOptsIntf, ProjectIntf, PackageIntf,
// IDE
LazarusIDEStrConsts, IDEProcs, Project, PackageDefs,
LazarusIDEStrConsts, Project, PackageDefs,
CompilerOptions, ModeMatrixOpts, MiscOptions;
type

View File

@ -4555,7 +4555,7 @@ begin
CommentType:=EditorOpts.HighlighterList[i].DefaultCommentType;
end;
end;
Result:=IDEProcs.CommentText(Txt,CommentType);
Result:=LazStringUtils.CommentText(Txt,CommentType);
end;
procedure TSourceEditor.InsertCharacterFromMap;

View File

@ -29,11 +29,11 @@ uses
// LCL
Forms, Controls, Dialogs, StdCtrls, ButtonPanel, EditBtn,
// LazUtils
FileProcs, LazFileUtils,
FileProcs, LazFileUtils, LazStringUtils,
// IdeIntf
IDEWindowIntf,
// IDE
IDEProcs, LazarusIDEStrConsts, PackageDefs;
LazarusIDEStrConsts, PackageDefs;
type

View File

@ -50,7 +50,7 @@ uses
Forms, Controls, Dialogs, LCLProc,
// LazUtils
FileUtil, LazFileCache, LazLoggerBase, LazUtilities, LazFileUtils, LazUTF8,
Laz2_XMLCfg, laz2_XMLRead, AvgLvlTree,
Laz2_XMLCfg, laz2_XMLRead, LazStringUtils, AvgLvlTree,
// codetools
FileProcs, DefineTemplates, CodeToolManager, CodeCache, DirectoryCacher,
BasicCodeTools, NonPascalCodeTools, SourceChanger,

View File

@ -50,7 +50,7 @@ uses
// LCL
Forms, Controls, Dialogs, Menus, ComCtrls, LResources,
// LazUtils
LazUTF8, Laz2_XMLCfg, LazUTF8Classes, LazTracer, LazUtilities,
LazUTF8, Laz2_XMLCfg, LazUTF8Classes, LazTracer, LazUtilities, LazStringUtils,
LazFileUtils, LazFileCache, StringHashList, Translations, AvgLvlTree,
// Codetools
CodeToolsConfig, CodeToolManager, CodeCache, BasicCodeTools,