Browse Source

use is_space_char also on windows (close #477)

Nicolas Cannasse 3 years ago
parent
commit
8d7b29c186
2 changed files with 23 additions and 11 deletions
  1. 6 6
      src/hl.h
  2. 17 5
      src/std/ucs2.c

+ 6 - 6
src/hl.h

@@ -224,8 +224,8 @@ typedef wchar_t	uchar;
 #	define ustrlen		wcslen
 #	define ustrdup		_wcsdup
 HL_API int uvszprintf( uchar *out, int out_size, const uchar *fmt, va_list arglist );
-#	define utod(s,end)	wcstod(s,end)
-#	define utoi(s,end)	wcstol(s,end,10)
+#	define _utod(s,end)	wcstod(s,end)
+#	define _utoi(s,end)	wcstol(s,end,10)
 #	define ucmp(a,b)	wcscmp(a,b)
 #	define utostr(out,size,str) wcstombs(out,str,size)
 #elif defined(HL_MAC)
@@ -247,19 +247,19 @@ typedef char16_t uchar;
 #	define USTR(str)	u##str
 #endif
 
-#ifndef HL_NATIVE_UCHAR_FUN
 C_FUNCTION_BEGIN
-HL_API int ustrlen( const uchar *str );
-HL_API uchar *ustrdup( const uchar *str );
 HL_API double utod( const uchar *str, uchar **end );
 HL_API int utoi( const uchar *str, uchar **end );
+#ifndef HL_NATIVE_UCHAR_FUN
+HL_API int ustrlen( const uchar *str );
+HL_API uchar *ustrdup( const uchar *str );
 HL_API int ucmp( const uchar *a, const uchar *b );
 HL_API int utostr( char *out, int out_size, const uchar *str );
 HL_API int usprintf( uchar *out, int out_size, const uchar *fmt, ... );
 HL_API int uvszprintf( uchar *out, int out_size, const uchar *fmt, va_list arglist );
 HL_API void uprintf( const uchar *fmt, const uchar *str );
-C_FUNCTION_END
 #endif
+C_FUNCTION_END
 
 #if defined(HL_VCC)
 #	define hl_debug_break()	if( IsDebuggerPresent() ) __debugbreak()

+ 17 - 5
src/std/ucs2.c

@@ -22,7 +22,23 @@
 #include <hl.h>
 #include <stdarg.h>
 
-#ifndef HL_NATIVE_UCHAR_FUN
+static bool is_space_char( uchar c ) {
+	return c > 8 && c < 14;
+}
+
+#ifdef HL_NATIVE_UCHAR_FUN
+
+HL_PRIM double utod( const uchar *str, uchar **end ) {
+	while( is_space_char(*str) ) str++;
+	return _utod(str,end);
+}
+
+HL_PRIM int utoi( const uchar *str, uchar **end ) {
+	while( is_space_char(*str) ) str++;
+	return _utoi(str,end);
+}
+
+#else
 
 #ifdef HL_ANDROID
 #	include <android/log.h>
@@ -67,10 +83,6 @@ uchar *ustrdup( const uchar *str ) {
 	return d;
 }
 
-static bool is_space_char( uchar c ) {
-	return c == ' ' || c == '\r' || c == '\n' || c == '\t';
-}
-
 double utod( const uchar *str, uchar **end ) {
 	char buf[31];
 	char *bend;