X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fshared%2Futils.pas;h=f5f762c6e983c96a5dd7c54ad3fb68c82110d058;hb=76b68febf6f7d7a3f0a45e47b57606ac8f40a083;hp=14fa53b94eecb7425bbb1d8b8746eb4e412a5826;hpb=2d2ce4c1770a59c3e780f3fd31249ce6043f374c;p=d2df-sdl.git diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 14fa53b..f5f762c 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -74,6 +74,10 @@ function forceFilenameExt (const fn, ext: AnsiString): AnsiString; // rewrites slashes to '/' function fixSlashes (s: AnsiString): AnsiString; +// replaces all the shitty characters with '_' +// (everything except alphanumerics, '_', '.') +function sanitizeFilename (s: AnsiString): AnsiString; + function isAbsolutePath (const s: AnsiString): Boolean; function isRootPath (const s: AnsiString): Boolean; @@ -342,13 +346,31 @@ end; // ////////////////////////////////////////////////////////////////////////// // // rewrites slashes to '/' function fixSlashes (s: AnsiString): AnsiString; +{$IFDEF WINDOWS} var f: Integer; +{$ENDIF} begin result := s; + {$IFDEF WINDOWS} for f := 1 to length(result) do if (result[f] = '\') then result[f] := '/'; + {$ENDIF} end; +// replaces all the shitty characters with '_' +// (everything except alphanumerics, '_', '.') +function sanitizeFilename (s: AnsiString): AnsiString; +var + i: Integer; +const + leaveChars: set of Char = [ '0'..'9', 'A'..'Z', 'a'..'z', '_', '.', #192..#255 ]; + replaceWith: Char = '_'; +begin + result := s; + for i := 1 to length(result) do + if not (result[i] in leaveChars) then + result[i] := replaceWith; +end; function isAbsolutePath (const s: AnsiString): Boolean; begin @@ -1017,7 +1039,7 @@ end; function IsValid1251 (ch: Word): Boolean; begin - result := ((ch = Ord('?')) or (wc2shitmap[ch] <> '?')) and (ch <> $98) + result := ((ch = Ord('?')) or (wc2shitmap[ch] <> '?')) and (wc2shitmap[ch] <> #$98) end; function IsPrintable1251 (ch: AnsiChar): Boolean;