plugins/include/string.inc
author David Anderson <dvander@alliedmods.net>
Sun Oct 28 08:24:47 2007 +0000 (2007-10-28)
changeset 1649 37373aea4dfe
parent 1330 ab94316bb52b
child 1652 eacd2002cda8
permissions -rw-r--r--
fixed macro bug in the sdk
dvander@233
     1
/**
ds@475
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@374
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     5
 * =============================================================================
ds@1330
     6
 *
ds@1330
     7
 * This file is part of the SourceMod/SourcePawn SDK.
dvander@374
     8
 *
ds@1330
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    11
 * Free Software Foundation.
ds@1330
    12
 * 
ds@1330
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    16
 * details.
ds@1330
    17
 *
ds@1330
    18
 * You should have received a copy of the GNU General Public License along with
ds@1330
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1330
    20
 *
ds@1330
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    28
 * or <http://www.sourcemod.net/license.php>.
dvander@374
    29
 *
dvander@374
    30
 * Version: $Id$
dvander@233
    31
 */
dvander@374
    32
 
dvander@233
    33
#if defined _string_included
dvander@233
    34
 #endinput
dvander@233
    35
#endif
dvander@233
    36
#define _string_included
dvander@233
    37
dvander@233
    38
/**
dvander@748
    39
 * @global Unless otherwise noted, all string functions which take in a 
dvander@748
    40
 * writable buffer and maximum length should have the null terminator INCLUDED
dvander@748
    41
 * in the length.  This means that this is valid: 
dvander@1010
    42
 * strcopy(string, sizeof(string), ...)
dvander@233
    43
 */
dvander@631
    44
 
dvander@233
    45
/**
dvander@233
    46
 * Calculates the length of a string.
dvander@233
    47
 *
ds@475
    48
 * @param str			String to check.
ds@475
    49
 * @return				Length of string, in cells (NOT characters).
dvander@233
    50
 */
dvander@233
    51
native strlen(const String:str[]);
dvander@233
    52
dvander@233
    53
/**
dvander@233
    54
 * Tests whether a string is found inside another string.
dvander@233
    55
 *
dvander@233
    56
 * @param str			String to search in.
dvander@233
    57
 * @param substr		Substring to find inside the original string.
dvander@233
    58
 * @param caseSensitive	If true (default), search is case sensitive.
ds@475
    59
 *						If false, search is case insensitive.
ds@475
    60
 * @return				-1 on failure (no match found). Any other value
ds@475
    61
 *						indicates a position in the string where the match starts.
dvander@233
    62
 */
dvander@233
    63
native StrContains(const String:str[], const String:substr[], bool:caseSensitive=true);
dvander@233
    64
dvander@233
    65
/**
dvander@233
    66
 * Compares two strings lexographically.
dvander@233
    67
 *
dvander@233
    68
 * @param str1			First string (left).
dvander@233
    69
 * @param str2			Second string (right).
dvander@233
    70
 * @param caseSensitive	If true (default), comparison is case sensitive.
ds@475
    71
 *						If false, comparison is case insensitive.
ds@475
    72
 * @return				-1 if str1 < str2
ds@475
    73
 *						0 if str1 == str2
ds@475
    74
 *						1 if str1 > str2
dvander@233
    75
 */
dvander@680
    76
native strcmp(const String:str1[], const String:str2[], bool:caseSensitive=true);
dvander@680
    77
dvander@680
    78
/**
dvander@680
    79
 * Compares two strings parts lexographically.
dvander@680
    80
 *
dvander@680
    81
 * @param str1			First string (left).
dvander@680
    82
 * @param str2			Second string (right).
dvander@680
    83
 * @param num			Number of characters to compare.
dvander@680
    84
 * @param caseSensitive	If true (default), comparison is case sensitive.
dvander@680
    85
 *						If false, comparison is case insensitive.
dvander@680
    86
 * @return				-1 if str1 < str2
dvander@680
    87
 *						0 if str1 == str2
dvander@680
    88
 *						1 if str1 > str2
dvander@680
    89
 */
dvander@680
    90
native strncmp(const String:str1[], const String:str2[], num, bool:caseSensitive=true);
dvander@680
    91
dvander@680
    92
