Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

109 wiersze
2.1 KiB

  1. #pragma once
  2. #include "platform.hpp"
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. typedef int8_t s8;
  7. typedef int16_t s16;
  8. typedef int32_t s32;
  9. typedef int64_t s64;
  10. typedef uint8_t u8;
  11. typedef uint16_t u16;
  12. typedef uint32_t u32;
  13. typedef uint64_t u64;
  14. typedef float f32;
  15. typedef long double f64;
  16. #ifdef UNICODE
  17. typedef wchar_t path_char;
  18. #else
  19. typedef char path_char;
  20. #endif
  21. inline auto heap_copy_c_string(const char* str) -> char* {
  22. #ifdef FTB_WINDOWS
  23. return _strdup(str);
  24. #else
  25. return strdup(str);
  26. #endif
  27. }
  28. struct String_Slice {
  29. String_Slice() = default;
  30. String_Slice (const char* str)
  31. : length(strlen(str)),
  32. data(str)
  33. {}
  34. const char* data;
  35. u64 length;
  36. };
  37. struct String {
  38. String () = default;
  39. String (const char* str) {
  40. length = strlen(str);
  41. data = heap_copy_c_string(str);
  42. }
  43. ~String () {
  44. free(data);
  45. data = nullptr;
  46. }
  47. String (const String&) = delete;
  48. String (String&& other) {
  49. length = other.length;
  50. data = other.data;
  51. other.data = nullptr;
  52. }
  53. String& operator= (String&& other) {
  54. length = other.length;
  55. data = other.data;
  56. other.data = nullptr;
  57. return *this;
  58. }
  59. char* data;
  60. u64 length;
  61. };
  62. inline auto make_static_string(const char* str) -> const String_Slice {
  63. String_Slice ret(str);
  64. return ret;
  65. }
  66. auto inline string_equal(const char* input, const char* check) -> bool {
  67. return strcmp(input, check) == 0;
  68. }
  69. auto inline string_equal(String_Slice str, const char* check) -> bool {
  70. if (str.length != strlen(check))
  71. return false;
  72. return strncmp(str.data, check, str.length) == 0;
  73. }
  74. auto inline string_equal(const char* check, String_Slice str) -> bool {
  75. if (str.length != strlen(check))
  76. return false;
  77. return strncmp(str.data, check, str.length) == 0;
  78. }
  79. auto inline string_equal(String_Slice str1, String_Slice str2) -> bool {
  80. if (str1.length != str2.length)
  81. return false;
  82. return strncmp(str1.data, str2.data, str2.length) == 0;
  83. }