From 9d2bee261cacaf690a0a345712edfbcc8e418f3b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 26 Aug 2015 00:46:09 -0400 Subject: [PATCH] Move TrimWhitespace from core to logic. --- core/logic/intercom.h | 3 +-- core/logic/smn_maplists.cpp | 2 +- core/logic/stringutil.cpp | 32 ++++++++++++++++++++++++++++++++ core/logic/stringutil.h | 1 + core/logic_bridge.cpp | 1 - core/sm_stringutil.cpp | 30 ------------------------------ core/sm_stringutil.h | 1 - 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/core/logic/intercom.h b/core/logic/intercom.h index a8470590..c4280940 100644 --- a/core/logic/intercom.h +++ b/core/logic/intercom.h @@ -52,7 +52,7 @@ using namespace SourceHook; * Add 1 to the RHS of this expression to bump the intercom file * This is to prevent mismatching core/logic binaries */ -#define SM_LOGIC_MAGIC (0x0F47C0DE - 32) +#define SM_LOGIC_MAGIC (0x0F47C0DE - 33) #if defined SM_LOGIC class IVEngineServer @@ -293,7 +293,6 @@ struct sm_core_t ISourcePawnEngine2 **spe2; /* Functions */ ConVar * (*FindConVar)(const char*); - char * (*TrimWhitespace)(char *, size_t &); void (*LogToGame)(const char *message); void (*ConPrint)(const char *message); const char * (*GetCvarString)(ConVar*); diff --git a/core/logic/smn_maplists.cpp b/core/logic/smn_maplists.cpp index 0334223a..d93d2f03 100644 --- a/core/logic/smn_maplists.cpp +++ b/core/logic/smn_maplists.cpp @@ -504,7 +504,7 @@ private: while (!smcore.filesystem->EndOfFile(fp) && smcore.filesystem->ReadLine(buffer, sizeof(buffer), fp) != NULL) { size_t len = strlen(buffer); - char *ptr = smcore.TrimWhitespace(buffer, len); + char *ptr = UTIL_TrimWhitespace(buffer, len); if (*ptr == '\0' || *ptr == ';' || strncmp(ptr, "//", 2) == 0) diff --git a/core/logic/stringutil.cpp b/core/logic/stringutil.cpp index 3ea284e6..7d5050e2 100644 --- a/core/logic/stringutil.cpp +++ b/core/logic/stringutil.cpp @@ -35,6 +35,7 @@ #include #include "stringutil.h" #include +#include "TextParsers.h" // We're in logic so we don't have this from the SDK. #ifndef MIN @@ -329,3 +330,34 @@ void UTIL_StripExtension(const char *in, char *out, int outSize) } } } + +char *UTIL_TrimWhitespace(char *str, size_t &len) +{ + char *end = str + len - 1; + + if (!len) + { + return str; + } + + /* Iterate backwards through string until we reach first non-whitespace char */ + while (end >= str && g_TextParser.IsWhitespace(end)) + { + end--; + len--; + } + + /* Replace first whitespace char (at the end) with null terminator. + * If there is none, we're just replacing the null terminator. + */ + *(end + 1) = '\0'; + + while (*str != '\0' && g_TextParser.IsWhitespace(str)) + { + str++; + len--; + } + + return str; +} + diff --git a/core/logic/stringutil.h b/core/logic/stringutil.h index f4296965..558ab37c 100644 --- a/core/logic/stringutil.h +++ b/core/logic/stringutil.h @@ -41,6 +41,7 @@ char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t se size_t UTIL_DecodeHexString(unsigned char *buffer, size_t maxlength, const char *hexstr); void UTIL_StripExtension(const char *in, char *out, int outSize); +char *UTIL_TrimWhitespace(char *str, size_t &len); #endif /* _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_ */ diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 64ec59ae..e7ea4043 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -583,7 +583,6 @@ static sm_core_t core_bridge = &g_pSourcePawn2, /* Functions */ find_convar, - UTIL_TrimWhitespace, log_to_game, conprint, get_cvar_string, diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index ee55820f..c0507bb1 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -1304,36 +1304,6 @@ char *sm_strdup(const char *str) return ptr; } -char *UTIL_TrimWhitespace(char *str, size_t &len) -{ - char *end = str + len - 1; - - if (!len) - { - return str; - } - - /* Iterate backwards through string until we reach first non-whitespace char */ - while (end >= str && textparsers->IsWhitespace(end)) - { - end--; - len--; - } - - /* Replace first whitespace char (at the end) with null terminator. - * If there is none, we're just replacing the null terminator. - */ - *(end + 1) = '\0'; - - while (*str != '\0' && textparsers->IsWhitespace(str)) - { - str++; - len--; - } - - return str; -} - char *UTIL_ToLowerCase(const char *str) { size_t len = strlen(str); diff --git a/core/sm_stringutil.h b/core/sm_stringutil.h index 494e2389..699b941d 100644 --- a/core/sm_stringutil.h +++ b/core/sm_stringutil.h @@ -56,7 +56,6 @@ bool gnprintf(char *buffer, size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...); size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap); char *sm_strdup(const char *str); -char *UTIL_TrimWhitespace(char *str, size_t &len); char *UTIL_ToLowerCase(const char *str); #endif // _INCLUDE_SOURCEMOD_STRINGUTIL_H_