/**
dvander@680
    93
 * Backwards compatible stock - StrCompare is now strcmp
dvander@681
    94
 * @deprecated		Renamed to strcmp
dvander@680
    95
 */
ds@1268
    96
#pragma deprecated Use strcmp() instead
dvander@680
    97
stock StrCompare(const String:str1[], const String:str2[], bool:caseSensitive=true)
dvander@680
    98
{
dvander@680
    99
	return strcmp(str1, str2, caseSensitive);
dvander@680
   100
}
dvander@233
   101
dvander@233
   102
/**
dvander@233
   103
 * Returns whether two strings are equal.
dvander@233
   104
 *
dvander@233
   105
 * @param str1			First string (left).
dvander@233
   106
 * @param str2			Second string (right).
dvander@233
   107
 * @param caseSensitive	If true (default), comparison is case sensitive.
dvander@412
   108
 * 						If false, comparison is case insensitive.
dvander@412
   109
 * @return				True if equal, false otherwise.
dvander@233
   110
 */
faluco@234
   111
stock bool:StrEqual(const String:str1[], const String:str2[], bool:caseSensitive=true)
dvander@233
   112
{
ds@1268
   113
	return (strcmp(str1, str2, caseSensitive) == 0);
dvander@233
   114
}
dvander@233
   115
dvander@233
   116
/**
dvander@233
   117
 * Copies one string to another string.
dvander@619
   118
 * @note If the destination buffer is too small to hold the source string, the 
dvander@619
   119
 *       destination will be truncated.
dvander@233
   120
 *
dvander@233
   121
 * @param dest			Destination string buffer to copy to.
dvander@233
   122
 * @param destlen		Destination buffer length (includes null terminator).
dvander@233
   123
 * @param source		Source string buffer to copy from.
dvander@412
   124
 * @return				Number of cells written.
dvander@233
   125
 */
dvander@681
   126
native strcopy(String:dest[], destLen, const String:source[]);
dvander@681
   127
dvander@681
   128
/**
dvander@681
   129
 * Backwards compatibility stock - use strcopy
dvander@681
   130
 * @deprecated			Renamed to strcopy
dvander@681
   131
 */
ds@1268
   132
#pragma deprecated Use strcopy() instead
dvander@681
   133
stock StrCopy(String:dest[], destLen, const String:source[])
dvander@681
   134
{
dvander@681
   135
	return strcopy(dest, destLen, source);
dvander@681
   136
}
dvander@233
   137
dvander@233
   138
/**
dvander@257
   139
 * Formats a string according to the SourceMod format rules (see documentation).
dvander@257
   140
 *
dvander@257
   141
 * @param buffer		Destination string buffer.
dvander@257
   142
 * @param maxlength		Maximum length of output string buffer.
dvander@257
   143
 * @param format		Formatting rules.
dvander@257
   144
 * @param ...			Variable number of format parameters.
dvander@412
   145
 * @return				Number of cells written.
dvander@257
   146
 */
ds@634
   147
native Format(String:buffer[], maxlength, const String:format[], any:...);
dvander@257
   148
dvander@257
   149
/**
dvander@257
   150
 * Formats a string according to the SourceMod format rules (see documentation).
dvander@748
   151
 * @note This is the same as Format(), except none of the input buffers can 
dvander@748
   152
 *       overlap the same memory as the output buffer.  Since this security 
dvander@748
   153
 *       check is removed, it is slightly faster.
dvander@257
   154
 *
dvander@257
   155
 * @param buffer		Destination string buffer.
dvander@257
   156
 * @param maxlength		Maximum length of output string buffer.
dvander@257
   157
 * @param format		Formatting rules.
dvander@257
   158
 * @param ...			Variable number of format parameters.
dvander@412
   159
 * @return				Number of cells written.
dvander@257
   160
 */
ds@634
   161
native FormatEx(String:buffer[], maxlength, const String:format[], any:...);
dvander@257
   162
dvander@257
   163
/**
dvander@412
   164
 * Formats a string according to the SourceMod format rules (see documentation).
dvander@748
   165
 * @note This is the same as Format(), except it grabs parameters from a 
dvander@748
   166
 *       parent parameter stack, rather than a local.  This is useful for 
dvander@748
   167
 *       implementing your own variable argument functions.
dvander@412
   168
 *
dvander@412
   169
 * @param buffer		Destination string buffer.
dvander@412
   170
 * @param maxlength		Maximum length of output string buffer.
dvander@412
   171
 * @param format		Formatting rules.
dvander@412
   172
 * @param varpos		Argument number which contains the '...' symbol.
dvander@412
   173
 *						Note: Arguments start at 1.
dvander@412
   174
 * @return 				Number of bytes written.
dvander@412
   175
 */
