mbed I/F binding for mruby
Dependents: mruby_mbed_web mirb_mbed
mbed-mruby
How to use
Class
include/mruby/string.h@1:8ccd1d494a4b, 2015-04-13 (annotated)
- Committer:
- mzta
- Date:
- Mon Apr 13 05:20:15 2015 +0000
- Revision:
- 1:8ccd1d494a4b
- Parent:
- 0:158c61bb030f
- code refactoring.; - add SPI, SPISlave, I2C class to mruby-mbed (Incomplete).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mzta | 0:158c61bb030f | 1 | /* |
mzta | 0:158c61bb030f | 2 | ** mruby/string.h - String class |
mzta | 0:158c61bb030f | 3 | ** |
mzta | 0:158c61bb030f | 4 | ** See Copyright Notice in mruby.h |
mzta | 0:158c61bb030f | 5 | */ |
mzta | 0:158c61bb030f | 6 | |
mzta | 0:158c61bb030f | 7 | #ifndef MRUBY_STRING_H |
mzta | 0:158c61bb030f | 8 | #define MRUBY_STRING_H |
mzta | 0:158c61bb030f | 9 | |
mzta | 0:158c61bb030f | 10 | #if defined(__cplusplus) |
mzta | 0:158c61bb030f | 11 | extern "C" { |
mzta | 0:158c61bb030f | 12 | #endif |
mzta | 0:158c61bb030f | 13 | |
mzta | 0:158c61bb030f | 14 | extern const char mrb_digitmap[]; |
mzta | 0:158c61bb030f | 15 | |
mzta | 0:158c61bb030f | 16 | #define RSTRING_EMBED_LEN_MAX ((mrb_int)(sizeof(void*) * 3 - 1)) |
mzta | 0:158c61bb030f | 17 | |
mzta | 0:158c61bb030f | 18 | struct RString { |
mzta | 0:158c61bb030f | 19 | MRB_OBJECT_HEADER; |
mzta | 0:158c61bb030f | 20 | union { |
mzta | 0:158c61bb030f | 21 | struct { |
mzta | 0:158c61bb030f | 22 | mrb_int len; |
mzta | 0:158c61bb030f | 23 | union { |
mzta | 0:158c61bb030f | 24 | mrb_int capa; |
mzta | 0:158c61bb030f | 25 | struct mrb_shared_string *shared; |
mzta | 0:158c61bb030f | 26 | } aux; |
mzta | 0:158c61bb030f | 27 | char *ptr; |
mzta | 0:158c61bb030f | 28 | } heap; |
mzta | 0:158c61bb030f | 29 | char ary[RSTRING_EMBED_LEN_MAX + 1]; |
mzta | 0:158c61bb030f | 30 | } as; |
mzta | 0:158c61bb030f | 31 | }; |
mzta | 0:158c61bb030f | 32 | |
mzta | 0:158c61bb030f | 33 | #define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED) |
mzta | 0:158c61bb030f | 34 | #define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED) |
mzta | 0:158c61bb030f | 35 | #define RSTR_UNSET_EMBED_FLAG(s) ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK)) |
mzta | 0:158c61bb030f | 36 | #define RSTR_SET_EMBED_LEN(s, n) do {\ |
mzta | 0:158c61bb030f | 37 | size_t tmp_n = (n);\ |
mzta | 0:158c61bb030f | 38 | s->flags &= ~MRB_STR_EMBED_LEN_MASK;\ |
mzta | 0:158c61bb030f | 39 | s->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\ |
mzta | 0:158c61bb030f | 40 | } while (0) |
mzta | 0:158c61bb030f | 41 | #define RSTR_SET_LEN(s, n) do {\ |
mzta | 0:158c61bb030f | 42 | if (RSTR_EMBED_P(s)) {\ |
mzta | 0:158c61bb030f | 43 | RSTR_SET_EMBED_LEN((s),(n));\ |
mzta | 0:158c61bb030f | 44 | } else {\ |
mzta | 0:158c61bb030f | 45 | s->as.heap.len = (mrb_int)(n);\ |
mzta | 0:158c61bb030f | 46 | }\ |
mzta | 0:158c61bb030f | 47 | } while (0) |
mzta | 0:158c61bb030f | 48 | #define RSTR_EMBED_LEN(s)\ |
mzta | 0:158c61bb030f | 49 | (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) |
mzta | 0:158c61bb030f | 50 | #define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr) |
mzta | 0:158c61bb030f | 51 | #define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len) |
mzta | 0:158c61bb030f | 52 | #define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa) |
mzta | 0:158c61bb030f | 53 | |
mzta | 0:158c61bb030f | 54 | #define RSTR_SHARED_P(s) ((s)->flags & MRB_STR_SHARED) |
mzta | 0:158c61bb030f | 55 | #define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED) |
mzta | 0:158c61bb030f | 56 | #define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED) |
mzta | 0:158c61bb030f | 57 | |
mzta | 0:158c61bb030f | 58 | #define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE) |
mzta | 0:158c61bb030f | 59 | #define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE) |
mzta | 0:158c61bb030f | 60 | #define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE) |
mzta | 0:158c61bb030f | 61 | |
mzta | 0:158c61bb030f | 62 | #define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s))) |
mzta | 0:158c61bb030f | 63 | #define RSTRING(s) mrb_str_ptr(s) |
mzta | 0:158c61bb030f | 64 | #define RSTRING_PTR(s) RSTR_PTR(RSTRING(s)) |
mzta | 0:158c61bb030f | 65 | #define RSTRING_EMBED_LEN(s) RSTR_ENBED_LEN(RSTRING(s)) |
mzta | 0:158c61bb030f | 66 | #define RSTRING_LEN(s) RSTR_LEN(RSTRING(s)) |
mzta | 0:158c61bb030f | 67 | #define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s)) |
mzta | 0:158c61bb030f | 68 | #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) |
mzta | 0:158c61bb030f | 69 | mrb_int mrb_str_strlen(mrb_state*, struct RString*); |
mzta | 0:158c61bb030f | 70 | |
mzta | 0:158c61bb030f | 71 | #define MRB_STR_SHARED 1 |
mzta | 0:158c61bb030f | 72 | #define MRB_STR_NOFREE 2 |
mzta | 0:158c61bb030f | 73 | #define MRB_STR_EMBED 4 |
mzta | 0:158c61bb030f | 74 | #define MRB_STR_EMBED_LEN_MASK 0xf8 |
mzta | 0:158c61bb030f | 75 | #define MRB_STR_EMBED_LEN_SHIFT 3 |
mzta | 0:158c61bb030f | 76 | |
mzta | 0:158c61bb030f | 77 | void mrb_gc_free_str(mrb_state*, struct RString*); |
mzta | 0:158c61bb030f | 78 | MRB_API void mrb_str_modify(mrb_state*, struct RString*); |
mzta | 0:158c61bb030f | 79 | MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value); |
mzta | 0:158c61bb030f | 80 | MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value); |
mzta | 0:158c61bb030f | 81 | MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*); |
mzta | 0:158c61bb030f | 82 | MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); |
mzta | 0:158c61bb030f | 83 | MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); |
mzta | 0:158c61bb030f | 84 | MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); |
mzta | 0:158c61bb030f | 85 | MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 86 | MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 87 | MRB_API mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa); |
mzta | 0:158c61bb030f | 88 | |
mzta | 0:158c61bb030f | 89 | MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr); |
mzta | 0:158c61bb030f | 90 | MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr); |
mzta | 0:158c61bb030f | 91 | MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 92 | MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); |
mzta | 0:158c61bb030f | 93 | MRB_API mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck); |
mzta | 0:158c61bb030f | 94 | MRB_API double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck); |
mzta | 0:158c61bb030f | 95 | MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 96 | MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); |
mzta | 0:158c61bb030f | 97 | MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len); |
mzta | 0:158c61bb030f | 98 | MRB_API mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr); |
mzta | 0:158c61bb030f | 99 | MRB_API mrb_value mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2); |
mzta | 0:158c61bb030f | 100 | #define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit)) |
mzta | 0:158c61bb030f | 101 | MRB_API mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2); |
mzta | 0:158c61bb030f | 102 | |
mzta | 0:158c61bb030f | 103 | MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); |
mzta | 0:158c61bb030f | 104 | MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 105 | mrb_value mrb_str_pool(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 106 | mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 107 | mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 108 | mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str); |
mzta | 0:158c61bb030f | 109 | |
mzta | 0:158c61bb030f | 110 | void mrb_noregexp(mrb_state *mrb, mrb_value self); |
mzta | 0:158c61bb030f | 111 | void mrb_regexp_check(mrb_state *mrb, mrb_value obj); |
mzta | 0:158c61bb030f | 112 | |
mzta | 0:158c61bb030f | 113 | /* For backward compatibility */ |
mzta | 0:158c61bb030f | 114 | #define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr) |
mzta | 0:158c61bb030f | 115 | #define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len) |
mzta | 0:158c61bb030f | 116 | #define mrb_str_buf_append(mrb, str, str2) mrb_str_cat_str(mrb, str, str2) |
mzta | 0:158c61bb030f | 117 | |
mzta | 0:158c61bb030f | 118 | #if defined(__cplusplus) |
mzta | 0:158c61bb030f | 119 | } /* extern "C" { */ |
mzta | 0:158c61bb030f | 120 | #endif |
mzta | 0:158c61bb030f | 121 | |
mzta | 0:158c61bb030f | 122 | #endif /* MRUBY_STRING_H */ |
mzta | 0:158c61bb030f | 123 |