rewritten symbolic string expansion using a string range

This commit is contained in:
Basile Burg 2016-03-18 22:26:37 +01:00
parent 4792f0ed87
commit 3d56c76834
1 changed files with 23 additions and 44 deletions

View File

@ -5,7 +5,8 @@ unit ce_symstring;
interface interface
uses uses
ce_observer, ce_interfaces, ce_nativeproject, ce_synmemo, ce_common; ce_observer, ce_interfaces, ce_nativeproject, ce_synmemo, ce_common,
ce_stringrange;
type type
@ -224,50 +225,28 @@ end;
function TCESymbolExpander.get(const symString: string): string; function TCESymbolExpander.get(const symString: string): string;
var var
elems: TStringList; rng: TStringRange;
elem: string; sym: string;
begs, ends: boolean;
i: integer;
begin begin
Result := ''; Result := '';
if symString.isEmpty then if symString.isEmpty then
exit; exit;
// //
updateSymbols; updateSymbols;
elems := TStringList.Create; rng := TStringRange.create(symString);
try while true do
i := 0;
elem := '';
repeat
Inc(i);
if not (symString[i] in ['<', '>']) then
elem += symString[i]
else
begin begin
if symString[i] = '<' then if rng.empty then
begs := True; break;
ends := symString[i] = '>'; Result += rng.takeUntil('<').yield;
elems.Add(elem); if not rng.empty and (rng.front = '<') then
elem := '';
if begs and ends then
begin begin
begs := False; rng.popFront;
ends := False; sym := rng.takeUntil('>').yield;
// elem.obj is a flag to differenciate symbols from elements if not rng.empty and (rng.front = '>') then
elems.Objects[elems.Count - 1] := Self;
end;
end;
until
i = symString.length;
elems.Add(elem);
elem := '';
for i := 0 to elems.Count - 1 do
begin begin
if elems.Objects[i].isNil then rng.popFront;
Result += elems[i] case sym of
else
case elems[i] of
'<', '>': continue;
'CAF', 'CoeditApplicationFile': Result += fSymbols[CAF]; 'CAF', 'CoeditApplicationFile': Result += fSymbols[CAF];
'CAP', 'CoeditApplicationPath': Result += fSymbols[CAP]; 'CAP', 'CoeditApplicationPath': Result += fSymbols[CAP];
// //
@ -282,13 +261,13 @@ begin
'CPP', 'CurrentProjectPath' : Result += fSymbols[CPP]; 'CPP', 'CurrentProjectPath' : Result += fSymbols[CPP];
'CPR', 'CurrentProjectRoot' : Result += fSymbols[CPR]; 'CPR', 'CurrentProjectRoot' : Result += fSymbols[CPR];
'CPCD','CurrentProjectCommonDirectory': Result += fSymbols[CPCD]; 'CPCD','CurrentProjectCommonDirectory': Result += fSymbols[CPCD];
else Result += '<' + sym + '>';
end; end;
end
else Result += '<' + sym;
end; end;
finally
elems.Free;
end; end;
end; end;
{$ENDREGION} {$ENDREGION}
initialization initialization