소스 검색

Added swnprintf.

bkaradzic 12 년 전
부모
커밋
01f6e30ac7
1개의 변경된 파일20개의 추가작업 그리고 5개의 파일을 삭제
  1. 20 5
      include/bx/string.h

+ 20 - 5
include/bx/string.h

@@ -12,6 +12,7 @@
 #include <stdio.h>  // vsnprintf
 #include <string.h>
 #include <string>
+#include <wchar.h>  // wchar_t
 
 namespace bx
 {
@@ -172,21 +173,34 @@ namespace bx
 	/// Cross platform implementation of vsnprintf that returns number of
 	/// characters which would have been written to the final string if
 	/// enough space had been available.
-	inline int32_t vsnprintf(char* _str, size_t _size, const char* _format, va_list _argList)
+	inline int32_t vsnprintf(char* _str, size_t _count, const char* _format, va_list _argList)
 	{
 #if BX_COMPILER_MSVC
-		int32_t len = ::vsnprintf(_str, _size, _format, _argList);
+		int32_t len = ::vsnprintf(_str, _count, _format, _argList);
 		return -1 == len ? ::_vscprintf(_format, _argList) : len;
 #else
-		return ::vsnprintf(_str, _size, _format, _argList);
+		return ::vsnprintf(_str, _count, _format, _argList);
 #endif // BX_COMPILER_MSVC
 	}
 
-	inline int32_t snprintf(char* _str, size_t _size, 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_start(argList, _format);
-		int32_t len = vsnprintf(_str, _size, _format, argList);
+		int32_t len = vsnprintf(_str, _count, _format, argList);
+		va_end(argList);
+		return len;
+	}
+
+	inline int32_t swnprintf(wchar_t* _out, size_t _count, const wchar_t* _format, ...)
+	{
+		va_list argList;
+		va_start(argList, _format);
+#if defined(__MINGW32__)
+		int32_t len = swprintf(_out, _format, argList);
+#else
+		int32_t len = swprintf(_out, _count, _format, argList);
+#endif // defined(__MINGW__)
 		va_end(argList);
 		return len;
 	}
@@ -213,6 +227,7 @@ namespace bx
 		stringPrintfVargs(_out, _format, argList);
 		va_end(argList);
 	}
+
 } // namespace bx
 
 #endif // __BX_PRINTF_H__