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.
 
 
 
 

76 lines
1.6 KiB

  1. #pragma once
  2. #include <stdint.h>
  3. #include <string.h>
  4. typedef int8_t s8;
  5. typedef int16_t s16;
  6. typedef int32_t s32;
  7. typedef int64_t s64;
  8. typedef uint8_t u8;
  9. typedef uint16_t u16;
  10. typedef uint32_t u32;
  11. typedef uint64_t u64;
  12. typedef float f32;
  13. typedef long double f64;
  14. #ifdef UNICODE
  15. typedef wchar_t path_char;
  16. #else
  17. typedef char path_char;
  18. #endif
  19. struct String {
  20. u64 length;
  21. char* data;
  22. };
  23. struct StringSlice {
  24. u64 length;
  25. const char* data;
  26. };
  27. inline auto make_heap_string(const char* str) -> String {
  28. String ret;
  29. ret.length = strlen(str);
  30. ret.data = strdup(str);
  31. return ret;
  32. }
  33. inline const StringSlice make_static_string(const char* str) {
  34. StringSlice ret;
  35. ret.length = strlen(str);
  36. ret.data = str;
  37. return ret;
  38. }
  39. auto inline string_equal(const char* input, const char* check) -> bool {
  40. return strcmp(input, check) == 0;
  41. }
  42. template <typename Str>
  43. auto inline string_equal(Str str, const char* check) -> bool {
  44. if (str.length != strlen(check))
  45. return false;
  46. return strncmp(str.data, check, str.length) == 0;
  47. }
  48. template <typename Str>
  49. auto inline string_equal(const char* check, Str str) -> bool {
  50. if (str.length != strlen(check))
  51. return false;
  52. return strncmp(str.data, check, str.length) == 0;
  53. }
  54. template <typename StrA, typename StrB>
  55. auto inline string_equal(StrA str1, StrB str2) -> bool {
  56. if (str1.length != str2.length)
  57. return false;
  58. return strncmp(str1.data, str2.data, str2.length) == 0;
  59. }
  60. template auto string_equal(StringSlice str1, StringSlice str2) -> bool;