Skip to content

Commit

Permalink
new ExtractExtP() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Jan 8, 2024
1 parent 96b7160 commit 41e13cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/core/mormot.core.os.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3342,10 +3342,18 @@ function ExtractNameU(const FileName: RawUtf8): RawUtf8;
// - but cross-platform, i.e. detect both '\' and '/' on all platforms
function ExtractExt(const FileName: TFileName; WithoutDot: boolean = false): TFileName;

// defined here for proper ExtractExtP() inlining
function GetLastDelimU(const FileName: RawUtf8; OtherDelim: AnsiChar): PtrInt;

/// extract an extension from a file name like ExtractFileExt function
// - but cross-platform, i.e. detect both '\' and '/' on all platforms
function ExtractExtU(const FileName: RawUtf8; WithoutDot: boolean = false): RawUtf8;

/// extract an extension from a file name like ExtractFileExt function
// - but cross-platform, i.e. detect both '\' and '/' on all platforms
function ExtractExtP(const FileName: RawUtf8; WithoutDot: boolean = false): PUtf8Char;
{$ifdef HASINLINE} inline; {$endif}

/// compute the file name, including its path if supplied, but without its extension
// - e.g. GetFileNameWithoutExt('/var/toto.ext') = '/var/toto'
// - may optionally return the extracted extension, as '.ext'
Expand Down Expand Up @@ -6929,6 +6937,21 @@ function ExtractExtU(const FileName: RawUtf8; WithoutDot: boolean): RawUtf8;
result := copy(FileName, i, 100);
end;

function ExtractExtP(const FileName: RawUtf8; WithoutDot: boolean): PUtf8Char;
var
i: PtrInt;
begin
result := nil;
i := GetLastDelimU(FileName, '.') - 1;
if i <= 0 then
exit;
result := PUtf8Char(pointer(FileName)) + i;
if result^ <> '.' then
result := nil
else if WithoutDot then
inc(result);
end;

function GetFileNameWithoutExt(const FileName: TFileName; Extension: PFileName): TFileName;
var
i, max: PtrInt;
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'2.2.6620'
'2.2.6621'

0 comments on commit 41e13cb

Please sign in to comment.