mruby/c VM Source Code release 3.4
Loading...
Searching...
No Matches
c_string.h
Go to the documentation of this file.
1
13
14#ifndef MRBC_SRC_C_STRING_H_
15#define MRBC_SRC_C_STRING_H_
16
17/***** Feature test switches ************************************************/
18/***** System headers *******************************************************/
19//@cond
20#include "vm_config.h"
21#include <stdint.h>
22#include <string.h>
23//@endcond
24
25/***** Local headers ********************************************************/
26#include "value.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31/***** Constant values ******************************************************/
32#if !defined(MRBC_STRING_SIZE_T)
33#define MRBC_STRING_SIZE_T uint16_t
34#endif
35
36/***** Macros ***************************************************************/
37#define RSTRING_LEN(str) mrbc_string_size(&str)
38#define RSTRING_PTR(str) mrbc_string_cstr(&str)
39
40/***** Typedefs *************************************************************/
41//================================================================
54
55
56/***** Global variables *****************************************************/
57/***** Function prototypes **************************************************/
58//@cond
59mrbc_value mrbc_string_new(struct VM *vm, const void *src, int len);
60mrbc_value mrbc_string_new_alloc(struct VM *vm, void *buf, int len);
63void mrbc_string_clear_vm_id(mrbc_value *str);
65mrbc_value mrbc_string_add(struct VM *vm, const mrbc_value *s1, const mrbc_value *s2);
66int mrbc_string_append(mrbc_value *s1, const mrbc_value *s2);
67int mrbc_string_append_cbuf(mrbc_value *s1, const void *s2, int len2);
68int mrbc_string_index(const mrbc_value *src, const mrbc_value *pattern, int offset);
69int mrbc_string_strip(mrbc_value *src, int mode);
73//@endcond
74
75
76/***** Inline functions *****************************************************/
77
78//================================================================
85static inline mrbc_value mrbc_string_new_cstr(struct VM *vm, const char *src)
86{
87 return mrbc_string_new(vm, src, (src ? strlen(src) : 0));
88}
89
90
91//================================================================
94static inline int mrbc_string_compare(const mrbc_value *v1, const mrbc_value *v2)
95{
96 int len = (v1->string->size < v2->string->size) ?
97 v1->string->size : v2->string->size;
98
99 int res = memcmp(v1->string->data, v2->string->data, len);
100 if( res != 0 ) return res;
101
102 return v1->string->size - v2->string->size;
103}
104
105//================================================================
108static inline int mrbc_string_size(const mrbc_value *str)
109{
110 return str->string->size;
111}
112
113//================================================================
116static inline char * mrbc_string_cstr(const mrbc_value *v)
117{
118 return (char*)v->string->data;
119}
120
121//================================================================
128static inline int mrbc_string_append_cstr(mrbc_value *s1, const char *s2)
129{
130 return mrbc_string_append_cbuf( s1, s2, strlen(s2) );
131}
132
133#ifdef __cplusplus
134}
135#endif
136#endif
int mrbc_string_index(const mrbc_value *src, const mrbc_value *pattern, int offset)
Definition c_string.c:269
void mrbc_string_delete(mrbc_value *str)
Definition c_string.c:129
mrbc_value mrbc_string_dup(struct VM *vm, mrbc_value *s1)
Definition c_string.c:167
void mrbc_string_clear(mrbc_value *str)
Definition c_string.c:140
mrbc_value mrbc_string_add(struct VM *vm, const mrbc_value *s1, const mrbc_value *s2)
Definition c_string.c:188
int mrbc_string_chomp(mrbc_value *src)
Definition c_string.c:334
int mrbc_string_append_cbuf(mrbc_value *s1, const void *s2, int len2)
Definition c_string.c:240
int mrbc_string_upcase(mrbc_value *str)
Definition c_string.c:363
int mrbc_string_downcase(mrbc_value *str)
Definition c_string.c:385
int mrbc_string_append(mrbc_value *s1, const mrbc_value *s2)
Definition c_string.c:210
mrbc_value mrbc_string_new(struct VM *vm, const void *src, int len)
Definition c_string.c:62
mrbc_value mrbc_string_new_alloc(struct VM *vm, void *buf, int len)
Definition c_string.c:105
int mrbc_string_strip(mrbc_value *src, int mode)
Definition c_string.c:294
struct RString mrbc_string
String object.
static char * mrbc_string_cstr(const mrbc_value *v)
Definition c_string.h:116
static int mrbc_string_compare(const mrbc_value *v1, const mrbc_value *v2)
Definition c_string.h:94
static mrbc_value mrbc_string_new_cstr(struct VM *vm, const char *src)
Definition c_string.h:85
static int mrbc_string_append_cstr(mrbc_value *s1, const char *s2)
Definition c_string.h:128
#define MRBC_STRING_SIZE_T
Definition c_string.h:33
static int mrbc_string_size(const mrbc_value *str)
Definition c_string.h:108
struct RString * string
Definition value.h:164
String object.
Definition c_string.h:47
MRBC_OBJECT_HEADER
Definition c_string.h:48
uint8_t * data
pointer to allocated buffer.
Definition c_string.h:51
MRBC_STRING_SIZE_T size
string length.
Definition c_string.h:50
Virtual Machine.
Definition vm.h:140
mruby/c value definitions
struct RObject mrbc_value
Definition value.h:174
Global configuration of mruby/c VM's.