From: Ketmar Dark Date: Mon, 21 Oct 2019 03:23:58 +0000 (+0300) Subject: utils: more useless APIs X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=469fea05c58ca92a5a18483751dde23f255ab52d;p=d2df-sdl.git utils: more useless APIs --- diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 0ac5caa..bf8abf4 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -74,6 +74,9 @@ function forceFilenameExt (const fn, ext: AnsiString): AnsiString; // rewrites slashes to '/' function fixSlashes (s: AnsiString): AnsiString; +function isAbsolutePath (const s: AnsiString): Boolean; +function isRootPath (const s: AnsiString): Boolean; + // strips out name from `fn`, leaving trailing slash function getFilenamePath (const fn: AnsiString): AnsiString; @@ -347,6 +350,32 @@ begin end; +function isAbsolutePath (const s: AnsiString): Boolean; +begin + result := false; + if (length(s) = 0) then exit; + {$IFDEF WINDOWS} + if (s[1] = '/') or (s[1] = '\') then begin result := true; exit; end; + if (length(s) > 2) and (s[2] = ':') and ((s[3] = '/') or (s[3] = '\')) then begin result := true; exit; end; + {$ELSE} + result := (s[1] = '/'); + {$ENDIF} +end; + + +function isRootPath (const s: AnsiString): Boolean; +begin + result := false; + if (length(s) = 0) then exit; + {$IFDEF WINDOWS} + if (s = '/') or (s = '\') then begin result := true; exit; end; + if (length(s) = 3) and (s[2] = ':') and ((s[3] = '/') or (s[3] = '\')) then begin result := true; exit; end; + {$ELSE} + result := (s = '/'); + {$ENDIF} +end; + + // ////////////////////////////////////////////////////////////////////////// // constructor TSimpleList.TEnumerator.Create (const aitems: TItemArr; acount: Integer); begin