summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 92dde38)
raw | patch | inline | side by side (parent: 92dde38)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 8 Sep 2023 10:33:31 +0000 (13:33 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 8 Sep 2023 10:33:31 +0000 (13:33 +0300) |
src/shared/WADEDITOR.pas | patch | blob | history |
index db62d0e767e99b57c1c00d06ff0023551e8b5d37..30b3260bfa20cb88b4cec54af788addae9de8bbf 100644 (file)
--- a/src/shared/WADEDITOR.pas
+++ b/src/shared/WADEDITOR.pas
implementation
- uses SysUtils, utils;
+ uses SysUtils, Math, utils;
var
uWADEditorFactory: TWADEditorFactory;
+ // EBNF:
+ // Resource = [Archive ":"] [{slash} Section {slash}slash] Name.
+ // slash = "/" | "\".
procedure g_ProcessResourceStr(ResourceStr: String; var FileName, SectionName, ResourceName: String);
- var a, i: Integer;
begin
- for i := Length(ResourceStr) downto 1 do
- if ResourceStr[i] = ':' then
- Break;
-
- FileName := Copy(ResourceStr, 1, i-1);
-
- for a := i+1 to Length(ResourceStr) do
- if (ResourceStr[a] = '\') or (ResourceStr[a] = '/') then Break;
-
- ResourceName := Copy(ResourceStr, a+1, Length(ResourceStr)-Abs(a));
- SectionName := Copy(ResourceStr, i+1, Length(ResourceStr)-Length(ResourceName)-Length(FileName)-2);
+ g_ProcessResourceStr(ResourceStr, @FileName, @SectionName, @ResourceName);
end;
procedure g_ProcessResourceStr(ResourceStr: AnsiString; FileName, SectionName, ResourceName: PAnsiString);
- var a, i, l1, l2: Integer;
+ var i, j: Integer; sn: AnsiString;
begin
- for i := Length(ResourceStr) downto 1 do
- if ResourceStr[i] = ':' then
- Break;
+ i := Max(1, LastDelimiter(':', ResourceStr));
if FileName <> nil then
- begin
- FileName^ := Copy(ResourceStr, 1, i-1);
- l1 := Length(FileName^);
- end
- else
- l1 := 0;
+ FileName^ := LeftStr(ResourceStr, i - 1);
+
+ if (SectionName <> nil) or (ResourceName <> nil) then
+ begin
+ for i := i to High(ResourceStr) do
+ if ResourceStr[i] in ['\', '/', ':'] = False then
+ break;
+ sn := Copy(ResourceStr, i);
- for a := i+1 to Length(ResourceStr) do
- if (ResourceStr[a] = '\') or (ResourceStr[a] = '/') then Break;
+ j := LastDelimiter('/\', sn);
+ if ResourceName <> nil then
+ ResourceName^ := Copy(sn, j + 1);
- if ResourceName <> nil then
+ if SectionName <> nil then
begin
- ResourceName^ := Copy(ResourceStr, a+1, Length(ResourceStr)-Abs(a));
- l2 := Length(ResourceName^);
- end
- else
- l2 := 0;
-
- if SectionName <> nil then
- SectionName^ := Copy(ResourceStr, i+1, Length(ResourceStr)-l2-l1-2);
+ for j := j downto 0 do
+ if (j > 0) and (sn[j] in ['\', '/'] = False) then
+ break;
+ if SectionName <> nil then
+ SectionName^ := LeftStr(sn, j);
+ end;
+ end;
end;
{ TWADEditor }