com_string.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
  3. Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
  4. Copyright (C) 1997-2001 Id Software, Inc.
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. * com_string.h: Common string functions done in a portable manner.
  19. *
  20. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  21. *
  22. * Acknowledgement:
  23. * Portion of this code was derived from Quake II, and was originally
  24. * written by Id Software, Inc.
  25. *
  26. * Portion of this code was derived from code that was originally
  27. * written by Todd C. Miller.
  28. *
  29. */
  30. /*
  31. Notes:
  32. This module is implemented by com_string.c.
  33. */
  34. #ifndef __COM_STRING_H__
  35. #define __COM_STRING_H__
  36. #define ISSPACE( c ) ( ( c ) == ' ' || ( c ) == '\f' || ( c ) == '\n' || ( c ) == '\r' || ( c ) == '\t' || ( c ) == '\v' )
  37. #define ISUPPER( c ) ( ( c ) >= 'A' && ( c ) <= 'Z' )
  38. #define ISLOWER( c ) ( ( c ) >= 'a' && ( c ) <= 'z' )
  39. #define ISALPHA( c ) ( ISUPPER( c ) || ISLOWER( c ) )
  40. #define TOUPPER( c ) ( ISLOWER( c ) ? (c) - 'a' + 'A' : ( c ) )
  41. #define TOLOWER( c ) ( ISUPPER( c ) ? (c) - 'A' + 'a' : ( c ) )
  42. #define ISNUMERIC( c ) ( ( c ) >= '0' && ( c ) <= '9' )
  43. #define ISALPHANUMERIC( c ) ( ISALPHA( c ) || ISNUMERIC( c ) )
  44. extern size_t my_strlcpy( char *dest, const char *source, size_t nMaxLength );
  45. extern size_t my_strlcat( char *dest, const char *source, size_t nMaxLength );
  46. extern int my_stricmp( const char *string1, const char *string2 );
  47. extern int my_strnicmp( const char *string1, const char *string2, size_t count );
  48. extern void my_snprintf( char *dest, size_t size, const char *format, ... );
  49. extern char *my_CopyString( const char *in );
  50. extern W32 my_strhash( const char *string );
  51. extern char *my_strupr( char *string );
  52. extern char *my_strlwr( char *string );
  53. /* String conversion error */
  54. #define SCE_NON_NUMERIC (1 << 0) /* Non-numeric value was encountered */
  55. #define SCE_BUFFER_OVERFLOW (1 << 1) /* Numberic overflowed */
  56. #define SCE_NULL_VALUE (1 << 2) /* NULL string was passed into function */
  57. extern SW32 StringToInteger( const char *string, W32 *error );
  58. extern double StringToFloat( const char *string, W32 *error );
  59. #endif /* __COM_STRING_H__ */