Explorar o código

Added baseName to extract base file name from file path.

Branimir Karadžić %!s(int64=11) %!d(string=hai) anos
pai
achega
eb3258aa86
Modificáronse 1 ficheiros con 21 adicións e 0 borrados
  1. 21 0
      include/bx/string.h

+ 21 - 0
include/bx/string.h

@@ -16,6 +16,7 @@
 
 
 namespace bx
 namespace bx
 {
 {
+	///
 	inline bool toBool(const char* _str)
 	inline bool toBool(const char* _str)
 	{
 	{
 		char ch = (char)tolower(_str[0]);
 		char ch = (char)tolower(_str[0]);
@@ -247,6 +248,7 @@ namespace bx
 #endif // BX_COMPILER_MSVC
 #endif // BX_COMPILER_MSVC
 	}
 	}
 
 
+	///
 	inline int32_t snprintf(char* _str, size_t _count, const char* _format, ...) // BX_PRINTF_ARGS(3, 4)
 	inline int32_t snprintf(char* _str, size_t _count, const char* _format, ...) // BX_PRINTF_ARGS(3, 4)
 	{
 	{
 		va_list argList;
 		va_list argList;
@@ -256,6 +258,7 @@ namespace bx
 		return len;
 		return len;
 	}
 	}
 
 
+	///
 	inline int32_t swnprintf(wchar_t* _out, size_t _count, const wchar_t* _format, ...)
 	inline int32_t swnprintf(wchar_t* _out, size_t _count, const wchar_t* _format, ...)
 	{
 	{
 		va_list argList;
 		va_list argList;
@@ -265,6 +268,7 @@ namespace bx
 		return len;
 		return len;
 	}
 	}
 
 
+	///
 	template <typename Ty>
 	template <typename Ty>
 	inline void stringPrintfVargs(Ty& _out, const char* _format, va_list _argList)
 	inline void stringPrintfVargs(Ty& _out, const char* _format, va_list _argList)
 	{
 	{
@@ -281,6 +285,7 @@ namespace bx
 		_out.append(out);
 		_out.append(out);
 	}
 	}
 
 
+	///
 	template <typename Ty>
 	template <typename Ty>
 	inline void stringPrintf(Ty& _out, const char* _format, ...)
 	inline void stringPrintf(Ty& _out, const char* _format, ...)
 	{
 	{
@@ -290,6 +295,22 @@ namespace bx
 		va_end(argList);
 		va_end(argList);
 	}
 	}
 
 
+	/// Extract base file name from file path.
+	inline const char* baseName(const char* _filePath)
+	{
+		const char* bs       = strrchr(_filePath, '\\');
+		const char* fs       = strrchr(_filePath, '/');
+		const char* slash    = (bs > fs ? bs : fs);
+		const char* colon    = strrchr(_filePath, ':');
+		const char* basename = slash > colon ? slash : colon;
+		if (NULL != basename)
+		{
+			return basename+1;
+		}
+
+		return _filePath;
+	}
+
 	/*
 	/*
 	 * Copyright (c) 1998 Todd C. Miller <[email protected]>
 	 * Copyright (c) 1998 Todd C. Miller <[email protected]>
 	 *
 	 *