| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : Command & Conquer *
- * *
- * $Archive:: /VSS_Sync/wwlib/trim.cpp $*
- * *
- * $Author:: Vss_sync $*
- * *
- * $Modtime:: 8/29/01 10:24p $*
- * *
- * $Revision:: 3 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "always.h"
- #include "trim.h"
- #include <ctype.h>
- #include <stddef.h>
- #include <string.h>
- #ifdef _UNIX
- #include <wctype.h>
- #endif // _UNIX
- /***********************************************************************************************
- * strtrim -- Trim leading and trailing white space off of string. *
- * *
- * This routine will remove the leading and trailing whitespace from the string specifed. *
- * The string is modified in place. *
- * *
- * INPUT: buffer -- Pointer to the string to be trimmed. *
- * *
- * OUTPUT: none *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 02/06/1997 JLB : Created. *
- *=============================================================================================*/
- char * strtrim(char * buffer)
- {
- if (buffer != NULL) {
- /*
- ** Strip leading white space from the string.
- */
- char * source = buffer;
- while (isspace(*source)) {
- source++;
- }
- if (source != buffer) {
- strcpy(buffer, source);
- }
- /*
- ** Clip trailing white space from the string.
- */
- for (int index = strlen(buffer)-1; index >= 0; index--) {
- if (isspace(buffer[index])) {
- buffer[index] = '\0';
- } else {
- break;
- }
- }
- }
- return(buffer);
- }
- wchar_t * wcstrim(wchar_t * buffer)
- {
- if (buffer != NULL) {
- /*
- ** Strip leading white space from the string.
- */
- wchar_t * source = buffer;
- while (iswspace(*source)) {
- source++;
- }
- if (source != buffer) {
- wcscpy(buffer, source);
- }
- /*
- ** Clip trailing white space from the string.
- */
- for (int index = wcslen(buffer)-1; index >= 0; index--) {
- if (iswspace(buffer[index])) {
- buffer[index] = L'\0';
- } else {
- break;
- }
- }
- }
- return(buffer);
- }
|