plugins/include/string.inc
author Borja Ferrer <faluco@alliedmods.net>
Sat Dec 30 19:01:23 2006 +0000 (2006-12-30)
changeset 234 6bd6eca451bb
parent 233 968f92668138
child 257 583a23434070
permissions -rw-r--r--
tiny fixes
     1 /**
     2  * :TODO: license info
     3  */
     4 
     5 #if defined _string_included
     6  #endinput
     7 #endif
     8 #define _string_included
     9 
    10 /**
    11  * @GLOBAL@
    12  *   Unless otherwise noted, all string functions which take in a writable buffer and maximum length
    13  * should have the null terminator INCLUDED in the length.  This means that this is valid:
    14  *   StrCopy(string, sizeof(string), ...)
    15  */
    16 
    17 /**
    18  * Calculates the length of a string.
    19  *
    20  * @param str		String to check.
    21  * @return		Length of string, in cells (NOT characters).
    22  */
    23 native strlen(const String:str[]);
    24 
    25 /**
    26  * Tests whether a string is found inside another string.
    27  *
    28  * @param str			String to search in.
    29  * @param substr		Substring to find inside the original string.
    30  * @param caseSensitive	If true (default), search is case sensitive.
    31  * 					If false, search is case insensitive.
    32  * @return			-1 on failure (no match found).  Any other value
    33  *					indicates a position in the string where the match starts.
    34  */
    35 native StrContains(const String:str[], const String:substr[], bool:caseSensitive=true);
    36 
    37 /**
    38  * Compares two strings lexographically.
    39  *
    40  * @param str1			First string (left).
    41  * @param str2			Second string (right).
    42  * @param caseSensitive	If true (default), comparison is case sensitive.
    43  * 					If false, comparison is case insensitive.
    44  * @return			-1 if str1 < str2
    45  *					0 if str1 == str2
    46  * 					1 if str1 > str2
    47  */
    48 native StrCompare(const String:str1[], const String:str2[], bool:caseSensitive=true);
    49 
    50 /**
    51  * Returns whether two strings are equal.
    52  *
    53  *
    54  * @param str1			First string (left).
    55  * @param str2			Second string (right).
    56  * @param caseSensitive	If true (default), comparison is case sensitive.
    57  * 					If false, comparison is case insensitive.
    58  * @return			True if equal, false otherwise.
    59  */
    60 stock bool:StrEqual(const String:str1[], const String:str2[], bool:caseSensitive=true)
    61 {
    62 	return (StrCompare(str1, str2, caseSensitive) == 0);
    63 }
    64 
    65 /**
    66  * Copies one string to another string.
    67  * NOTE: If the destination buffer is too small to hold the source string,
    68  * the destination will be truncated.
    69  *
    70  * @param dest			Destination string buffer to copy to.
    71  * @param destlen		Destination buffer length (includes null terminator).
    72  * @param source		Source string buffer to copy from.
    73  * @return			Number of cells written.
    74  */
    75 native StrCopy(String:dest[], destLen, const String:source[]);
    76 
    77 /**
    78  * Converts a string to an integer.
    79  *
    80  * @param str			String to convert.
    81  * @param nBase		Numerical base to use.  10 is default.
    82  * @return			Integer conversion of string, or 0 on failure.
    83  */
    84 native StringToInt(const String:str[], nBase=10);
    85 
    86 /**
    87  * Converts an integer to a string.
    88  *
    89  * @param str			Buffer to store string in.
    90  * @param maxlength		Maximum length of string buffer.
    91  * @param num			Integer to convert.
    92  * @return			Number of cells written to buffer.
    93  */
    94 native IntToString(String:str[], maxlength, num);
    95 
    96 /** 
    97  * Converts a string to a floating point number.
    98  *
    99  * @param str			String to convert to a foat.
   100  * @return			Floating point result, or 0.0 on error.
   101  */
   102 native Float:StringToFloat(const String:str[]);
   103 
   104 /**
   105  * Converts a floating point number to a string.
   106  *
   107  * @param str			Buffer to store string in.
   108  * @param maxlength		Maximum length of string buffer.
   109  * @param num			Floating point number to convert.
   110  * @return			Number of cells written to buffer.
   111  */
   112 native FloatToString(String:str[], maxlength, Float:num);