Changeset - r10977:42a8ddddcf37
[Not reviewed]
master
0 3 0
glx - 16 years ago 2009-02-02 13:46:26
glx@openttd.org
(svn r15316) -Fix [NoAI]: ignore unprintable chars when returning a string to squirrel
3 files changed with 6 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/script/squirrel_helper.hpp
Show inline comments
 
@@ -9,6 +9,7 @@
 
#include "../core/math_func.hpp"
 
#include "../core/smallvec_type.hpp"
 
#include "../economy_type.h"
 
#include "../string_func.h"
 
#include "squirrel_helper_type.hpp"
 

	
 
/**
 
@@ -79,8 +80,8 @@ namespace SQConvert {
 
	template <> inline int Return<int64>       (HSQUIRRELVM vm, int64 res)       { sq_pushinteger(vm, ClampToI32(res)); return 1; }
 
	template <> inline int Return<Money>       (HSQUIRRELVM vm, Money res)       { sq_pushinteger(vm, ClampToI32(res)); return 1; }
 
	template <> inline int Return<bool>        (HSQUIRRELVM vm, bool res)        { sq_pushbool   (vm, res); return 1; }
 
	template <> inline int Return<char *>      (HSQUIRRELVM vm, char *res)       { if (res == NULL) sq_pushnull(vm); else sq_pushstring (vm, OTTD2FS(res), strlen(res)); free(res); return 1; }
 
	template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else sq_pushstring (vm, OTTD2FS(res), strlen(res)); return 1; }
 
	template <> inline int Return<char *>      (HSQUIRRELVM vm, char *res)       { if (res == NULL) sq_pushnull(vm); else {str_validate(res, false, true); sq_pushstring (vm, OTTD2FS(res), strlen(res)); free(res);} return 1; }
 
	template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else {str_validate((char*)res, false, true); sq_pushstring (vm, OTTD2FS(res), strlen(res));} return 1; }
 
	template <> inline int Return<void *>      (HSQUIRRELVM vm, void *res)       { sq_pushuserpointer(vm, res); return 1; }
 

	
 
	/**
src/string.cpp
Show inline comments
 
@@ -97,7 +97,7 @@ char *CDECL str_fmt(const char *str, ...
 
}
 

	
 

	
 
void str_validate(char *str, bool allow_newlines)
 
void str_validate(char *str, bool allow_newlines, bool ignore)
 
{
 
	char *dst = str;
 
	WChar c;
 
@@ -122,7 +122,7 @@ void str_validate(char *str, bool allow_
 
			assert(c != '\r');
 
			/* Replace the undesirable character with a question mark */
 
			str += len;
 
			*dst++ = '?';
 
			if (!ignore) *dst++ = '?';
 
		}
 
	}
 

	
src/string_func.h
Show inline comments
 
@@ -95,7 +95,7 @@ char *CDECL str_fmt(const char *str, ...
 

	
 
/** Scans the string for valid characters and if it finds invalid ones,
 
 * replaces them with a question mark '?' */
 
void str_validate(char *str, bool allow_newlines = false);
 
void str_validate(char *str, bool allow_newlines = false, bool ignore = false);
 

	
 
/** Scans the string for colour codes and strips them */
 
void str_strip_colours(char *str);
0 comments (0 inline, 0 general)