Creating/Firing/Canceling events now use CStack to avoid the need to use new when possible
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _string_included
19 #define _string_included
23 * Unless otherwise noted, all string functions which take in a writable buffer and maximum length
24 * should have the null terminator INCLUDED in the length. This means that this is valid:
25 * StrCopy(string, sizeof(string), ...)
29 * Calculates the length of a string.
31 * @param str String to check.
32 * @return Length of string, in cells (NOT characters).
34 native strlen(const String:str[]);
37 * Tests whether a string is found inside another string.
39 * @param str String to search in.
40 * @param substr Substring to find inside the original string.
41 * @param caseSensitive If true (default), search is case sensitive.
42 * If false, search is case insensitive.
43 * @return -1 on failure (no match found). Any other value
44 * indicates a position in the string where the match starts.
46 native StrContains(const String:str[], const String:substr[], bool:caseSensitive=true);
49 * Compares two strings lexographically.
51 * @param str1 First string (left).
52 * @param str2 Second string (right).
53 * @param caseSensitive If true (default), comparison is case sensitive.
54 * If false, comparison is case insensitive.
55 * @return -1 if str1 < str2
59 native StrCompare(const String:str1[], const String:str2[], bool:caseSensitive=true);
62 * Returns whether two strings are equal.
65 * @param str1 First string (left).
66 * @param str2 Second string (right).
67 * @param caseSensitive If true (default), comparison is case sensitive.
68 * If false, comparison is case insensitive.
69 * @return True if equal, false otherwise.
71 stock bool:StrEqual(const String:str1[], const String:str2[], bool:caseSensitive=true)
73 return (StrCompare(str1, str2, caseSensitive) == 0);
77 * Copies one string to another string.
78 * NOTE: If the destination buffer is too small to hold the source string,
79 * the destination will be truncated.
81 * @param dest Destination string buffer to copy to.
82 * @param destlen Destination buffer length (includes null terminator).
83 * @param source Source string buffer to copy from.
84 * @return Number of cells written.
86 native StrCopy(String:dest[], destLen, const String:source[]);
89 * Formats a string according to the SourceMod format rules (see documentation).
91 * @param buffer Destination string buffer.
92 * @param maxlength Maximum length of output string buffer.
93 * @param format Formatting rules.
94 * @param ... Variable number of format parameters.
95 * @return Number of cells written.
97 native Format(String:buffer[], maxlength, const String:format[], {Handle,Float,String,_}:...);
100 * Formats a string according to the SourceMod format rules (see documentation).
101 * @note This is the same as Format(), except none of the input buffers can overlap the same
102 * memory as the output buffer. Since this security check is removed, it is slightly faster.
104 * @param buffer Destination string buffer.
105 * @param maxlength Maximum length of output string buffer.
106 * @param format Formatting rules.
107 * @param ... Variable number of format parameters.
108 * @return Number of cells written.
110 native FormatEx(String:buffer[], maxlength, const String:format[], {Handle,Float,String,_}:...);
113 * Formats a string according to the SourceMod format rules (see documentation).
114 * @note This is the same as Format(), except it grabs parameters from a parent parameter
115 * stack, rather than a local. This is useful for implementing your own variable argument
118 * @param buffer Destination string buffer.
119 * @param maxlength Maximum length of output string buffer.
120 * @param format Formatting rules.
121 * @param varpos Argument number which contains the '...' symbol.
122 * Note: Arguments start at 1.
123 * @return Number of bytes written.
125 native VFormat(String:buffer[], maxlength, const String:format[], varpos);
128 * Converts a string to an integer.
130 * @param str String to convert.
131 * @param nBase Numerical base to use. 10 is default.
132 * @return Integer conversion of string, or 0 on failure.
134 native StringToInt(const String:str[], nBase=10);
137 * Converts an integer to a string.
139 * @param num Integer to convert.
140 * @param str Buffer to store string in.
141 * @param maxlength Maximum length of string buffer.
142 * @return Number of cells written to buffer.
144 native IntToString(num, String:str[], maxlength);
147 * Converts a string to a floating point number.
149 * @param str String to convert to a foat.
150 * @return Floating point result, or 0.0 on error.
152 native Float:StringToFloat(const String:str[]);
155 * Converts a floating point number to a string.
157 * @param num Floating point number to convert.
158 * @param str Buffer to store string in.
159 * @param maxlength Maximum length of string buffer.
160 * @return Number of cells written to buffer.
162 native FloatToString(Float:num, String:str[], maxlength);