RxFPC:New function in RxFileUtils - NormalizeFileName. Fix languages

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4815 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2016-06-24 07:43:52 +00:00
parent 54dc447750
commit eec24fb3f0
9 changed files with 52 additions and 41 deletions

View File

@ -43,6 +43,16 @@ procedure GetFileOwnerData(const SearchDomain, FileName:String;out UserName, Dom
function NormalizeDirectoryName(const DirName:string):string;
function GetUserName:string;
function IsValidFileNameChar(const AChar: Char): Boolean;inline;
function NormalizeFileName(const FileName:string; AReplaceChar:char = '_'):string; //funtion only for filename - without folder name
const
{$IFDEF WINDOWS}
FileNameDisabledChars = [#0 .. #31, '"', '*', '/', ':', '<', '>', '?', '\' , '|'];
{$ELSE}
FileNameDisabledChars = [#0 .. #31, '/', '~'];
{$ENDIF}
implementation
uses
@ -207,5 +217,20 @@ begin
{$ENDIF}
end;
function IsValidFileNameChar(const AChar: Char): Boolean;
begin
Result:=not (AChar in FileNameDisabledChars);
end;
function NormalizeFileName(const FileName: string; AReplaceChar:char = '_'): string;
var
i:integer;
begin
Result:=FileName;
for i:=1 to Length(Result) do
if not IsValidFileNameChar(Result[i]) then
Result[i]:=AReplaceChar;
end;
end.