kstring.h (1840B)
1 /* 2 ** kstring.h 3 ** Kernel Strings 4 ** See Copyright Notice in klisp.h 5 */ 6 7 /* SOURCE NOTE: the string table & hashing code is from lua */ 8 9 #ifndef kstring_h 10 #define kstring_h 11 12 #include <stdbool.h> 13 14 #include "kobject.h" 15 #include "kstate.h" 16 17 /* for immutable string table */ 18 void klispS_resize (klisp_State *K, int32_t newsize); 19 20 /* General constructor for strings */ 21 TValue kstring_new_bs_g(klisp_State *K, bool m, const char *buf, 22 uint32_t size); 23 24 /* 25 ** Constructors for immutable strings 26 */ 27 28 /* main immutable string constructor */ 29 /* with buffer & size */ 30 TValue kstring_new_bs_imm(klisp_State *K, const char *buf, uint32_t size); 31 32 /* with just buffer, no embedded '\0's */ 33 TValue kstring_new_b_imm(klisp_State *K, const char *buf); 34 35 /* 36 ** Constructors for mutable strings 37 */ 38 39 /* main mutable string constructor */ 40 /* with just size */ 41 TValue kstring_new_s(klisp_State *K, uint32_t size); 42 /* with buffer & size */ 43 TValue kstring_new_bs(klisp_State *K, const char *buf, uint32_t size); 44 /* with just buffer, no embedded '\0's */ 45 TValue kstring_new_b(klisp_State *K, const char *buf); 46 /* with size & fill char */ 47 TValue kstring_new_sf(klisp_State *K, uint32_t size, char fill); 48 49 /* some macros to access the parts of the string */ 50 #define kstring_buf(tv_) (tv2str(tv_)->b) 51 #define kstring_size(tv_) (tv2str(tv_)->size) 52 53 #define kstring_emptyp(tv_) (kstring_size(tv_) == 0) 54 #define kstring_mutablep(tv_) (kis_mutable(tv_)) 55 #define kstring_immutablep(tv_) (kis_immutable(tv_)) 56 57 /* both obj1 and obj2 should be strings, this compares char by char 58 and doesn't differentiate immutable from mutable strings */ 59 bool kstring_equalp(TValue obj1, TValue obj2); 60 bool kstringp(TValue obj); 61 bool kimmutable_stringp(TValue obj); 62 bool kmutable_stringp(TValue obj); 63 int32_t kstring_cstr_cmp(TValue str, const char *buf); 64 65 #endif