str.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /** String functions. Use the ALLEGRO_USTR,
  2. but wrap it a bit with macros to have to do less typing. */
  3. #ifndef STR_H_
  4. #define STR_H_
  5. #include <allegro5/allegro.h>
  6. /** String type */
  7. #ifndef USSTR
  8. #define USTR ALLEGRO_USTR
  9. #endif
  10. /** Static String info helper type */
  11. #ifndef USTR_INFO
  12. #define USTR_INFO ALLEGRO_USTR_INFO
  13. #endif
  14. #define ustr_new(STR) al_ustr_new(STR)
  15. #define ustr_newcstr(STR) al_ustr_new(STR)
  16. #define ustr_newbuffer(B, SZ) al_ustr_new_from_buffer(B, SZ)
  17. #define ustr_newf(FMT, ...) al_ustr_newf(FMT, __VA_ARGS__)
  18. #define ustr_free(STR) al_ustr_free(STR)
  19. #define ustr_c(STR) al_cstr(STR)
  20. #define ustr_cstr(STR) al_cstr(STR)
  21. #define ustr_buffer(STR, B, SZ) al_ustr_to_buffer(STR, B, SZ)
  22. #define ustr_cdup(STR) al_cstr_dup(STR)
  23. #define ustr_cfree(CS) al_free(CS)
  24. #define ustr_dup(STR) al_ustr_dup(STR)
  25. #define ustr_dupsub(STR, FROM, TO) al_ustr_dup_substr(STR, FROM, TO)
  26. #define ustr_empty al_ustr_empty_string()
  27. #define ustr_refcstr(INFO, CS) al_ref_cstr(INFO, CS)
  28. #define ustr_refbuffer(INFO, BUF, SZ) al_ref_buffer(INFO, BUF, SZ)
  29. #define ustr_refustr(INFO, STR, FROM, TO) al_ref_ustr(INFO, STR, FROM, TO)
  30. #define ustr_size(STR) al_ustr_size(STR)
  31. #define ustr_length(STR) al_ustr_length(STR)
  32. #define ustr_offset(STR, INDEX) al_ustr_offset(STR, INDEX)
  33. #define ustr_next(STR, POS) al_ustr_next(STR, POS)
  34. #define ustr_prev(STR, POS) al_ustr_prev(STR, PREV)
  35. #define ustr_get(STR, INDEX) al_ustr_get(STR, INDEX)
  36. #define ustr_getnext(STR, POS) al_ustr_get_next(STR, POS)
  37. #define ustr_getprev(STR, POS) al_ustr_prev_get(STR, POS)
  38. #define ustr_insert(STR, POS, STR2) al_ustr_insert(STR, POS, STR2)
  39. #define ustr_insertcstr(STR, POS, CS) al_ustr_insert_cstr(STR, POS, CS)
  40. #define ustr_insertch(STR, POS, CH) al_ustr_insert_ch(STR, POS, CH)
  41. #define ustr_append(STR, STR2) al_ustr_append(STR, STR2)
  42. #define ustr_appendcstr(STR, CS) al_ustr_append_cstr(STR, CS)
  43. #define ustr_appendch(STR, CH) al_ustr_append_chr(STR, CH)
  44. #define ustr_appendf(STR, FMT, ...) al_ustr_appendf(STR, FMT, __VA_ARGS__)
  45. #define ustr_vappendf(STR, FMR, AP) al_ustr_vappendf(STR, FMT, AP)
  46. #define ustr_removechr(STR, INDEX) al_ustr_remove_chr(STR, INDEX)
  47. #define ustr_remove_chr(STR, INDEX) al_ustr_remove_chr(STR, INDEX)
  48. #define ustr_removerange(STR, FROM, TO) al_ustr_remove_range(STR, FROM, TO)
  49. #define ustr_truncate(STR, INDEX) al_ustr_truncate(STR, INDEX)
  50. #define ustr_ltrim(STR) al_ustr_ltrim_ws(STR, INDEX)
  51. #define ustr_rtrim(STR) al_ustr_rtrim_ws(STR, INDEX)
  52. #define ustr_trim(STR) al_ustr_trim_ws(STR, INDEX)
  53. #define ustr_set(STR, STR2) al_ustr_assign(STR, STR2)
  54. #define ustr_setsub(STR, STR2, FROM, TO) \
  55. al_ustr_assign_substr(STR, STR2, FROM, TO)
  56. #define ustr_setcstr(STR, CS) al_ustr_assign_cstr(STR, CS)
  57. #define ustr_setch(STR, INDEX, CH) al_ustr_set_chr(STR, INDEX, CH)
  58. #define ustr_setrange(STR, FROM, TO, STR2) \
  59. al_ustr_replace_range(STR, FROM, TO, STR2)
  60. #define ustr_findchr(STR, POS, CH) al_ustr_find_chr(STR, POS, CH)
  61. #define ustr_rfindchr(STR, POS, CH) al_ustr_rfind_chr(STR, POS, CH)
  62. #define ustr_findin(STR, POS, STR2) al_ustr_find_set(STR, POS, STR2)
  63. #define ustr_findincstr(STR, POS, CS) al_ustr_find_set_cstr(STR, POS, CS)
  64. #define ustr_findnotin(STR, POS, STR2) al_ustr_find_cset(STR, POS, STR2)
  65. #define ustr_findnotincstr(STR, POS, CS) al_ustr_find_cset_cstr(STR, POS, CS)
  66. #define ustr_find(STR, POS, STR2) al_ustr_find_str(STR, POS, STR2)
  67. #define ustr_findcstr(STR, POS, CS) al_ustr_find_cstr(STR, POS, CS)
  68. #define ustr_rfind(STR, POS, STR2) al_ustr_rfind_str(STR, POS, STR2)
  69. #define ustr_rfindcstr(STR, POS, CS) al_ustr_rfind_cstr(STR, POS, CS)
  70. #define ustr_replace(STR, POS, STR2, STR3)\
  71. al_ustr_find_replace(STR, POS, STR2, STR3)
  72. #define ustr_replacecstr(STR, POS, CS1, CS2)\
  73. al_ustr_find_replace_cstr(STR, POS, CS1, CS2)
  74. #define ustr_equal(STR, STR2) al_ustr_equal(STR, STR2)
  75. #define ustr_compare(STR, STR2) al_ustr_compare(STR, STR2)
  76. #define ustr_ncopare(STR, STR2, SZ) al_ustr_ncompare(STR, STR2, SZ)
  77. #define ustr_isprefix(STR, STR2) al_ustr_has_prefix(STR, STR2)
  78. #define ustr_issuffix(STR, STR2) al_ustr_has_suffix(STR, STR2)
  79. #define ustr_isprefixcstr(STR, CS) al_ustr_has_prefix_cstr(STR, CS)
  80. #define ustr_issuffixcstr(STR, CS) al_ustr_has_suffix_cstr(STR, CS)
  81. #define ustr_const(NAME, CSTR) \
  82. USTR_INFO info_##NAME; US * NAME = ustr_refcstr(&info_##NAME, CSTR);
  83. #define ustr_isempty(USTR) (ustr_size((USTR)) < 1)
  84. char * cstr_dup(char * str);
  85. int ustr_atoi(USTR * str );
  86. double ustr_tod(USTR * ustr , int * ok );
  87. long ustr_tol(USTR * ustr , int * ok , int base );
  88. double ustr_atod(USTR * ustr );
  89. double ustr_atol(USTR * ustr );
  90. USTR * ustr_newdouble(double d );
  91. USTR * ustr_newlong(long l );
  92. int cstr_charis(const char * expression , int ch );
  93. int cstr_simplematch(const char * expression , int ch );
  94. #include "bad.h"
  95. /* An ustrlist is a list of UTF-8 enabled strings. */
  96. typedef struct USTRListNode_ USTRListNode;
  97. typedef BadList USTRList;
  98. struct USTRListNode_ {
  99. USTR * ustr;
  100. BadListNode list;
  101. };
  102. USTR * ustrlistnode_ustr(USTRListNode * self);
  103. USTRListNode * ustrlistnode_alloc(void);
  104. USTRListNode * ustrlistnode_init(USTRListNode * self, const USTR * ustr);
  105. USTRListNode * ustrlistnode_initcstr(USTRListNode * self, const char * str);
  106. USTRListNode * ustrlistnode_new(const USTR * ustr);
  107. USTRListNode * ustrlistnode_done(USTRListNode * self);
  108. USTRListNode * badlistnode_ustrlistnode(BadListNode * elem);
  109. USTRListNode * ustrlistnode_free(USTRListNode * self);
  110. USTRListNode * ustrlistnode_next(USTRListNode * self);
  111. USTRListNode * ustrlistnode_prev(USTRListNode * self);
  112. USTRListNode * ustrlist_head(USTRList * self);
  113. USTRListNode * ustrlist_tail(USTRList * self);
  114. USTRList * ustrlist_alloc(void);
  115. USTRList * ustrlist_init(USTRList * self);
  116. USTRList * ustrlist_new();
  117. USTRList * ustrlist_done(USTRList * self);
  118. USTRList * ustrlist_free(USTRList * self);
  119. USTRList * ustrlist_addnode(USTRList * self, USTRListNode * node);
  120. USTRList * ustrlist_removenode(USTRList * self, USTRListNode * node);
  121. USTRListNode * ustrlist_addustr(USTRList * self, const USTR * ustr);
  122. USTRListNode * ustrlist_addcstr(USTRList * self, const char * cstr);
  123. USTRListNode * ustrlist_shiftustr(USTRList * self, const USTR * ustr);
  124. USTRListNode * ustrlist_shiftcstr(USTRList * self, const char * cstr);
  125. int ustrlist_size(USTRList * self);
  126. USTRList * ustrlist_droplast(USTRList * self);
  127. USTR * ustrlist_join(USTRList * self);
  128. USTR * ustrlist_joinwithcstr(USTRList * self, const char * sep);
  129. USTR * ustrlist_joinwithch(USTRList * self, const char ch);
  130. USTR * ustrlist_joinwithustr(USTRList * self, USTR * sep);
  131. USTRListNode * ustrlist_skipnode(USTRList * self, int skip);
  132. #endif