Team Fortress 2 Source Code as on 22/4/2020
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.

83 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: dll-agnostic routines (no dll dependencies here)
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. // Author: Matthew D. Campbell ([email protected]), 2003
  8. #ifndef SHARED_UTIL_H
  9. #define SHARED_UTIL_H
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //--------------------------------------------------------------------------------------------------------
  13. /**
  14. * Returns the token parsed by SharedParse()
  15. */
  16. char *SharedGetToken( void );
  17. //--------------------------------------------------------------------------------------------------------
  18. /**
  19. * Sets the character used to delimit quoted strings. Default is '\"'. Be sure to set it back when done.
  20. */
  21. void SharedSetQuoteChar( char c );
  22. //--------------------------------------------------------------------------------------------------------
  23. /**
  24. * Parse a token out of a string
  25. */
  26. const char *SharedParse( const char *data );
  27. //--------------------------------------------------------------------------------------------------------
  28. /**
  29. * Returns true if additional data is waiting to be processed on this line
  30. */
  31. bool SharedTokenWaiting( const char *buffer );
  32. //--------------------------------------------------------------------------------------------------------
  33. /**
  34. * Simple utility function to allocate memory and duplicate a string
  35. */
  36. inline char *CloneString( const char *str )
  37. {
  38. char *cloneStr = new char [ strlen(str)+1 ];
  39. strcpy( cloneStr, str );
  40. return cloneStr;
  41. }
  42. //--------------------------------------------------------------------------------------------------------------
  43. /**
  44. * snprintf-alike that allows multiple prints into a buffer
  45. */
  46. char * BufPrintf(char *buf, int& len, PRINTF_FORMAT_STRING const char *fmt, ...);
  47. //--------------------------------------------------------------------------------------------------------------
  48. /**
  49. * wide char version of BufPrintf
  50. */
  51. wchar_t * BufWPrintf(wchar_t *buf, int& len, PRINTF_FORMAT_STRING const wchar_t *fmt, ...);
  52. //--------------------------------------------------------------------------------------------------------------
  53. /**
  54. * convenience function that prints an int into a static wchar_t*
  55. */
  56. const wchar_t * NumAsWString( int val );
  57. //--------------------------------------------------------------------------------------------------------------
  58. /**
  59. * convenience function that prints an int into a static char*
  60. */
  61. const char * NumAsString( int val );
  62. //--------------------------------------------------------------------------------------------------------------
  63. /**
  64. * convenience function that composes a string into a static char*
  65. */
  66. char * SharedVarArgs(PRINTF_FORMAT_STRING const char *format, ...);
  67. #include "tier0/memdbgoff.h"
  68. #endif // SHARED_UTIL_H