Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mruby/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ struct RStringEmbed {
#endif
#define RSTR_SET_ASCII_FLAG(s) RSTR_SET_SINGLE_BYTE_FLAG(s)
#define RSTR_BINARY_P(s) ((s)->flags & MRB_STR_BINARY)
#define RSTR_SET_BINARY_FLAG(s) ((s)->flags |= MRB_STR_BINARY)
#define RSTR_UNSET_BINARY_FLAG(s) ((s)->flags &= ~MRB_STR_BINARY)
/* A copy of a string is byte-indexed exactly when the string it copies is, so
the flag travels with the bytes rather than being left behind on the
original. */
Expand Down
4 changes: 2 additions & 2 deletions mrbgems/mruby-encoding/src/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ str_force_encoding(mrb_state *mrb, mrb_value self)
struct RString *s = mrb_str_ptr(self);
if (MRB_STR_CASECMP_P(enc, ENC_ASCII_8BIT) ||
MRB_STR_CASECMP_P(enc, ENC_BINARY)) {
s->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(s);
}
else if (MRB_STR_CASECMP_P(enc, ENC_UTF8)) {
s->flags &= ~MRB_STR_BINARY;
RSTR_UNSET_BINARY_FLAG(s);
}
else {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "unknown encoding name - %v", enc);
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-regexp/src/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ re_mark_spliced(mrb_value result, mrb_value subject, mrb_value replacement,
while (p < e && !(*p & 0x80)) p++;
if (p == e) return;
}
mrb_str_ptr(result)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(result));
}

/*
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-sprintf/src/sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ mark_written_bytes(mrb_value result, mrb_value src)
const char *p = RSTR_PTR(s);
const char *e = p + RSTR_LEN(s);
while (p < e && !(*p & 0x80)) p++;
if (p < e) r->flags |= MRB_STR_BINARY;
if (p < e) RSTR_SET_BINARY_FLAG(r);
}

static mrb_value
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-string-bitops/src/string_bitops.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ static mrb_value
bitop_result_str(mrb_state *mrb, mrb_int len)
{
mrb_value result = mrb_str_new(mrb, NULL, len);
mrb_str_ptr(result)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(result));
return result;
}

Expand Down
10 changes: 5 additions & 5 deletions mrbgems/mruby-string-ext/src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int_chr_binary(mrb_state *mrb, mrb_value num)
RSTR_SET_ASCII_FLAG(mrb_str_ptr(str));
}
else {
mrb_str_ptr(str)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(str));
}
return str;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ str_mark_spliced_bytes(mrb_value recv, mrb_value src)
const char *p = RSTR_PTR(s);
const char *e = p + RSTR_LEN(s);
while (p < e && !(*p & 0x80)) p++;
if (p < e) r->flags |= MRB_STR_BINARY;
if (p < e) RSTR_SET_BINARY_FLAG(r);
}

static void
Expand Down Expand Up @@ -1522,7 +1522,7 @@ static mrb_value
str_b(mrb_state *mrb, mrb_value self)
{
mrb_value str = mrb_str_dup(mrb, self);
mrb_str_ptr(str)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(str));
return str;
}

Expand Down Expand Up @@ -1914,7 +1914,7 @@ str_rjust_core(mrb_state *mrb, mrb_value self)
/* the padded string is the receiver's bytes in wider clothes, so it is
read the way the receiver was, ASCII bytes and all */
if (RSTR_BINARY_P(mrb_str_ptr(self))) {
mrb_str_ptr(result)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(result));
}
return result;
}
Expand Down Expand Up @@ -1988,7 +1988,7 @@ str_center_core(mrb_state *mrb, mrb_value self)
/* the padded string is the receiver's bytes in wider clothes, so it is
read the way the receiver was, ASCII bytes and all */
if (RSTR_BINARY_P(mrb_str_ptr(self))) {
mrb_str_ptr(result)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(result));
}
return result;
}
Expand Down
8 changes: 4 additions & 4 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b)
if ((RSTR_BINARY_P(s) && RSTR_BINARY_P(s2)) ||
(RSTR_BINARY_P(s) && !str_ascii_p(s)) ||
(RSTR_BINARY_P(s2) && !str_ascii_p(s2))) {
t->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(t);
}

return mrb_obj_value(t);
Expand Down Expand Up @@ -1851,7 +1851,7 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb
their reading over, ASCII bytes move nothing */
struct RString *repp = mrb_str_ptr(rep);
if (!RSTR_BINARY_P(str) && RSTR_BINARY_P(repp) && !str_ascii_p(repp)) {
str->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(str);
}
}
RSTR_SET_LEN(str, newlen);
Expand Down Expand Up @@ -3638,7 +3638,7 @@ mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2)
mrb_bool binary = !RSTR_BINARY_P(s) && RSTR_BINARY_P(s2) && !str_ascii_p(s2);
mrb_value ret = mrb_str_cat(mrb, str, RSTRING_PTR(str2), RSTRING_LEN(str2));
if (binary) {
mrb_str_ptr(ret)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(ret));
}
return ret;
}
Expand Down Expand Up @@ -3879,7 +3879,7 @@ sub_replace(mrb_state *mrb, mrb_value self)
if ((RSTR_BINARY_P(mrb_str_ptr(replace)) && !str_ascii_p(mrb_str_ptr(replace))) ||
(match_taken && RSTR_BINARY_P(mrb_str_ptr(pat)) && !str_ascii_p(mrb_str_ptr(pat))) ||
(self_taken && RSTR_BINARY_P(mrb_str_ptr(self)) && !str_ascii_p(mrb_str_ptr(self)))) {
mrb_str_ptr(result)->flags |= MRB_STR_BINARY;
RSTR_SET_BINARY_FLAG(mrb_str_ptr(result));
}
return result;
}
Expand Down
Loading