Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
1.8 KiB

  1. #ifndef TIER1_STRTOOLS_INLINES_H
  2. #define TIER1_STRTOOLS_INLINES_H
  3. inline int _V_strlen_inline( const char *str )
  4. {
  5. #ifdef POSIX
  6. if ( !str )
  7. return 0;
  8. #endif
  9. return strlen( str );
  10. }
  11. inline char *_V_strrchr_inline( const char *s, char c )
  12. {
  13. int len = _V_strlen_inline(s);
  14. s += len;
  15. while (len--)
  16. if (*--s == c) return (char *)s;
  17. return 0;
  18. }
  19. inline int _V_wcscmp_inline( const wchar_t *s1, const wchar_t *s2 )
  20. {
  21. while (1)
  22. {
  23. if (*s1 != *s2)
  24. return -1; // strings not equal
  25. if (!*s1)
  26. return 0; // strings are equal
  27. s1++;
  28. s2++;
  29. }
  30. return -1;
  31. }
  32. #define STRTOOLS_TOLOWERC( x ) (( ( x >= 'A' ) && ( x <= 'Z' ) )?( x + 32 ) : x )
  33. inline int _V_stricmp_inline( const char *s1, const char *s2 )
  34. {
  35. #ifdef POSIX
  36. if ( s1 == NULL && s2 == NULL )
  37. return 0;
  38. if ( s1 == NULL )
  39. return -1;
  40. if ( s2 == NULL )
  41. return 1;
  42. return stricmp( s1, s2 );
  43. #else
  44. // THIS BLOCK ISN'T USED ON THE PS3 SINCE IT IS POSIX!!! Would be a code bloat concern otherwise.
  45. uint8 const *pS1 = ( uint8 const * ) s1;
  46. uint8 const *pS2 = ( uint8 const * ) s2;
  47. for(;;)
  48. {
  49. int c1 = *( pS1++ );
  50. int c2 = *( pS2++ );
  51. if ( c1 == c2 )
  52. {
  53. if ( !c1 ) return 0;
  54. }
  55. else
  56. {
  57. if ( ! c2 )
  58. {
  59. return c1 - c2;
  60. }
  61. c1 = TOLOWERC( c1 );
  62. c2 = TOLOWERC( c2 );
  63. if ( c1 != c2 )
  64. {
  65. return c1 - c2;
  66. }
  67. }
  68. c1 = *( pS1++ );
  69. c2 = *( pS2++ );
  70. if ( c1 == c2 )
  71. {
  72. if ( !c1 ) return 0;
  73. }
  74. else
  75. {
  76. if ( ! c2 )
  77. {
  78. return c1 - c2;
  79. }
  80. c1 = STRTOOLS_TOLOWERC( c1 );
  81. c2 = STRTOOLS_TOLOWERC( c2 );
  82. if ( c1 != c2 )
  83. {
  84. return c1 - c2;
  85. }
  86. }
  87. }
  88. #endif
  89. }
  90. inline char *_V_strstr_inline( const char *s1, const char *search )
  91. {
  92. #if defined( _X360 )
  93. return (char *)strstr( (char *)s1, search );
  94. #else
  95. return (char *)strstr( s1, search );
  96. #endif
  97. }
  98. #endif // TIER1_STRTOOLS_INLINES_H