platformString.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PLATFORM_STRING_H_
  23. #define _PLATFORM_STRING_H_
  24. #ifndef _TORQUE_TYPES_H_
  25. #include "platform/types.h"
  26. #endif
  27. #include <stdarg.h>
  28. //------------------------------------------------------------------------------
  29. extern U32 dStrlen(const char *str);
  30. extern char* dStrcat(char *dst, const char *src);
  31. extern UTF8* dStrcat(UTF8 *dst, const UTF8 *src);
  32. extern char* dStrncat(char* dst, const char* src, dsize_t len);
  33. extern char* dStrcatl(char *dst, dsize_t dstSize, ...);
  34. extern int dStrcmp(const char *str1, const char *str2);
  35. extern int dStrcmp(const UTF16 *str1, const UTF16 *str2);
  36. extern int dStrcmp(const UTF8 *str1, const UTF8 *str2);
  37. extern int dStricmp(const char *str1, const char *str2);
  38. extern int dStrncmp(const char *str1, const char *str2, dsize_t len);
  39. extern int dStrnicmp(const char *str1, const char *str2, dsize_t len);
  40. extern char* dStrcpy(char *dst, const char *src);
  41. extern char* dStrcpyl(char *dst, dsize_t dstSize, ...);
  42. extern char* dStrncpy(char *dst, const char *src, dsize_t len);
  43. extern char* dStrncpy(UTF8 *dst, const UTF8 *src, dsize_t len);
  44. extern char* dStrupr(char *str);
  45. extern char* dStrlwr(char *str);
  46. inline char dToupper(const char c) { if (c >= char('a') && c <= char('z')) return char(c + 'A' - 'a'); else return c; }
  47. inline char dTolower(const char c) { if (c >= char('A') && c <= char('Z')) return char(c - 'A' + 'a'); else return c; }
  48. extern char* dStrchr(char *str, int c);
  49. extern const char* dStrchr(const char *str, int c);
  50. extern char* dStrrchr(char *str, int c);
  51. extern const char* dStrrchr(const char *str, int c);
  52. extern U32 dStrspn(const char *str, const char *set);
  53. extern U32 dStrcspn(const char *str, const char *set);
  54. extern char* dStrstr(char *str1, const char *str2);
  55. extern const char* dStrstr(const char *str1, const char *str2);
  56. extern char* dStrtok(char *str, const char *sep);
  57. extern int dStrrev(char* str);
  58. extern int dAtoi(const char *str);
  59. extern float dAtof(const char *str);
  60. extern bool dAtob(const char *str);
  61. extern int dItoa(int n, char s[]);
  62. extern bool dIsalnum(const char c);
  63. extern bool dIsalpha(const char c);
  64. extern bool dIsdigit(const char c);
  65. extern bool dIsspace(const char c);
  66. extern int dSscanf(const char *buffer, const char *format, ...);
  67. extern int dFflushStdout();
  68. extern int dFflushStderr();
  69. extern void dPrintf(const char *format, ...);
  70. extern int dVprintf(const char *format, va_list arglist);
  71. extern int dSprintf(char *buffer, dsize_t bufferSize, const char *format, ...);
  72. extern int dVsprintf(char *buffer, dsize_t bufferSize, const char *format, va_list arglist);
  73. #define QSORT_CALLBACK FN_CDECL
  74. extern void dQsort(void *base, U32 nelem, U32 width, int (QSORT_CALLBACK *fcmp)(const void *, const void *));
  75. // UNICODE is a windows platform API switching flag. Don't define it on other platforms.
  76. #ifdef UNICODE
  77. #define dT(s) L##s
  78. #else
  79. #define dT(s) s
  80. #endif
  81. #define dStrdup(x) dStrdup_r(x, __FILE__, __LINE__)
  82. extern char* dStrdup_r(const char *src, const char*, dsize_t);
  83. #endif // _PLATFORM_STRING_H_