Move TrimWhitespace from core to logic.
This commit is contained in:
parent
c261bb0b2e
commit
9d2bee261c
@ -52,7 +52,7 @@ using namespace SourceHook;
|
|||||||
* Add 1 to the RHS of this expression to bump the intercom file
|
* Add 1 to the RHS of this expression to bump the intercom file
|
||||||
* This is to prevent mismatching core/logic binaries
|
* This is to prevent mismatching core/logic binaries
|
||||||
*/
|
*/
|
||||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 32)
|
#define SM_LOGIC_MAGIC (0x0F47C0DE - 33)
|
||||||
|
|
||||||
#if defined SM_LOGIC
|
#if defined SM_LOGIC
|
||||||
class IVEngineServer
|
class IVEngineServer
|
||||||
@ -293,7 +293,6 @@ struct sm_core_t
|
|||||||
ISourcePawnEngine2 **spe2;
|
ISourcePawnEngine2 **spe2;
|
||||||
/* Functions */
|
/* Functions */
|
||||||
ConVar * (*FindConVar)(const char*);
|
ConVar * (*FindConVar)(const char*);
|
||||||
char * (*TrimWhitespace)(char *, size_t &);
|
|
||||||
void (*LogToGame)(const char *message);
|
void (*LogToGame)(const char *message);
|
||||||
void (*ConPrint)(const char *message);
|
void (*ConPrint)(const char *message);
|
||||||
const char * (*GetCvarString)(ConVar*);
|
const char * (*GetCvarString)(ConVar*);
|
||||||
|
@ -504,7 +504,7 @@ private:
|
|||||||
while (!smcore.filesystem->EndOfFile(fp) && smcore.filesystem->ReadLine(buffer, sizeof(buffer), fp) != NULL)
|
while (!smcore.filesystem->EndOfFile(fp) && smcore.filesystem->ReadLine(buffer, sizeof(buffer), fp) != NULL)
|
||||||
{
|
{
|
||||||
size_t len = strlen(buffer);
|
size_t len = strlen(buffer);
|
||||||
char *ptr = smcore.TrimWhitespace(buffer, len);
|
char *ptr = UTIL_TrimWhitespace(buffer, len);
|
||||||
if (*ptr == '\0'
|
if (*ptr == '\0'
|
||||||
|| *ptr == ';'
|
|| *ptr == ';'
|
||||||
|| strncmp(ptr, "//", 2) == 0)
|
|| strncmp(ptr, "//", 2) == 0)
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <sm_platform.h>
|
#include <sm_platform.h>
|
||||||
#include "stringutil.h"
|
#include "stringutil.h"
|
||||||
#include <am-string.h>
|
#include <am-string.h>
|
||||||
|
#include "TextParsers.h"
|
||||||
|
|
||||||
// We're in logic so we don't have this from the SDK.
|
// We're in logic so we don't have this from the SDK.
|
||||||
#ifndef MIN
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -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);
|
size_t UTIL_DecodeHexString(unsigned char *buffer, size_t maxlength, const char *hexstr);
|
||||||
|
|
||||||
void UTIL_StripExtension(const char *in, char *out, int outSize);
|
void UTIL_StripExtension(const char *in, char *out, int outSize);
|
||||||
|
char *UTIL_TrimWhitespace(char *str, size_t &len);
|
||||||
|
|
||||||
#endif /* _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_ */
|
#endif /* _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_ */
|
||||||
|
|
||||||
|
@ -583,7 +583,6 @@ static sm_core_t core_bridge =
|
|||||||
&g_pSourcePawn2,
|
&g_pSourcePawn2,
|
||||||
/* Functions */
|
/* Functions */
|
||||||
find_convar,
|
find_convar,
|
||||||
UTIL_TrimWhitespace,
|
|
||||||
log_to_game,
|
log_to_game,
|
||||||
conprint,
|
conprint,
|
||||||
get_cvar_string,
|
get_cvar_string,
|
||||||
|
@ -1304,36 +1304,6 @@ char *sm_strdup(const char *str)
|
|||||||
return ptr;
|
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)
|
char *UTIL_ToLowerCase(const char *str)
|
||||||
{
|
{
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
|
@ -56,7 +56,6 @@ bool gnprintf(char *buffer,
|
|||||||
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
|
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);
|
size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap);
|
||||||
char *sm_strdup(const char *str);
|
char *sm_strdup(const char *str);
|
||||||
char *UTIL_TrimWhitespace(char *str, size_t &len);
|
|
||||||
char *UTIL_ToLowerCase(const char *str);
|
char *UTIL_ToLowerCase(const char *str);
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_STRINGUTIL_H_
|
#endif // _INCLUDE_SOURCEMOD_STRINGUTIL_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user