dvander@412
   176
native VFormat(String:buffer[], maxlength, const String:format[], varpos);
dvander@412
   177
dvander@412
   178
/**
dvander@233
   179
 * Converts a string to an integer.
dvander@233
   180
 *
dvander@233
   181
 * @param str			String to convert.
dvander@412
   182
 * @param nBase			Numerical base to use.  10 is default.
dvander@412
   183
 * @return				Integer conversion of string, or 0 on failure.
dvander@233
   184
 */
dvander@233
   185
native StringToInt(const String:str[], nBase=10);
dvander@233
   186
dvander@233
   187
/**
dvander@1072
   188
 * Converts a string to an integer with some more options.
dvander@1072
   189
 *
dvander@1072
   190
 * @param str			String to convert.
dvander@1072
   191
 * @param result		Variable to store the result in.
dvander@1072
   192
 * @param nBase			Numerical base to use.  10 is default.
dvander@1072
   193
 * @return				Number of characters consumed.
dvander@1072
   194
 */
dvander@1072
   195
native StringToIntEx(const String:str[], &result, nBase=10);
dvander@1072
   196
dvander@1072
   197
/**
dvander@233
   198
 * Converts an integer to a string.
dvander@233
   199
 *
dvander@451
   200
 * @param num			Integer to convert.
dvander@233
   201
 * @param str			Buffer to store string in.
dvander@233
   202
 * @param maxlength		Maximum length of string buffer.
dvander@412
   203
 * @return				Number of cells written to buffer.
dvander@233
   204
 */
dvander@451
   205
native IntToString(num, String:str[], maxlength);
dvander@233
   206
dvander@233
   207
/** 
dvander@233
   208
 * Converts a string to a floating point number.
dvander@233
   209
 *
dvander@233
   210
 * @param str			String to convert to a foat.
dvander@412
   211
 * @return				Floating point result, or 0.0 on error.
dvander@233
   212
 */
dvander@233
   213
native Float:StringToFloat(const String:str[]);
dvander@233
   214
dvander@1072
   215
/** 
dvander@1072
   216
 * Converts a string to a floating point number with some more options.
dvander@1072
   217
 *
dvander@1072
   218
 * @param str			String to convert to a foat.
dvander@1072
   219
 * @param result		Variable to store result in.
dvander@1072
   220
 * @return				Number of characters consumed.
dvander@1072
   221
 */
dvander@1072
   222
native StringToFloatEx(const String:str[], &Float:result);
dvander@1072
   223
dvander@233
   224
/**
dvander@233
   225
 * Converts a floating point number to a string.
dvander@233
   226
 *
ds@454
   227
 * @param num			Floating point number to convert.
dvander@233
   228
 * @param str			Buffer to store string in.
dvander@233
   229
 * @param maxlength		Maximum length of string buffer.
dvander@412
   230
 * @return				Number of cells written to buffer.
dvander@233
   231
 */
ds@454
   232
native FloatToString(Float:num, String:str[], maxlength);
dvander@631
   233
dvander@631
   234
/**
dvander@631
   235
 * Finds the first "argument" in a string; either a set of space
dvander@631
   236
 * terminated characters, or a fully quoted string.  After the 
dvander@631
   237
 * argument is found, whitespace is read until the next portion
dvander@631
   238
 * of the string is reached.  If nothing remains, -1 is returned.
dvander@631
   239
 * Otherwise, the index to the first character is returned.
dvander@631
   240
 *
dvander@631
   241
 * @param source		Source input string.
dvander@631
   242
 * @param arg			Stores argument read from string.
dvander@631
   243
 * @param argLen		Maximum length of argument buffer.
dvander@631
   244
 * @return				Index to next piece of string, or -1 if none.
dvander@631
   245
 */
ds@830
   246
native BreakString(const String:source[], String:arg[], argLen);
ds@830
   247
ds@830
   248
