Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
32e45016
Commit
32e45016
authored
Jun 07, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move STR_* macros to mruby/string.h with renaming
parent
b0c90141
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
153 additions
and
168 deletions
+153
-168
include/mruby/string.h
include/mruby/string.h
+32
-15
mrbgems/mruby-string-utf8/src/string.c
mrbgems/mruby-string-utf8/src/string.c
+6
-12
src/string.c
src/string.c
+115
-141
No files found.
include/mruby/string.h
View file @
32e45016
...
...
@@ -30,20 +30,37 @@ struct RString {
}
as
;
};
#define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED)
#define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED)
#define RSTR_UNSET_EMBED_FLAG(s) ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK))
#define RSTR_SET_EMBED_LEN(s, n) do {\
size_t tmp_n = (n);\
s->flags &= ~MRB_STR_EMBED_LEN_MASK;\
s->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\
} while (0)
#define RSTR_SET_LEN(s, n) do {\
if (RSTR_EMBED_P(s)) {\
RSTR_SET_EMBED_LEN((s),(n));\
} else {\
s->as.heap.len = (mrb_int)(n);\
}\
} while (0)
#define RSTR_EMBED_LEN(s)\
(mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT)
#define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr)
#define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len)
#define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa)
#define RSTR_SHARED_P(s) ((s)->flags & MRB_STR_SHARED)
#define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED)
#define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED)
#define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s)))
#define RSTRING(s) ((struct RString*)(mrb_ptr(s)))
#define RSTRING_PTR(s)\
((RSTRING(s)->flags & MRB_STR_EMBED) ?\
RSTRING(s)->as.ary :\
RSTRING(s)->as.heap.ptr)
#define RSTRING_LEN(s)\
((RSTRING(s)->flags & MRB_STR_EMBED) ?\
(mrb_int)((RSTRING(s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) :\
RSTRING(s)->as.heap.len)
#define RSTRING_CAPA(s)\
((RSTRING(s)->flags & MRB_STR_EMBED) ?\
RSTRING_EMBED_LEN_MAX :\
RSTRING(s)->as.heap.aux.capa)
#define RSTRING(s) mrb_str_ptr(s)
#define RSTRING_PTR(s) RSTR_PTR(RSTRING(s))
#define RSTRING_EMBED_LEN(s) RSTR_ENBED_LEN(RSTRING(s))
#define RSTRING_LEN(s) RSTR_LEN(RSTRING(s))
#define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s))
#define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s))
mrb_int
mrb_str_strlen
(
mrb_state
*
,
struct
RString
*
);
...
...
mrbgems/mruby-string-utf8/src/string.c
View file @
32e45016
...
...
@@ -7,12 +7,6 @@
#include <ctype.h>
#include <string.h>
#define STR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED)
#define STR_EMBED_LEN(s)\
(mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT)
#define STR_PTR(s) ((STR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr)
#define STR_LEN(s) ((STR_EMBED_P(s)) ? STR_EMBED_LEN(s) : (mrb_int)(s)->as.heap.len)
static
const
char
utf8len_codepage
[
256
]
=
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
...
...
@@ -250,17 +244,17 @@ str_rindex(mrb_state *mrb, mrb_value str, mrb_value sub, mrb_int pos)
mrb_int
len
=
RSTRING_LEN
(
sub
);
/* substring longer than string */
if
(
STR_LEN
(
ps
)
<
len
)
return
-
1
;
if
(
STR_LEN
(
ps
)
-
pos
<
len
)
{
pos
=
STR_LEN
(
ps
)
-
len
;
if
(
R
STR_LEN
(
ps
)
<
len
)
return
-
1
;
if
(
R
STR_LEN
(
ps
)
-
pos
<
len
)
{
pos
=
R
STR_LEN
(
ps
)
-
len
;
}
sbeg
=
STR_PTR
(
ps
);
s
=
STR_PTR
(
ps
)
+
pos
;
sbeg
=
R
STR_PTR
(
ps
);
s
=
R
STR_PTR
(
ps
)
+
pos
;
t
=
RSTRING_PTR
(
sub
);
if
(
len
)
{
while
(
sbeg
<=
s
)
{
if
(
memcmp
(
s
,
t
,
len
)
==
0
)
{
return
s
-
STR_PTR
(
ps
);
return
s
-
R
STR_PTR
(
ps
);
}
s
--
;
}
...
...
src/string.c
View file @
32e45016
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment