2006-12-30 08:23:17 +01:00
|
|
|
/**
|
2007-02-12 10:00:55 +01:00
|
|
|
* vim: set ts=4 :
|
2007-01-26 03:07:24 +01:00
|
|
|
* ===============================================================
|
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* ===============================================================
|
|
|
|
*
|
|
|
|
* This file is part of the SourceMod/SourcePawn SDK. This file may only be used
|
|
|
|
* or modified under the Terms and Conditions of its License Agreement, which is found
|
|
|
|
* in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
|
|
|
|
* may change at any time. To view the latest information, see:
|
|
|
|
* http://www.sourcemod.net/license.php
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
2007-01-26 03:07:24 +01:00
|
|
|
|
2006-12-30 08:23:17 +01:00
|
|
|
#if defined _string_included
|
|
|
|
#endinput
|
|
|
|
#endif
|
|
|
|
#define _string_included
|
|
|
|
|
|
|
|
/**
|
2007-03-15 21:44:23 +01:00
|
|
|
* @global Unless otherwise noted, all string functions which take in a writable buffer
|
|
|
|
* and maximum length should have the null terminator INCLUDED in the length. This means
|
|
|
|
* that this is valid: StrCopy(string, sizeof(string), ...)
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
2007-03-16 21:10:13 +01:00
|
|
|
|
2006-12-30 08:23:17 +01:00
|
|
|
/**
|
|
|
|
* Calculates the length of a string.
|
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param str String to check.
|
|
|
|
* @return Length of string, in cells (NOT characters).
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
|
|
|
native strlen(const String:str[]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests whether a string is found inside another string.
|
|
|
|
*
|
|
|
|
* @param str String to search in.
|
|
|
|
* @param substr Substring to find inside the original string.
|
|
|
|
* @param caseSensitive If true (default), search is case sensitive.
|
2007-02-12 10:00:55 +01:00
|
|
|
* If false, search is case insensitive.
|
|
|
|
* @return -1 on failure (no match found). Any other value
|
|
|
|
* indicates a position in the string where the match starts.
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
|
|
|
native StrContains(const String:str[], const String:substr[], bool:caseSensitive=true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares two strings lexographically.
|
|
|
|
*
|
|
|
|
* @param str1 First string (left).
|
|
|
|
* @param str2 Second string (right).
|
|
|
|
* @param caseSensitive If true (default), comparison is case sensitive.
|
2007-02-12 10:00:55 +01:00
|
|
|
* If false, comparison is case insensitive.
|
|
|
|
* @return -1 if str1 < str2
|
|
|
|
* 0 if str1 == str2
|
|
|
|
* 1 if str1 > str2
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
2007-04-11 18:24:50 +02:00
|
|
|
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
|
2007-04-11 22:07:20 +02:00
|
|
|
* @deprecated Renamed to strcmp
|
2007-04-11 18:24:50 +02:00
|
|
|
*/
|
|
|
|
stock StrCompare(const String:str1[], const String:str2[], bool:caseSensitive=true)
|
|
|
|
{
|
|
|
|
return strcmp(str1, str2, caseSensitive);
|
|
|
|
}
|
2006-12-30 08:23:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether two strings are equal.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param str1 First string (left).
|
|
|
|
* @param str2 Second string (right).
|
|
|
|
* @param caseSensitive If true (default), comparison is case sensitive.
|
2007-01-29 23:35:06 +01:00
|
|
|
* If false, comparison is case insensitive.
|
|
|
|
* @return True if equal, false otherwise.
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
2006-12-30 20:01:23 +01:00
|
|
|
stock bool:StrEqual(const String:str1[], const String:str2[], bool:caseSensitive=true)
|
2006-12-30 08:23:17 +01:00
|
|
|
{
|
2006-12-30 20:01:23 +01:00
|
|
|
return (StrCompare(str1, str2, caseSensitive) == 0);
|
2006-12-30 08:23:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies one string to another string.
|
2007-03-15 21:44:23 +01:00
|
|
|
* @note If the destination buffer is too small to hold the source string, the
|
|
|
|
* destination will be truncated.
|
2006-12-30 08:23:17 +01:00
|
|
|
*
|
|
|
|
* @param dest Destination string buffer to copy to.
|
|
|
|
* @param destlen Destination buffer length (includes null terminator).
|
|
|
|
* @param source Source string buffer to copy from.
|
2007-01-29 23:35:06 +01:00
|
|
|
* @return Number of cells written.
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
2007-04-11 22:07:20 +02:00
|
|
|
native strcopy(String:dest[], destLen, const String:source[]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backwards compatibility stock - use strcopy
|
|
|
|
* @deprecated Renamed to strcopy
|
|
|
|
*/
|
|
|
|
stock StrCopy(String:dest[], destLen, const String:source[])
|
|
|
|
{
|
|
|
|
return strcopy(dest, destLen, source);
|
|
|
|
}
|
2006-12-30 08:23:17 +01:00
|
|
|
|
2007-01-01 22:46:33 +01:00
|
|
|
/**
|
|
|
|
* Formats a string according to the SourceMod format rules (see documentation).
|
|
|
|
*
|
|
|
|
* @param buffer Destination string buffer.
|
|
|
|
* @param maxlength Maximum length of output string buffer.
|
|
|
|
* @param format Formatting rules.
|
|
|
|
* @param ... Variable number of format parameters.
|
2007-01-29 23:35:06 +01:00
|
|
|
* @return Number of cells written.
|
2007-01-01 22:46:33 +01:00
|
|
|
*/
|
2007-03-16 21:39:32 +01:00
|
|
|
native Format(String:buffer[], maxlength, const String:format[], any:...);
|
2007-01-01 22:46:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a string according to the SourceMod format rules (see documentation).
|
|
|
|
* @note This is the same as Format(), except none of the input buffers can overlap the same
|
2007-03-15 21:44:23 +01:00
|
|
|
* memory as the output buffer. Since this security check is removed, it is slightly faster.
|
2007-01-01 22:46:33 +01:00
|
|
|
*
|
|
|
|
* @param buffer Destination string buffer.
|
|
|
|
* @param maxlength Maximum length of output string buffer.
|
|
|
|
* @param format Formatting rules.
|
|
|
|
* @param ... Variable number of format parameters.
|
2007-01-29 23:35:06 +01:00
|
|
|
* @return Number of cells written.
|
2007-01-01 22:46:33 +01:00
|
|
|
*/
|
2007-03-16 21:39:32 +01:00
|
|
|
native FormatEx(String:buffer[], maxlength, const String:format[], any:...);
|
2007-01-01 22:46:33 +01:00
|
|
|
|
2007-01-29 23:35:06 +01:00
|
|
|
/**
|
|
|
|
* Formats a string according to the SourceMod format rules (see documentation).
|
|
|
|
* @note This is the same as Format(), except it grabs parameters from a parent parameter
|
2007-03-15 21:44:23 +01:00
|
|
|
* stack, rather than a local. This is useful for implementing your own variable
|
|
|
|
* argument functions.
|
2007-01-29 23:35:06 +01:00
|
|
|
*
|
|
|
|
* @param buffer Destination string buffer.
|
|
|
|
* @param maxlength Maximum length of output string buffer.
|
|
|
|
* @param format Formatting rules.
|
|
|
|
* @param varpos Argument number which contains the '...' symbol.
|
|
|
|
* Note: Arguments start at 1.
|
|
|
|
* @return Number of bytes written.
|
|
|
|
*/
|
|
|
|
native VFormat(String:buffer[], maxlength, const String:format[], varpos);
|
|
|
|
|
2006-12-30 08:23:17 +01:00
|
|
|
/**
|
|
|
|
* Converts a string to an integer.
|
|
|
|
*
|
|
|
|
* @param str String to convert.
|
2007-01-29 23:35:06 +01:00
|
|
|
* @param nBase Numerical base to use. 10 is default.
|
|
|
|
* @return Integer conversion of string, or 0 on failure.
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
|
|
|
native StringToInt(const String:str[], nBase=10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an integer to a string.
|
|
|
|
*
|
2007-02-08 02:10:48 +01:00
|
|
|
* @param num Integer to convert.
|
2006-12-30 08:23:17 +01:00
|
|
|
* @param str Buffer to store string in.
|
|
|
|
* @param maxlength Maximum length of string buffer.
|
2007-01-29 23:35:06 +01:00
|
|
|
* @return Number of cells written to buffer.
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
2007-02-08 02:10:48 +01:00
|
|
|
native IntToString(num, String:str[], maxlength);
|
2006-12-30 08:23:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a string to a floating point number.
|
|
|
|
*
|
|
|
|
* @param str String to convert to a foat.
|
2007-01-29 23:35:06 +01:00
|
|
|
* @return Floating point result, or 0.0 on error.
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
|
|
|
native Float:StringToFloat(const String:str[]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a floating point number to a string.
|
|
|
|
*
|
2007-02-08 05:53:56 +01:00
|
|
|
* @param num Floating point number to convert.
|
2006-12-30 08:23:17 +01:00
|
|
|
* @param str Buffer to store string in.
|
|
|
|
* @param maxlength Maximum length of string buffer.
|
2007-01-29 23:35:06 +01:00
|
|
|
* @return Number of cells written to buffer.
|
2006-12-30 08:23:17 +01:00
|
|
|
*/
|
2007-02-08 05:53:56 +01:00
|
|
|
native FloatToString(Float:num, String:str[], maxlength);
|
2007-03-16 21:10:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the first "argument" in a string; either a set of space
|
|
|
|
* terminated characters, or a fully quoted string. After the
|
|
|
|
* argument is found, whitespace is read until the next portion
|
|
|
|
* of the string is reached. If nothing remains, -1 is returned.
|
|
|
|
* Otherwise, the index to the first character is returned.
|
|
|
|
*
|
|
|
|
* @param source Source input string.
|
|
|
|
* @param arg Stores argument read from string.
|
|
|
|
* @param argLen Maximum length of argument buffer.
|
|
|
|
* @return Index to next piece of string, or -1 if none.
|
|
|
|
*/
|
2007-03-16 21:39:32 +01:00
|
|
|
native StrBreak(const String:source[], String:arg[], argLen);
|