cFile:ChangeFileExt now accepts extensions with leading dot, too.
This commit is contained in:
parent
c4842cb9aa
commit
79e8f8fb20
@ -973,12 +973,12 @@ cFile:Delete("/usr/bin/virus.exe");
|
|||||||
]],
|
]],
|
||||||
Functions =
|
Functions =
|
||||||
{
|
{
|
||||||
ChangeFileExt = { Params = "FileName, NewExt", Return = "string", Notes = "(STATIC) Returns FileName with its extension changed to NewExt. FileName may contain path elements, extension is recognized as the last dot in the string." },
|
ChangeFileExt = { Params = "FileName, NewExt", Return = "string", Notes = "(STATIC) Returns FileName with its extension changed to NewExt. NewExt may begin with a dot, but needn't, the result is the same in both cases (the first dot, if present, is ignored). FileName may contain path elements, extension is recognized as the last dot after the last path separator in the string." },
|
||||||
Copy = { Params = "SrcFileName, DstFileName", Return = "bool", Notes = "(STATIC) Copies a single file to a new destination. Returns true if successful. Fails if the destination already exists." },
|
Copy = { Params = "SrcFileName, DstFileName", Return = "bool", Notes = "(STATIC) Copies a single file to a new destination. Returns true if successful. Fails if the destination already exists." },
|
||||||
CreateFolder = { Params = "FolderName", Return = "bool", Notes = "(STATIC) Creates a new folder. Returns true if successful." },
|
CreateFolder = { Params = "FolderName", Return = "bool", Notes = "(STATIC) Creates a new folder. Returns true if successful." },
|
||||||
Delete = { Params = "FileName", Return = "bool", Notes = "(STATIC) Deletes the specified file. Returns true if successful." },
|
Delete = { Params = "FileName", Return = "bool", Notes = "(STATIC) Deletes the specified file. Returns true if successful." },
|
||||||
Exists = { Params = "FileName", Return = "bool", Notes = "(STATIC) Returns true if the specified file exists." },
|
Exists = { Params = "FileName", Return = "bool", Notes = "(STATIC) Returns true if the specified file exists." },
|
||||||
GetExecutableExt = { Params = "", Return = "string", Notes = "(STATIC) Returns the customary executable extension used by the current platform (\".exe\" on Windows, empty string on Linux). " },
|
GetExecutableExt = { Params = "", Return = "string", Notes = "(STATIC) Returns the customary executable extension (including the dot) used by the current platform (\".exe\" on Windows, empty string on Linux). " },
|
||||||
GetFolderContents = { Params = "FolderName", Return = "array table of strings", Notes = "(STATIC) Returns the contents of the specified folder, as an array table of strings. Each filesystem object is listed. Use the IsFile() and IsFolder() functions to determine the object type." },
|
GetFolderContents = { Params = "FolderName", Return = "array table of strings", Notes = "(STATIC) Returns the contents of the specified folder, as an array table of strings. Each filesystem object is listed. Use the IsFile() and IsFolder() functions to determine the object type." },
|
||||||
GetLastModificationTime = { Params = "Path", Return = "number", Notes = "(STATIC) Returns the last modification time (in current timezone) of the specified file or folder. Returns zero if file not found / not accessible. The returned value is in the same units as values returned by os.time()." },
|
GetLastModificationTime = { Params = "Path", Return = "number", Notes = "(STATIC) Returns the last modification time (in current timezone) of the specified file or folder. Returns zero if file not found / not accessible. The returned value is in the same units as values returned by os.time()." },
|
||||||
GetPathSeparator = { Params = "", Return = "string", Notes = "(STATIC) Returns the primary path separator used by the current platform. Returns \"\\\" on Windows and \"/\" on Linux. Note that the platform or CRT may support additional path separators, those are not reported." },
|
GetPathSeparator = { Params = "", Return = "string", Notes = "(STATIC) Returns the primary path separator used by the current platform. Returns \"\\\" on Windows and \"/\" on Linux. Note that the platform or CRT may support additional path separators, those are not reported." },
|
||||||
|
@ -84,10 +84,19 @@ end;
|
|||||||
|
|
||||||
function TestFileExt()
|
function TestFileExt()
|
||||||
assert(cFile:ChangeFileExt("fileless_dir/", "new") == "fileless_dir/")
|
assert(cFile:ChangeFileExt("fileless_dir/", "new") == "fileless_dir/")
|
||||||
|
assert(cFile:ChangeFileExt("fileless_dir/", ".new") == "fileless_dir/")
|
||||||
assert(cFile:ChangeFileExt("pathless_file.ext", "new") == "pathless_file.new")
|
assert(cFile:ChangeFileExt("pathless_file.ext", "new") == "pathless_file.new")
|
||||||
|
assert(cFile:ChangeFileExt("pathless_file.ext", ".new") == "pathless_file.new")
|
||||||
assert(cFile:ChangeFileExt("path/to/file.ext", "new") == "path/to/file.new")
|
assert(cFile:ChangeFileExt("path/to/file.ext", "new") == "path/to/file.new")
|
||||||
|
assert(cFile:ChangeFileExt("path/to/file.ext", ".new") == "path/to/file.new")
|
||||||
assert(cFile:ChangeFileExt("path/to.dir/file", "new") == "path/to.dir/file.new")
|
assert(cFile:ChangeFileExt("path/to.dir/file", "new") == "path/to.dir/file.new")
|
||||||
|
assert(cFile:ChangeFileExt("path/to.dir/file", ".new") == "path/to.dir/file.new")
|
||||||
assert(cFile:ChangeFileExt("path/to.dir/file.ext", "new") == "path/to.dir/file.new")
|
assert(cFile:ChangeFileExt("path/to.dir/file.ext", "new") == "path/to.dir/file.new")
|
||||||
|
assert(cFile:ChangeFileExt("path/to.dir/file.ext", ".new") == "path/to.dir/file.new")
|
||||||
|
assert(cFile:ChangeFileExt("path/to.dir/file.longext", "new") == "path/to.dir/file.new")
|
||||||
|
assert(cFile:ChangeFileExt("path/to.dir/file.longext", ".new") == "path/to.dir/file.new")
|
||||||
|
assert(cFile:ChangeFileExt("path/to.dir/file.", "new") == "path/to.dir/file.new")
|
||||||
|
assert(cFile:ChangeFileExt("path/to.dir/file.", ".new") == "path/to.dir/file.new")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -481,13 +481,25 @@ AString cFile::ChangeFileExt(const AString & a_FileName, const AString & a_NewEx
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
// No extension, just append the new one:
|
// No extension, just append the new one:
|
||||||
res.push_back('.');
|
if (!a_NewExt.empty() && (a_NewExt[0] != '.'))
|
||||||
|
{
|
||||||
|
// a_NewExt doesn't start with a dot, insert one:
|
||||||
|
res.push_back('.');
|
||||||
|
}
|
||||||
res.append(a_NewExt);
|
res.append(a_NewExt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Replace existing extension:
|
// Replace existing extension:
|
||||||
res.erase(DotPos + 1, AString::npos);
|
if (!a_NewExt.empty() && (a_NewExt[0] != '.'))
|
||||||
|
{
|
||||||
|
// a_NewExt doesn't start with a dot, keep the current one:
|
||||||
|
res.erase(DotPos + 1, AString::npos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.erase(DotPos, AString::npos);
|
||||||
|
}
|
||||||
res.append(a_NewExt);
|
res.append(a_NewExt);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user