/**
ds@830
   249
 * Backwards compatibility stock - use BreakString
ds@830
   250
 * @deprecated			Renamed to BreakString.
ds@830
   251
 */
ds@1268
   252
#pragma deprecated Use BreakString() instead
ds@830
   253
stock StrBreak(const String:source[], String:arg[], argLen)
ds@830
   254
{
ds@830
   255
	return BreakString(source, arg, argLen);
ds@830
   256
}
dvander@748
   257
dvander@833
   258
/**
ds@839
   259
 * Removes whitespace characters from the beginning and end of a string.
ds@839
   260
 *
ds@839
   261
 * @param str			The string to trim.
ds@839
   262
 * @return				Number of bytes written (UTF-8 safe).
ds@839
   263
 */
ds@839
   264
native TrimString(String:str[]);
ds@839
   265
ds@839
   266
/**
dvander@834
   267
 * Returns text in a string up until a certain character sequence is reached.
dvander@834
   268
 *
dvander@834
   269
 * @param source		Source input string.
ds@839
   270
 * @param split			A string which specifies a search point to break at.
dvander@834
   271
 * @param part			Buffer to store string part.
dvander@834
   272
 * @param partLen		Maximum length of the string part buffer.
dvander@834
   273
 * @return				-1 if no match was found; otherwise, an index into source
dvander@834
   274
 *						marking the first index after the searched text.  The
dvander@834
   275
 *						index is always relative to the start of the input string.
dvander@834
   276
 */
dvander@834
   277
native SplitString(const String:source[], const String:split[], String:part[], partLen);
dvander@834
   278
dvander@834
   279
/**
dvander@833
   280
 * Given a string, replaces all occurrences of a search string with a 
dvander@833
   281
 * replacement string.
dvander@833
   282
 *
dvander@833
   283
 * @param text			String to perform search and replacements on.
dvander@833
   284
 * @param maxlength		Maximum length of the string buffer.
dvander@833
   285
 * @param search		String to search for.
dvander@833
   286
 * @param replace		String to replace the search string with.
dvander@833
   287
 * @return				Number of replacements that were performed.
dvander@833
   288
 */
dvander@833
   289
native ReplaceString(String:text[], maxlength, const String:search[], const String:replace[]);
dvander@833
   290
dvander@833
   291
/**
dvander@833
   292
 * Given a string, replaces the first occurrence of a search string with a 
dvander@833
   293
 * replacement string.
dvander@833
   294
 *
dvander@833
   295
 * @param text			String to perform search and replacements on.
dvander@833
   296
 * @param maxlength		Maximum length of the string buffer.
dvander@833
   297
 * @param search		String to search for.
dvander@833
   298
 * @param replace		String to replace the search string with.
dvander@833
   299
 * @param searchLen		If higher than -1, its value will be used instead of
dvander@833
   300
 *						a strlen() call on the search parameter.
dvander@833
   301
 * @param replaceLen	If higher than -1, its value will be used instead of
dvander@833
   302
 *						a strlen() call on the replace parameter.
dvander@833
   303
 * @return				Index into the buffer (relative to the start) from where
dvander@833
   304
 *						the last replacement ended, or -1 if no replacements were
dvander@833
   305
 *						made.
dvander@833
   306
 */
dvander@833
   307
native ReplaceStringEx(String:text[], maxlength, const String:search[], const String:replace[], searchLen=-1, replaceLen=-1);
dvander@833
   308
dvander@748
   309
/** 
dvander@748
   310
 * Returns the number of bytes a character is using.  This is
dvander@748
   311
 * for multi-byte characters (UTF-8).  For normal ASCII characters,
dvander@748
   312
 * this will return 1.
dvander@748
   313
 *
dvander@748
   314
 * @param source		Source input string.
dvander@748
   315
 * @return				Number of bytes the current character uses.
dvander@748
   316
 */
dvander@748
   317
native GetCharBytes(const String:source[]);
dvander@748
   318
dvander@748
   319
/**
dvander@748
   320
 * Returns whether a character is an ASCII alphabet character.
dvander@748
   321
 *
dvander@748
   322
 * @note Multi-byte characters will always return false.
dvander@748
   323
 *
dvander@748
   324
 * @param char			Character to test.
dvander@748
   325
 * @return				True if character is alphabetical, otherwise false.
dvander@748
   326
 */
