style modernisation using helpers isEmpty & isNotEmpty

This commit is contained in:
Basile Burg 2016-01-11 01:09:21 +01:00
parent 3fa80be500
commit 0303d0f75f
22 changed files with 87 additions and 70 deletions

View File

@ -48,6 +48,11 @@ type
function isNotNil: boolean;
end;
TStringHelper = type helper for string
function isEmpty: boolean;
function isNotEmpty: boolean;
end;
(**
* Workaround for a TAsyncProcess Linux issue: OnTerminate event not called.
* An idle timer is started when executing and trigs the event if necessary.
@ -316,6 +321,16 @@ begin
exit(self <> nil);
end;
function TStringHelper.isEmpty: boolean;
begin
exit(self = '');
end;
function TStringHelper.isNotEmpty: boolean;
begin
exit(self <> '');
end;
{$IFDEF LINUX}
constructor TCheckedAsyncProcess.Create(aOwner: TComponent);
begin
@ -653,7 +668,7 @@ var
files: TStringList;
begin
result := false;
if aPath = '' then
if aPath.isEmpty then
exit;
//
if aPath[length(aPath)] = '*' then
@ -759,7 +774,7 @@ var
env: string;
begin
ext := extractFileExt(anExeName);
if ext = '' then
if ext.isEmpty then
anExeName += exeExt;
//full path already specified
if FileExists(anExeName) and (not FileExists(ExtractFileName(anExeName))) then
@ -1083,7 +1098,7 @@ end;
function isStringDisabled(const str: string): boolean;
begin
result := false;
if str = '' then
if str.isEmpty then
exit;
if str[1] = ';' then
result := true;

View File

@ -392,7 +392,7 @@ begin
if i = 0 then
updateServerlistening;
setLength(str, i);
if str <> '' then
if str.isNotEmpty then
begin
i := Pos(#9, str);
if i = -1 then

View File

@ -402,7 +402,7 @@ begin
if (fConfigs.Count <> 1) and (fConfigs.Strings[0] <> DubDefaultConfigName) then
dubproc.Parameters.Add('--config=' + fConfigs.Strings[fConfigIx]);
dubProc.Parameters.Add('--compiler=' + DubCompilerFilename);
if run and (runArgs <> '') then
if run and runArgs.isNotEmpty then
dubproc.Parameters.Add('--' + runArgs);
dubproc.Execute;
while dubproc.Running do
@ -799,7 +799,7 @@ begin
try
try
maybe.loadFromFile(filename);
if (maybe.json = nil) or (maybe.filename = '') then
if maybe.json.isNil or maybe.filename.isEmpty then
result := false
else if maybe.json.Find('name').isNil then
result := false;
@ -824,7 +824,7 @@ begin
gdc: DubCompilerFilename := exeFullName('gdc' + exeExt);
ldc: DubCompilerFilename := exeFullName('ldc2' + exeExt);
end;
if (not fileExists(DubCompilerFilename)) or (DubCompilerFilename = '') then
if (not fileExists(DubCompilerFilename)) or DubCompilerFilename.isEmpty then
begin
value := dmd;
DubCompilerFilename:= 'dmd' + exeExt;

View File

@ -443,7 +443,7 @@ begin
fTokList.Clear;
fErrList.Clear;
end;
if md = '' then md := extractFileName(fDoc.fileName);
if md.isEmpty then md := extractFileName(fDoc.fileName);
pageControl.currentPage.Caption := md;
end;
end;
@ -480,7 +480,8 @@ begin
fTokList.Clear;
fErrList.Clear;
end;
if md = '' then md := extractFileName(fDoc.fileName);
if md.isEmpty then
md := extractFileName(fDoc.fileName);
pageControl.currentPage.Caption := md;
end;
{$ENDREGION}

View File

@ -25,12 +25,12 @@ inherited CEInfoWidget: TCEInfoWidget
Align = alTop
BorderSpacing.Around = 4
Caption = 'about'
ClientHeight = 89
ClientHeight = 75
ClientWidth = 399
TabOrder = 0
object Label1: TLabel
Left = 0
Height = 89
Height = 75
Top = 0
Width = 399
Align = alClient
@ -52,12 +52,12 @@ inherited CEInfoWidget: TCEInfoWidget
Align = alClient
BorderSpacing.Around = 4
Caption = 'tools status'
ClientHeight = 290
ClientHeight = 276
ClientWidth = 399
TabOrder = 1
object boxTools: TScrollBox
Left = 4
Height = 282
Height = 268
Top = 4
Width = 391
HorzScrollBar.Page = 1

View File

@ -119,7 +119,7 @@ begin
tikFindable:
begin
pth := exeFullName(fToolName + exeExt);
if pth = '' then
if pth.isEmpty then
begin
fStatus.Caption:= ' the tool cannot be found';
AssignPng(fIco, 'bullet_red');
@ -133,7 +133,7 @@ begin
tikOptional:
begin
pth := exeFullName(fToolName + exeExt);
if pth = '' then
if pth.isEmpty then
begin
fStatus.Caption:= ' the tool cannot be found';
AssignPng(fIco, 'bullet_yellow');
@ -147,7 +147,7 @@ begin
tikRunning:
begin
pth := exeFullName(fToolName + exeExt);
if pth = '' then
if pth.isEmpty then
begin
fStatus.Caption:= ' the tool cannot be found';
AssignPng(fIco, 'bullet_red');

View File

@ -259,7 +259,7 @@ begin
prj.loadFromFile(pth + DirectorySeparator + 'dub.json')
else if FileExists(pth + DirectorySeparator + 'package.json') then
prj.loadFromFile(pth + DirectorySeparator + 'package.json');
if (prj.filename <> '') and (prj.binaryKind = staticlib) then
if prj.filename.isNotEmpty and (prj.binaryKind = staticlib) then
begin
str := TStringList.Create;
try
@ -368,7 +368,7 @@ begin
root := commonFolder(str);
root := ExtractFileDir(root);
end;
if root = '' then
if root.isEmpty then
begin
dlgOkInfo('the static library can not be registered because its source files have no common folder');
exit;
@ -443,7 +443,7 @@ begin
else
begin
List.Selected.SubItems[0] := filename;
if (List.Selected.Caption = '') or (List.Selected.Caption = notav) then
if (List.Selected.Caption.isEmpty) or (List.Selected.Caption = notav) then
List.Selected.Caption := ChangeFileExt(extractFileName(filename), '');
end;
end;

View File

@ -554,7 +554,7 @@ begin
itf := TCEMainForm(aDestination).fProjectInterface;
if (itf <> nil) and (itf.filename = fProject) then
exit;
if fProject <> '' then if FileExists(fProject) then
if fProject.isNotEmpty and FileExists(fProject) then
TCEMainForm(aDestination).openProj(fProject);
end else
inherited;
@ -740,14 +740,14 @@ begin
if application.ParamCount > 0 then
begin
value := application.Params[1];
if value <> '' then
if value.isNotEmpty then
begin
lst := TStringList.Create;
try
lst.DelimitedText := value;
for value in lst do
begin
if value = '' then continue;
if value.isEmpty then continue;
if isEditable(ExtractFileExt(value)) then
openFile(value)
else if isValidNativeProject(value) or isValidDubProject(value) then
@ -764,10 +764,10 @@ begin
end;
end;
value := application.GetOptionValue('p', 'project');
if (value <> '') and fileExists(value) then
if value.isNotEmpty and fileExists(value) then
openProj(value);
value := application.GetOptionValue('f', 'files');
if value <> '' then
if value.isNotEmpty then
begin
lst := TStringList.Create;
try
@ -1790,9 +1790,9 @@ begin
RemoveTrailingChars(cur, [#0..#30]);
fRunnableSw += (cur + #13);
end;
if (fRunnableSw <> '') and (fRunnableSw[length(fRunnableSw)] = #13) then
if fRunnableSw.isNotEmpty and (fRunnableSw[length(fRunnableSw)] = #13) then
fRunnableSw := fRunnableSw[1..length(fRunnableSw)-1];
if fRunnableSw = '' then
if fRunnableSw.isEmpty then
fRunnableSw := '-vcolumns'#13'-w'#13'-wi';
//
form.Free;
@ -1846,7 +1846,7 @@ begin
else fDoc.saveTempFile;
fname := stripFileExt(fDoc.fileName);
if fRunnableSw = '' then
if fRunnableSw.isEmpty then
fRunnableSw := '-vcolumns'#13'-w'#13'-wi';
{$IFDEF RELEASE}
dmdProc.ShowWindow := swoHIDE;
@ -1879,7 +1879,7 @@ begin
fMsgs.message(shortenPath(fDoc.fileName, 25) + ' successfully compiled',
fDoc, amcEdit, amkInf);
fRunProc.CurrentDirectory := extractFileDir(fRunProc.Executable);
if runArgs <> '' then
if runArgs.isNotEmpty then
begin
extraArgs.Clear;
CommandToList(symbolExpander.get(runArgs), extraArgs);
@ -2249,7 +2249,7 @@ end;
procedure TCEMainForm.actProjSaveExecute(Sender: TObject);
begin
if fProjectInterface = nil then exit;
if fProjectInterface.filename <> '' then saveProj
if fProjectInterface.filename.isNotEmpty then saveProj
else actProjSaveAs.Execute;
end;

View File

@ -24,7 +24,7 @@ inherited CEMessagesWidget: TCEMessagesWidget
Width = 759
Align = alClient
BorderSpacing.Around = 2
DefaultItemHeight = 18
DefaultItemHeight = 16
Font.Height = -12
Font.Name = 'Courier New'
Font.Quality = fqProof

View File

@ -374,7 +374,7 @@ end;
procedure TCEMessagesWidget.TreeFilterEdit1AfterFilter(Sender: TObject);
begin
fFiltering := TreeFilterEdit1.Filter <> '';
fFiltering := TreeFilterEdit1.Filter.isNotEmpty;
filterMessages(fCtxt);
end;
@ -786,7 +786,7 @@ begin
if dat^.demangled then continue;
dat^.demangled := true;
str := list.Items.Item[i].Text;
if str = '' then continue;
if str.isEmpty then continue;
fToDemangleObjs.add(list.Items.Item[i]);
fToDemangle.Add(str);
end;

View File

@ -608,7 +608,7 @@ procedure TCENativeProject.updateOutFilename;
begin
fOutputFilename := currentConfiguration.pathsOptions.outputFilename;
// field is specified
if fOutputFilename <> '' then
if fOutputFilename.isNotEmpty then
begin
fOutputFilename := symbolExpander.get(fOutputFilename);
fOutputFilename := expandFilenameEx(fBasePath, fOutputFilename);
@ -652,9 +652,9 @@ var
i, j: integer;
begin
pname := symbolExpander.get(processInfo.executable);
if (not exeInSysPath(pname)) and (pname <> '') then
if (not exeInSysPath(pname)) and pname.isNotEmpty then
exit(false)
else if (pname = '') then
else if pname.isEmpty then
exit(true);
//
process := TProcess.Create(nil);
@ -666,7 +666,7 @@ begin
process.Parameters.AddText(symbolExpander.get(process.Parameters.Strings[i]));
for i:= 0 to j do
process.Parameters.Delete(0);
if process.CurrentDirectory <> '' then
if process.CurrentDirectory.isNotEmpty then
process.CurrentDirectory := symbolExpander.get(process.CurrentDirectory);
// else cwd is set to project dir in compile()
ensureNoPipeIfWait(process);
@ -766,13 +766,13 @@ begin
//
fRunner := TCEProcess.Create(nil); // fRunner can use the input process widget.
currentConfiguration.runOptions.setProcess(fRunner);
if runArgs <> '' then
if runArgs.isNotEmpty then
begin
i := 1;
repeat
prm := ExtractDelimited(i, runArgs, [' ']);
prm := symbolExpander.get(prm);
if prm <> '' then
if prm.isNotEmpty then
fRunner.Parameters.AddText(prm);
Inc(i);
until prm = '';
@ -786,7 +786,7 @@ begin
end;
//
fRunner.Executable := outputFilename;
if fRunner.CurrentDirectory = '' then
if fRunner.CurrentDirectory.isEmpty then
begin
fRunnerOldCwd := GetCurrentDir;
cwd := extractFilePath(fRunner.Executable);
@ -991,7 +991,7 @@ begin
ldc: NativeProjectCompilerFilename := exeFullName('ldmd2' + exeExt);
end;
if (not fileExists(NativeProjectCompilerFilename))
or (NativeProjectCompilerFilename = '') then
or NativeProjectCompilerFilename.isEmpty then
begin
value := dmd;
NativeProjectCompilerFilename:= 'dmd' + exeExt;

View File

@ -421,7 +421,7 @@ begin
// display Imports (-J)
for str in FProject.currentConfiguration.pathsOptions.importStringPaths do
begin
if str = '' then
if str.isEmpty then
continue;
fold := expandFilenameEx(fProject.basePath, str);
fold := symbolExpander.get(fold);
@ -433,7 +433,7 @@ begin
// display Includes (-I)
for str in FProject.currentConfiguration.pathsOptions.importModulePaths do
begin
if str = '' then
if str.isEmpty then
continue;
fold := expandFilenameEx(fProject.basePath, str);
fold := symbolExpander.get(fold);
@ -445,7 +445,7 @@ begin
// display extra sources (external .lib, *.a, *.d)
for str in FProject.currentConfiguration.pathsOptions.extraSources do
begin
if str = '' then
if str.isEmpty then
continue;
src := expandFilenameEx(fProject.basePath, str);
src := symbolExpander.get(src);

View File

@ -129,7 +129,7 @@ inherited CESearchWidget: TCESearchWidget
Align = alClient
BorderSpacing.Around = 4
Caption = 'Options'
ClientHeight = 92
ClientHeight = 78
ClientWidth = 382
TabOrder = 4
object chkWWord: TCheckBox

View File

@ -463,11 +463,11 @@ end;
procedure TCESearchWidget.updateImperative;
begin
btnFind.Enabled := fDoc.isNotNil and (fToFind <> '');
btnFindAll.Enabled := fDoc.isNotNil and (fToFind <> '');
btnReplace.Enabled := fDoc.isNotNil and (chkEnableRep.Checked) and (fToFind <> '');
btnFind.Enabled := fDoc.isNotNil and fToFind.isNotEmpty;
btnFindAll.Enabled := fDoc.isNotNil and fToFind.isNotEmpty;
btnReplace.Enabled := fDoc.isNotNil and chkEnableRep.Checked and fToFind.isNotEmpty;
btnReplaceAll.Enabled := btnReplace.Enabled;
cbReplaceWth.Enabled := fDoc.isNotNil and (chkEnableRep.Checked);
cbReplaceWth.Enabled := fDoc.isNotNil and chkEnableRep.Checked;
cbToFind.Enabled := fDoc.isNotNil;
end;
{$ENDREGION}

View File

@ -299,7 +299,7 @@ begin
begin
sh := Shortcut(Key, Shift);
sht := shortCutToText(sh);
if sht = '' then
if sht.isEmpty then
exit;
for i:= 0 to tree.Selected.Parent.Count-1 do
if i <> tree.Selected.Index then
@ -369,8 +369,8 @@ var
prt: TTreeNode;
begin
// root category
if cat = '' then exit;
if idt = '' then exit;
if cat.isEmpty or idt.isEmpty then
exit;
prt := findCategory(cat, obs);
if prt.isNil then
prt := tree.Items.AddObject(nil, cat, obs);
@ -413,7 +413,7 @@ begin
begin
shc := fShortcuts[i];
cat := findCategory(shc);
if cat = '' then
if cat.isEmpty then
continue;
if shc.declarator = nil then
continue;

View File

@ -24,7 +24,7 @@ inherited CESymbolListWidget: TCESymbolListWidget
Width = 302
Align = alClient
BorderSpacing.Around = 4
DefaultItemHeight = 18
DefaultItemHeight = 16
HideSelection = False
Images = imgList
ReadOnly = True

View File

@ -603,7 +603,7 @@ end;
procedure TCESymbolListWidget.TreeFilterEdit1AfterFilter(Sender: TObject);
begin
if TreeFilterEdit1.Filter = '' then
if TreeFilterEdit1.Filter.isEmpty then
updateVisibleCat;
end;
@ -612,7 +612,7 @@ function TCESymbolListWidget.TreeFilterEdit1FilterItem(Item: TObject; out
begin
if not fSmartFilter then exit(false);
//
if TreeFilterEdit1.Filter <> '' then
if TreeFilterEdit1.Filter.isNotEmpty then
tree.FullExpand
else if tree.Selected.isNil then
tree.FullCollapse
@ -769,7 +769,7 @@ begin
if fSmartExpander then
smartExpand;
tree.EndUpdate;
if flt <> '' then
if flt.isNotEmpty then
TreeFilterEdit1.Text := flt;
end;

View File

@ -175,7 +175,7 @@ begin
fDoc.saveTempFile;
fSymbols[CFF] := fDoc.fileName;
fSymbols[CFP] := ExtractFilePath(fDoc.fileName);
if fDoc.Identifier <> '' then
if fDoc.Identifier.isNotEmpty then
fSymbols[CI] := fDoc.Identifier;
end;
// project interface
@ -212,7 +212,7 @@ begin
if fileExists(fProj.fileName) then
begin
fSymbols[CPR] := expandFilenameEx(fProj.basePath, fProj.RootFolder);
if fSymbols[CPR] = '' then
if fSymbols[CPR].isEmpty then
fSymbols[CPR] := fSymbols[CPP];
end;
end;
@ -226,7 +226,7 @@ var
i: integer;
begin
Result := '';
if symString = '' then
if symString.isEmpty then
exit;
//
updateSymbols;

View File

@ -796,7 +796,7 @@ begin
i -= 1;
end;
DcdWrapper.getCallTip(str);
if str <> '' then
if str.isNotEmpty then
begin
pnt := ClientToScreen(point(CaretXPix, CaretYPix));
fCallTipWin.FontSize := Font.Size;
@ -818,7 +818,7 @@ begin
fCanShowHint := false;
DcdWrapper.getDdocFromCursor(str);
//
if str <> '' then
if str.isNotEmpty then
begin
fDDocWin.FontSize := Font.Size;
fDDocWin.HintRect := fDDocWin.CalcHintRect(0, str, nil);
@ -885,7 +885,7 @@ var
len: Integer;
begin
// empty items can be produced if completion list is too long
if aKey = '' then exit(true);
if aKey.isEmpty then exit(true);
// otherwise always at least 20 chars but...
// ... '20' depends on ce_dcd, case knd of, string literals length
result := true;

View File

@ -3,6 +3,7 @@ inherited CETodoListWidget: TCETodoListWidget
Height = 337
Top = 196
Width = 584
ActiveControl = btnRefresh
Caption = 'Todo list'
ClientHeight = 337
ClientWidth = 584

View File

@ -493,7 +493,7 @@ begin
trg.SubItems.Add(src.priority);
trg.SubItems.Add(shortenPath(src.filename, 25));
//
if flt <> '' then
if flt.isNotEmpty then
if flt <> '(filter)' then
if not AnsiContainsText(src.Text, flt) then
if not AnsiContainsText(src.category, flt) then
@ -505,13 +505,13 @@ begin
continue;
end;
//
if src.category <> '' then
if src.category.isNotEmpty then
lstItems.Column[1].Visible := True;
if src.assignee <> '' then
if src.assignee.isNotEmpty then
lstItems.Column[2].Visible := True;
if src.status <> '' then
if src.status.isNotEmpty then
lstItems.Column[3].Visible := True;
if src.priority <> '' then
if src.priority.isNotEmpty then
lstItems.Column[4].Visible := True;
end;
end;

View File

@ -209,7 +209,7 @@ begin
begin
prm := '';
if InputQuery('Parameters', '', prm) then
if prm <> '' then fProcess.Parameters.AddText(symbolExpander.get(prm));
if prm.isNotEmpty then fProcess.Parameters.AddText(symbolExpander.get(prm));
end;
ensureNoPipeIfWait(fProcess);
//
@ -234,7 +234,7 @@ var
str: string;
nxt: TCEToolItem;
begin
if ((not fOutputToNext) or (fNextToolAlias = '')) and (poUsePipes in options) then
if ((not fOutputToNext) or fNextToolAlias.isEmpty) and (poUsePipes in options) then
begin
getMessageDisplay(fMsgs);
lst := TStringList.Create;
@ -246,7 +246,7 @@ begin
lst.Free;
end;
end;
if (not fProcess.Running) and (fNextToolAlias <> '') then
if (not fProcess.Running) and fNextToolAlias.isNotEmpty then
begin
nxt := fToolItems.findTool(fNextToolAlias);
if nxt.isNotNil then nxt.execute(self);