Procházet zdrojové kódy

Fix path::basename

Daniele Bartolini před 13 roky
rodič
revize
245d50cbd4
1 změnil soubory, kde provedl 32 přidání a 0 odebrání
  1. 32 0
      src/core/strings/Path.h

+ 32 - 0
src/core/strings/Path.h

@@ -1,3 +1,28 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
 #pragma once
 
 #include "String.h"
@@ -215,6 +240,13 @@ void basename(const char* path, char* str, size_t len)
 		string::strncpy(str, path, final_len);
 		str[final_len] = '\0';
 	}
+	// "texture.tga"
+	else if (last_separator == -1 && last_dot != -1)
+	{
+		size_t final_len = (len >= (size_t)last_dot) ? last_dot : len;
+		string::strncpy(str, path, final_len);
+		str[final_len] = '\0';
+	}
 }
 
 /// Returns the extension of the path.