dvander@748
   327
native bool:IsCharAlpha(chr);
dvander@748
   328
dvander@748
   329
/**
dvander@748
   330
 * Returns whether a character is numeric.
dvander@748
   331
 *
dvander@748
   332
 * @note Multi-byte characters will always return false.
dvander@748
   333
 *
dvander@748
   334
 * @param char			Character to test.
dvander@748
   335
 * @return				True if character is numeric, otherwise false.
dvander@748
   336
 */
dvander@748
   337
native bool:IsCharNumeric(chr);
dvander@748
   338
dvander@748
   339
/**
dvander@748
   340
 * Returns whether a character is whitespace.
dvander@748
   341
 *
dvander@748
   342
 * @note Multi-byte characters will always return false.
dvander@748
   343
 *
dvander@748
   344
 * @param char			Character to test.
dvander@748
   345
 * @return				True if character is whitespace, otherwise false.
dvander@748
   346
 */
dvander@748
   347
native bool:IsCharSpace(chr);
dvander@748
   348
dvander@748
   349
/**
dvander@748
   350
 * Returns if a character is multi-byte or not.
dvander@748
   351
 *
dvander@748
   352
 * @param char			Character to test.
dvander@748
   353
 * @return				0 for a normal 7-bit ASCII character,
dvander@748
   354
 *						otherwise number of bytes in multi-byte character.
dvander@748
   355
 */
dvander@748
   356
native IsCharMB(chr);
dvander@748
   357
dvander@748
   358
/**
dvander@748
   359
 * Returns whether an alphabetic character is uppercase.
dvander@748
   360
 *
dvander@748
   361
 * @note Multi-byte characters will always return false.
dvander@748
   362
 *
dvander@748
   363
 * @param char			Character to test.
dvander@748
   364
 * @return				True if character is uppercase, otherwise false.
dvander@748
   365
 */
dvander@748
   366
native bool:IsCharUpper(chr);
dvander@748
   367
dvander@748
   368
/**
dvander@748
   369
 * Returns whether an alphabetic character is lowercase.
dvander@748
   370
 *
dvander@748
   371
 * @note Multi-byte characters will always return false.
dvander@748
   372
 *
dvander@748
   373
 * @param char			Character to test.
dvander@748
   374
 * @return				True if character is lowercase, otherwise false.
dvander@748
   375
 */
dvander@748
   376
native bool:IsCharLower(chr);
dvander@748
   377
dvander@748
   378
/**
dvander@748
   379
 * Returns an uppercase character to a lowercase character.
dvander@748
   380
 *
dvander@748
   381
 * @param chr			Characer to convert.
dvander@748
   382
 * @return				Lowercase character on success, 
dvander@748
   383
 *						no change on failure.
dvander@748
   384
 */
dvander@748
   385
stock CharToUpper(chr)
dvander@748
   386
{
dvander@748
   387
	if (IsCharLower(chr))
dvander@748
   388
	{
dvander@748
   389
		return (chr & ~(1<<5));
dvander@748
   390
	}
dvander@748
   391
	return chr;
dvander@748
   392
}
dvander@748
   393
dvander@748
   394
/**
dvander@748
   395
 * Returns a lowercase character to an uppercase character.
dvander@748
   396
 *
dvander@748
   397
 * @param chr			Characer to convert.
dvander@748
   398
 * @return				Uppercase character on success, 
dvander@748
   399
 *						no change on failure.
dvander@748
   400
 */
dvander@748
   401
stock CharToLower(chr)
dvander@748
   402
{
dvander@748
   403
	if (IsCharUpper(chr))
dvander@748
   404
	{
dvander@748
   405
		return (chr | (1<<5));
dvander@748
   406
	}
dvander@748
   407
	return chr;
dvander@748
   408
}
dvander@748
   409
dvander@749
   410
/**
dvander@749
   411
 * Concatenates one string onto another.
dvander@749
   412
 *
dvander@749
   413
 * @param buffer		String to append to.
dvander@749
   414
 * @param maxlength		Maximum length of entire buffer.
dvander@749
   415
 * @param source		Source string to concatenate.
dvander@749
   416
 * @return				Number of bytes written.
dvander@749
   417
 */
dvander@749
   418
