nxstring.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "../../foundation/types.h"
  3. #include <windows.h>
  4. #include "../../nx/nxapi.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef enum
  9. {
  10. nx_charset_ascii = 20127,
  11. nx_charset_latin1 = 28591,
  12. nx_charset_system = CP_ACP,
  13. nx_charset_utf8 = CP_UTF8,
  14. nx_charset_utf16le = 1200,
  15. nx_charset_utf16be = 1201,
  16. } nx_charset_t;
  17. typedef struct nx_string_struct_t
  18. {
  19. size_t ref_count;
  20. size_t len;
  21. wchar_t string[1]; // utf-16
  22. } nx_string_struct_t, *nx_string_t;
  23. enum
  24. {
  25. nx_compare_less_than = -1,
  26. nx_compare_equal_to = 0,
  27. nx_compare_greater_than = 1,
  28. };
  29. typedef int nx_compare_result;
  30. enum
  31. {
  32. nx_compare_default = 0,
  33. nx_compare_case_insensitive = ( 1 << 0),
  34. };
  35. typedef unsigned long nx_compare_options;
  36. NX_API int NXStringSetHeap(HANDLE string_heap);
  37. NX_API nx_string_t NXStringCreateFromPath(const wchar_t *folder, const wchar_t *filename);
  38. NX_API nx_string_t NXStringCreate(const wchar_t *str);
  39. NX_API nx_string_t NXStringCreateWithHeap(HANDLE heap, const wchar_t *str);
  40. NX_API nx_string_t NXStringMallocWithHeap(HANDLE heap, size_t characters);
  41. NX_API nx_string_t NXStringMalloc(size_t characters);
  42. NX_API nx_string_t NXStringRealloc(nx_string_t, size_t characters);
  43. NX_API nx_string_t NXStringRetain(nx_string_t string);
  44. NX_API void NXStringRelease(nx_string_t string);
  45. NX_API nx_string_t NXStringCreateFromUTF8(const char *str);
  46. NX_API int NXStringCreateWithUTF8(nx_string_t *new_value, const char *str);
  47. NX_API int NXStringCreateWithUTF16(nx_string_t *new_value, const wchar_t *str);
  48. NX_API int NXStringCreateWithCString(nx_string_t *new_value, const char *str, nx_charset_t charset);
  49. NX_API nx_string_t NXStringCreateFromUInt64(uint64_t value);
  50. NX_API int NXStringCreateWithUInt64(nx_string_t *new_value, uint64_t value);
  51. NX_API int NXStringCreateWithInt64(nx_string_t *new_value, int64_t value);
  52. NX_API int NXStringCreateWithBytes(nx_string_t *new_string, const void *data, size_t len, nx_charset_t charset);
  53. NX_API int NXStringCreateEmpty(nx_string_t *new_string);
  54. NX_API int NXStringCreateWithFormatting(nx_string_t *new_string, const char *format, ...);
  55. NX_API size_t NXStringGetLength(nx_string_t string);
  56. /* returns strcmp style return. compare_to is treated as an ASCII string.
  57. if compare_to has non-ASCII characters, results are undetermined */
  58. NX_API int NXStringKeywordCompareWithCString(nx_string_t string, const char *compare_to);
  59. NX_API int NXStringKeywordCompare(nx_string_t string, nx_string_t compare_to);
  60. NX_API int NXStringKeywordCaseCompare(nx_string_t string, nx_string_t compare_to);
  61. /* creates an NXString with the base path from the passed in filename (retains an appended \) */
  62. NX_API int NXStringCreateBasePathFromFilename(nx_string_t filename, nx_string_t *basepath);
  63. NX_API int NXStringGetCString(nx_string_t string, char *user_buffer, size_t user_buffer_length, const char **out_cstring, size_t *out_cstring_length);
  64. NX_API int NXStringGetDoubleValue(nx_string_t string, double *value);
  65. NX_API int NXStringGetIntegerValue(nx_string_t string, int *value);
  66. NX_API int NXStringGetGUIDValue(nx_string_t string, GUID *guid);
  67. static const int nx_string_get_bytes_size_null_terminate = 1; // pass this to null terminate the string
  68. /* returns byte count with enough room to store a converted string
  69. note: if this returns NErr_DirectPointer, you can call NXStringGetBytesDirect to directly retrieve a pointer. */
  70. NX_API int NXStringGetBytesSize(size_t *byte_count, nx_string_t string, nx_charset_t charset, int flags);
  71. /* if possible, retrieves a pointer to bytes.
  72. the length returned depends on whether or not you passed nx_string_get_bytes_size_null_terminate
  73. note: the pointer you get will be invalid after you call NXStringRelease on the string passed in */
  74. NX_API int NXStringGetBytesDirect(const void **bytes, size_t *length, nx_string_t string, nx_charset_t charset, int flags);
  75. NX_API int NXStringGetBytes(size_t *bytes_copied, nx_string_t string, void *bytes, size_t length, nx_charset_t charset, int flags);
  76. NX_API nx_compare_result NXStringCompare(nx_string_t string1, nx_string_t string2, nx_compare_options options);
  77. #ifdef __cplusplus
  78. }
  79. #endif