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
1 change: 0 additions & 1 deletion mrbgems/mruby-regexp/include/re_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ void mrb_re_free(mrb_state *mrb, mrb_regexp_pattern *pat);
/* UTF-8 helpers */
int mrb_re_utf8_charlen(const char *s, const char *end);
uint32_t mrb_re_utf8_decode(const char *s, const char *end, int *len);
int mrb_re_utf8_encode(uint32_t cp, char *buf);
mrb_bool mrb_re_is_word_char(uint32_t c);

/* The two foldings whose result is an ASCII letter. Every build carries them,
Expand Down
5 changes: 3 additions & 2 deletions mrbgems/mruby-regexp/src/re_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "re_internal.h"
#include <mruby/error.h>
#include <mruby/internal.h>
#include <string.h>

/* Compiler state */
Expand Down Expand Up @@ -449,7 +450,7 @@ parse_escape(re_compiler *c)

/* Reject what has no UTF-8 encoding. CRuby reports both a surrogate and a
value past the last plane as "invalid Unicode range", so neither ever
reaches mrb_re_utf8_encode(). */
reaches mrb_utf8_to_buf(). */
static void
check_unicode_cp(re_compiler *c, uint32_t cp)
{
Expand Down Expand Up @@ -1038,7 +1039,7 @@ emit_codepoint(re_compiler *c, uint32_t cp)
}
if ((c->flags & RE_FLAG_IGNORECASE) && emit_cp_folded(c, cp)) return;
char buf[4];
int len = mrb_re_utf8_encode(cp, buf);
int len = (int)mrb_utf8_to_buf(buf, cp);
for (int i = 0; i < len; i++) {
emit(c, RE_CHAR, (uint8_t)buf[i], 0);
}
Expand Down
28 changes: 0 additions & 28 deletions mrbgems/mruby-regexp/src/re_utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,6 @@ mrb_re_utf8_decode(const char *s, const char *end, int *len)
}
}

/* Encode a codepoint as UTF-8 into buf and return the byte length, at most 4.
Callers reject a surrogate and anything above U+10FFFF before they get
here, so every input has an encoding. */
int
mrb_re_utf8_encode(uint32_t cp, char *buf)
{
if (cp < 0x80) {
buf[0] = (char)cp;
return 1;
}
if (cp < 0x800) {
buf[0] = (char)(0xc0 | (cp >> 6));
buf[1] = (char)(0x80 | (cp & 0x3f));
return 2;
}
if (cp < 0x10000) {
buf[0] = (char)(0xe0 | (cp >> 12));
buf[1] = (char)(0x80 | ((cp >> 6) & 0x3f));
buf[2] = (char)(0x80 | (cp & 0x3f));
return 3;
}
buf[0] = (char)(0xf0 | (cp >> 18));
buf[1] = (char)(0x80 | ((cp >> 12) & 0x3f));
buf[2] = (char)(0x80 | ((cp >> 6) & 0x3f));
buf[3] = (char)(0x80 | (cp & 0x3f));
return 4;
}

/* Check if character is a "word" character (\w): [a-zA-Z0-9_] */
mrb_bool
mrb_re_is_word_char(uint32_t c)
Expand Down
Loading