stock StrCat(String:buffer[], maxlength, const String:source[])
dvander@749
   419
{
teame06@1254
   420
	new len = strlen(buffer);
dvander@749
   421
	if (len >= maxlength)
dvander@749
   422
	{
dvander@749
   423
		return 0;
dvander@749
   424
	}
dvander@749
   425
	
dvander@749
   426
	return Format(buffer[len], maxlength-len, "%s", source);
dvander@749
   427
}
ds@830
   428
ds@830
   429
/**
dvander@834
   430
 * Breaks a string into pieces and stores each piece into an array of buffers.
dvander@834
   431
 *
dvander@834
   432
 * @param text				The string to split.
dvander@834
   433
 * @param split				The string to use as a split delimiter.
dvander@834
   434
 * @param buffers			An array of string buffers (2D array).
dvander@834
   435
 * @param maxStrings		Number of string buffers (first dimension size).
dvander@834
   436
 * @param maxStringLength	Maximum length of each string buffer.
dvander@834
   437
 * @return					Number of strings retrieved.
dvander@834
   438
 */
dvander@834
   439
stock ExplodeString(const String:text[], const String:split[], String:buffers[][], maxStrings, maxStringLength)
dvander@834
   440
{
dvander@834
   441
	new reloc_idx, idx, total;
dvander@834
   442
	
dvander@834
   443
	if (maxStrings < 1 || split[0] == '\0')
dvander@834
   444
	{
dvander@834
   445
		return 0;
dvander@834
   446
	}
dvander@834
   447
	
dvander@834
   448
	while ((idx = SplitString(text[reloc_idx], split, buffers[total], maxStringLength)) != -1)
dvander@834
   449
	{
dvander@834
   450
		reloc_idx += idx;
dvander@834
   451
		if (text[reloc_idx] == '\0')
dvander@834
   452
		{
dvander@834
   453
			break;
dvander@834
   454
		}
dvander@834
   455
		if (++total >= maxStrings)
dvander@834
   456
		{
dvander@834
   457
			return total;
dvander@834
   458
		}
dvander@834
   459
	}
dvander@834
   460
	
dvander@834
   461
	if (text[reloc_idx] != '\0' && total <= maxStrings - 1)
dvander@834
   462
	{
dvander@834
   463
		strcopy(buffers[total++], maxStringLength, text[reloc_idx]);
dvander@834
   464
	}
dvander@834
   465
	
dvander@834
   466
	return total;
dvander@834
   467
}
dvander@834
   468
dvander@834
   469
/**
dvander@834
   470
 * Joins an array of strings into one string, with a "join" string inserted in
dvander@834
   471
 * between each given string.  This function complements ExplodeString.
dvander@834
   472
 *
dvander@834
   473
 * @param strings		An array of strings.
dvander@834
   474
 * @param numStrings	Number of strings in the array.
dvander@834
   475
 * @param join			The join string to insert between each string.
dvander@834
   476
 * @param buffer		Output buffer to write the joined string to.
dvander@834
   477
 * @param maxLength		Maximum length of the output buffer.
dvander@834
   478
 * @return				Number of bytes written to the output buffer.
dvander@834
   479
 */
dvander@834
   480
stock ImplodeStrings(const String:strings[][], numStrings, const String:join[], String:buffer[], maxLength)
dvander@834
   481
{
dvander@834
   482
	new total, length, part_length;
dvander@834
   483
	new join_length = strlen(join);
dvander@834
   484
	for (new i=0; i<numStrings; i++)
dvander@834
   485
	{
dvander@834
   486
		length = strcopy(buffer[total], maxLength-total, strings[i]);
dvander@834
   487
		total += length;
dvander@834
   488
		if (length < part_length)
dvander@834
   489
		{
dvander@834
   490
			break;
dvander@834
   491
		}
dvander@834
   492
		if (i != numStrings - 1)
dvander@834
   493
		{
dvander@834
   494
			length = strcopy(buffer[total], maxLength-total, join);
dvander@834
   495
			total += length;
dvander@834
   496
			if (length < join_length)
dvander@834
   497
			{
dvander@834
   498
				break;
dvander@834
   499
			}
dvander@834
   500
		}
dvander@834
   501
	}
dvander@834
   502
	return total;
dvander@834
   503
}