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,56 +225,34 @@ 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; begin
elem := ''; if rng.empty then
repeat break;
Inc(i); Result += rng.takeUntil('<').yield;
if not (symString[i] in ['<', '>']) then if not rng.empty and (rng.front = '<') then
elem += symString[i]
else
begin
if symString[i] = '<' then
begs := True;
ends := symString[i] = '>';
elems.Add(elem);
elem := '';
if begs and ends then
begin
begs := False;
ends := False;
// elem.obj is a flag to differenciate symbols from elements
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] sym := rng.takeUntil('>').yield;
else if not rng.empty and (rng.front = '>') then
case elems[i] of begin
'<', '>': continue; rng.popFront;
case sym of
'CAF', 'CoeditApplicationFile': Result += fSymbols[CAF]; 'CAF', 'CoeditApplicationFile': Result += fSymbols[CAF];
'CAP', 'CoeditApplicationPath': Result += fSymbols[CAP]; 'CAP', 'CoeditApplicationPath': Result += fSymbols[CAP];
// //
'CFF', 'CurrentFileFile' : Result += fSymbols[CFF]; 'CFF', 'CurrentFileFile' : Result += fSymbols[CFF];
'CFP', 'CurrentFilePath' : Result += fSymbols[CFP]; 'CFP', 'CurrentFilePath' : Result += fSymbols[CFP];
'CI', 'CurrentIdentifier' : Result += fSymbols[CI]; 'CI', 'CurrentIdentifier' : Result += fSymbols[CI];
// //
'CPF', 'CurrentProjectFile' : Result += fSymbols[CPF]; 'CPF', 'CurrentProjectFile' : Result += fSymbols[CPF];
'CPFS', 'CurrentProjectFiles' : Result += fSymbols[CPFS]; 'CPFS', 'CurrentProjectFiles' : Result += fSymbols[CPFS];
@ -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