1.1 --- a/plugins/include/string.inc Sun May 06 19:52:00 2007 +0000
1.2 +++ b/plugins/include/string.inc Sun May 06 23:12:54 2007 +0000
1.3 @@ -19,9 +19,10 @@
1.4 #define _string_included
1.5
1.6 /**
1.7 - * @global Unless otherwise noted, all string functions which take in a writable buffer
1.8 - * and maximum length should have the null terminator INCLUDED in the length. This means
1.9 - * that this is valid: StrCopy(string, sizeof(string), ...)
1.10 + * @global Unless otherwise noted, all string functions which take in a
1.11 + * writable buffer and maximum length should have the null terminator INCLUDED
1.12 + * in the length. This means that this is valid:
1.13 + * StrCopy(string, sizeof(string), ...)
1.14 */
1.15
1.16 /**
1.17 @@ -129,8 +130,9 @@
1.18
1.19 /**
1.20 * Formats a string according to the SourceMod format rules (see documentation).
1.21 - * @note This is the same as Format(), except none of the input buffers can overlap the same
1.22 - * memory as the output buffer. Since this security check is removed, it is slightly faster.
1.23 + * @note This is the same as Format(), except none of the input buffers can
1.24 + * overlap the same memory as the output buffer. Since this security
1.25 + * check is removed, it is slightly faster.
1.26 *
1.27 * @param buffer Destination string buffer.
1.28 * @param maxlength Maximum length of output string buffer.
1.29 @@ -142,9 +144,9 @@
1.30
1.31 /**
1.32 * Formats a string according to the SourceMod format rules (see documentation).
1.33 - * @note This is the same as Format(), except it grabs parameters from a parent parameter
1.34 - * stack, rather than a local. This is useful for implementing your own variable
1.35 - * argument functions.
1.36 + * @note This is the same as Format(), except it grabs parameters from a
1.37 + * parent parameter stack, rather than a local. This is useful for
1.38 + * implementing your own variable argument functions.
1.39 *
1.40 * @param buffer Destination string buffer.
1.41 * @param maxlength Maximum length of output string buffer.
1.42 @@ -205,3 +207,106 @@
1.43 * @return Index to next piece of string, or -1 if none.
1.44 */
1.45 native StrBreak(const String:source[], String:arg[], argLen);
1.46 +
1.47 +/**
1.48 + * Returns the number of bytes a character is using. This is
1.49 + * for multi-byte characters (UTF-8). For normal ASCII characters,
1.50 + * this will return 1.
1.51 + *
1.52 + * @param source Source input string.
1.53 + * @return Number of bytes the current character uses.
1.54 + */
1.55 +native GetCharBytes(const String:source[]);
1.56 +
1.57 +/**
1.58 + * Returns whether a character is an ASCII alphabet character.
1.59 + *
1.60 + * @note Multi-byte characters will always return false.
1.61 + *
1.62 + * @param char Character to test.
1.63 + * @return True if character is alphabetical, otherwise false.
1.64 + */
1.65 +native bool:IsCharAlpha(chr);
1.66 +
1.67 +/**
1.68 + * Returns whether a character is numeric.
1.69 + *
1.70 + * @note Multi-byte characters will always return false.
1.71 + *
1.72 + * @param char Character to test.
1.73 + * @return True if character is numeric, otherwise false.
1.74 + */
1.75 +native bool:IsCharNumeric(chr);
1.76 +
1.77 +/**
1.78 + * Returns whether a character is whitespace.
1.79 + *
1.80 + * @note Multi-byte characters will always return false.
1.81 + *
1.82 + * @param char Character to test.
1.83 + * @return True if character is whitespace, otherwise false.
1.84 + */
1.85 +native bool:IsCharSpace(chr);
1.86 +
1.87 +/**
1.88 + * Returns if a character is multi-byte or not.
1.89 + *
1.90 + * @param char Character to test.
1.91 + * @return 0 for a normal 7-bit ASCII character,
1.92 + * otherwise number of bytes in multi-byte character.
1.93 + */
1.94 +native IsCharMB(chr);
1.95 +
1.96 +/**
1.97 + * Returns whether an alphabetic character is uppercase.
1.98 + *
1.99 + * @note Multi-byte characters will always return false.
1.100 + *
1.101 + * @param char Character to test.
1.102 + * @return True if character is uppercase, otherwise false.
1.103 + */
1.104 +native bool:IsCharUpper(chr);
1.105 +
1.106 +/**
1.107 + * Returns whether an alphabetic character is lowercase.
1.108 + *
1.109 + * @note Multi-byte characters will always return false.
1.110 + *
1.111 + * @param char Character to test.
1.112 + * @return True if character is lowercase, otherwise false.
1.113 + */
1.114 +native bool:IsCharLower(chr);
1.115 +
1.116 +/**
1.117 + * Returns an uppercase character to a lowercase character.
1.118 + *
1.119 + * @param chr Characer to convert.
1.120 + * @return Lowercase character on success,
1.121 + * no change on failure.
1.122 + */
1.123 +stock CharToUpper(chr)
1.124 +{
1.125 + if (IsCharLower(chr))
1.126 + {
1.127 + return (chr & ~(1<<5));
1.128 + }
1.129 + return chr;
1.130 +}
1.131 +
1.132 +/**
1.133 + * Returns a lowercase character to an uppercase character.
1.134 + *
1.135 + * @param chr Characer to convert.
1.136 + * @return Uppercase character on success,
1.137 + * no change on failure.
1.138 + */
1.139 +stock CharToLower(chr)
1.140 +{
1.141 + if (IsCharUpper(chr))
1.142 + {
1.143 + return (chr | (1<<5));
1.144 + }
1.145 + return chr;
1.146 +}
1.147 +
1.148 +