diff --git a/src/shared/utils.pas b/src/shared/utils.pas
index 14fa53b94eecb7425bbb1d8b8746eb4e412a5826..f5f762c6e983c96a5dd7c54ad3fb68c82110d058 100644 (file)
--- a/src/shared/utils.pas
+++ b/src/shared/utils.pas
// 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;
// ////////////////////////////////////////////////////////////////////////// //
// 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
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;