diff --git a/core/smn_string.cpp b/core/smn_string.cpp index ca1bf21b..fbeb139f 100644 --- a/core/smn_string.cpp +++ b/core/smn_string.cpp @@ -74,6 +74,21 @@ static cell_t sm_strcmp(IPluginContext *pCtx, const cell_t *params) return (func(str1, str2)); } +static cell_t sm_strncmp(IPluginContext *pCtx, const cell_t *params) +{ + char *str1, *str2; + + pCtx->LocalToString(params[1], &str1); + pCtx->LocalToString(params[2], &str2); + + if (params[4]) + { + return strncmp(str1, str2, (size_t)params[3]); + } else { + return strncasecmp(str1, str2, (size_t)params[3]); + } +} + static cell_t sm_strcopy(IPluginContext *pCtx, const cell_t *params) { char *dest, *src; @@ -316,6 +331,7 @@ REGISTER_NATIVES(basicStrings) {"StrBreak", StrBreak}, {"StrContains", sm_contain}, {"StrCompare", sm_strcmp}, + {"StrCompareN", sm_strncmp}, {"StrCopy", sm_strcopy}, {"StringToInt", sm_strconvint}, {"IntToString", sm_numtostr}, diff --git a/plugins/include/string.inc b/plugins/include/string.inc index 4eef8021..5060a0bf 100644 --- a/plugins/include/string.inc +++ b/plugins/include/string.inc @@ -55,7 +55,29 @@ native StrContains(const String:str[], const String:substr[], bool:caseSensitive * 0 if str1 == str2 * 1 if str1 > str2 */ -native StrCompare(const String:str1[], const String:str2[], bool:caseSensitive=true); +native strcmp(const String:str1[], const String:str2[], bool:caseSensitive=true); + +/** + * Compares two strings parts lexographically. + * + * @param str1 First string (left). + * @param str2 Second string (right). + * @param num Number of characters to compare. + * @param caseSensitive If true (default), comparison is case sensitive. + * If false, comparison is case insensitive. + * @return -1 if str1 < str2 + * 0 if str1 == str2 + * 1 if str1 > str2 + */ +native strncmp(const String:str1[], const String:str2[], num, bool:caseSensitive=true); + +/** + * Backwards compatible stock - StrCompare is now strcmp + */ +stock StrCompare(const String:str1[], const String:str2[], bool:caseSensitive=true) +{ + return strcmp(str1, str2, caseSensitive); +} /** * Returns whether two strings are equal. diff --git a/public/sm_platform.h b/public/sm_platform.h index 499050f3..d78b3c75 100644 --- a/public/sm_platform.h +++ b/public/sm_platform.h @@ -34,6 +34,7 @@ #define stat _stat #endif #define strcasecmp strcmpi +#define strncasecmp strnicmp #include #include #define PLATFORM_LIB_EXT "dll"