summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-04-10 21:40:45 +0200
committerMattes D <github@xoft.cz>2015-04-10 21:40:45 +0200
commit65a1158e40b30d8c06d6398bc142c6ae9e783006 (patch)
tree67a51cecfb5a2d4b214fd083e470447d77f5fce6
parentFixed MSVC warnings, improved comments. (diff)
downloadcuberite-65a1158e40b30d8c06d6398bc142c6ae9e783006.tar
cuberite-65a1158e40b30d8c06d6398bc142c6ae9e783006.tar.gz
cuberite-65a1158e40b30d8c06d6398bc142c6ae9e783006.tar.bz2
cuberite-65a1158e40b30d8c06d6398bc142c6ae9e783006.tar.lz
cuberite-65a1158e40b30d8c06d6398bc142c6ae9e783006.tar.xz
cuberite-65a1158e40b30d8c06d6398bc142c6ae9e783006.tar.zst
cuberite-65a1158e40b30d8c06d6398bc142c6ae9e783006.zip
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua13
-rw-r--r--src/OSSupport/File.cpp19
2 files changed, 30 insertions, 2 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index d0c362ab4..c8e96d378 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -62,6 +62,7 @@ function Initialize(Plugin)
TestStringBase64()
-- TestUUIDFromName()
-- TestRankMgr()
+ TestFileExt()
--[[
-- Test cCompositeChat usage in console-logging:
@@ -79,6 +80,18 @@ end;
+function TestFileExt()
+ assert(cFile:ChangeFileExt("fileless_dir/", "new") == "fileless_dir/")
+ 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.dir/file", "new") == "path/to.dir/file.new")
+ assert(cFile:ChangeFileExt("path/to.dir/file.ext", "new") == "path/to.dir/file.new")
+end
+
+
+
+
+
function TestPluginCalls()
-- In order to test the inter-plugin communication, we're going to call Core's ReturnColorFromChar() function
-- It is a rather simple function that doesn't need any tables as its params and returns a value, too
diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp
index 7ad1b3f81..fcd5ec027 100644
--- a/src/OSSupport/File.cpp
+++ b/src/OSSupport/File.cpp
@@ -456,10 +456,25 @@ AString cFile::ReadWholeFile(const AString & a_FileName)
AString cFile::ChangeFileExt(const AString & a_FileName, const AString & a_NewExt)
{
auto res = a_FileName;
+
+ // If the path separator is the last character of the string, return the string unmodified (refers to a folder):
+ #ifdef _WIN32
+ auto LastPathSep = res.find_last_of("/\\"); // Find either path separator - Windows accepts slashes as separators, too
+ #else
+ auto LastPathSep = res.rfind('/');
+ #endif
+ if ((LastPathSep != AString::npos) && (LastPathSep + 1 == res.size()))
+ {
+ return res;
+ }
+
auto DotPos = res.rfind('.');
- if (DotPos == AString::npos)
+ if (
+ (DotPos == AString::npos) || // No dot found
+ ((LastPathSep != AString::npos) && (LastPathSep > DotPos)) // Last dot is before the last path separator (-> in folder name)
+ )
{
- // No extension, just append it:
+ // No extension, just append the new one:
res.push_back('.');
res.append(a_NewExt);
}