Skip to content

Commit

Permalink
* array.c (rb_ary_cycle): typo in rdoc. a patch from Yugui
Browse files Browse the repository at this point in the history
  <[email protected]>.  [ruby-dev:31748]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Sep 6, 2007
1 parent 629b1e4 commit edd7c78
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 133 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Thu Sep 6 21:31:49 2007 Yukihiro Matsumoto <[email protected]>

* array.c (rb_ary_cycle): typo in rdoc. a patch from Yugui
<[email protected]>. [ruby-dev:31748]

Thu Sep 6 12:42:10 2007 Nobuyoshi Nakada <[email protected]>

* string.c (rb_str_succ, rb_str_chop_bang, rb_str_chop): m17n support.
Expand Down
2 changes: 1 addition & 1 deletion array.c
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,7 @@ rb_ary_choice(VALUE ary)
* Calls <i>block</i> repeatedly forever.
*
* a = ["a", "b", "c"]
* a.each {|x| puts x } # print, a, b, c, a, b, c,.. forever.
* a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
*
*/

Expand Down
8 changes: 4 additions & 4 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ rb_enc_nth(const char *p, const char *e, int nth, rb_encoding *enc)
}
else {
for (c=0; p<e && nth--; c++) {
int n = rb_enc_mbclen(p, enc);
int n = rb_enc_mbclen(p, e, enc);

if (n == 0) return 0;
p += n;
Expand All @@ -208,7 +208,7 @@ rb_enc_strlen(const char *p, const char *e, rb_encoding *enc)
}

for (c=0; p<e; c++) {
int n = rb_enc_mbclen(p, enc);
int n = rb_enc_mbclen(p, e, enc);

if (n == 0) return -1;
p += n;
Expand All @@ -217,9 +217,9 @@ rb_enc_strlen(const char *p, const char *e, rb_encoding *enc)
}

int
rb_enc_mbclen(const char *p, rb_encoding *enc)
rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
{
int n = ONIGENC_MBC_ENC_LEN(enc, (UChar*)p);
int n = ONIGENC_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
if (n == 0) {
rb_raise(rb_eArgError, "invalid mbstring sequence");
}
Expand Down
10 changes: 5 additions & 5 deletions euc_jp.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static const int EncLen_EUCJP[] = {
};

static int
mbc_enc_len(const UChar* p)
mbc_enc_len(const UChar* p, const UChar* e)
{
return EncLen_EUCJP[*p];
}
Expand All @@ -62,7 +62,7 @@ mbc_to_code(const UChar* p, const UChar* end)
int c, i, len;
OnigCodePoint n;

len = enc_len(ONIG_ENCODING_EUC_JP, p);
len = enc_len(ONIG_ENCODING_EUC_JP, p, end);
n = (OnigCodePoint )*p++;
if (len == 1) return n;

Expand Down Expand Up @@ -113,7 +113,7 @@ code_to_mbc(OnigCodePoint code, UChar *buf)
*p++ = (UChar )(code & 0xff);

#if 1
if (enc_len(ONIG_ENCODING_EUC_JP, buf) != (p - buf))
if (enc_len(ONIG_ENCODING_EUC_JP, buf, p) != (p - buf))
return ONIGENC_ERR_INVALID_WIDE_CHAR_VALUE;
#endif
return p - buf;
Expand All @@ -134,7 +134,7 @@ mbc_case_fold(OnigCaseFoldType flag,
else {
int i;

len = enc_len(ONIG_ENCODING_EUC_JP, p);
len = enc_len(ONIG_ENCODING_EUC_JP, p, end);
for (i = 0; i < len; i++) {
*lower++ = *p++;
}
Expand All @@ -156,7 +156,7 @@ left_adjust_char_head(const UChar* start, const UChar* s)
p = s;

while (!eucjp_islead(*p) && p > start) p--;
len = enc_len(ONIG_ENCODING_EUC_JP, p);
len = enc_len(ONIG_ENCODING_EUC_JP, p, s);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
Expand Down
2 changes: 1 addition & 1 deletion ext/strscan/strscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ strscan_getch(VALUE self)
if (EOS_P(p))
return Qnil;

len = rb_enc_mbclen(CURPTR(p), enc);
len = rb_enc_mbclen(CURPTR(p), S_PEND(p), enc);
if (p->curr + len > S_LEN(p)) {
len = S_LEN(p) - p->curr;
}
Expand Down
2 changes: 1 addition & 1 deletion include/ruby/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ rb_encoding * rb_enc_find(const char *name);
#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len

/* ptr,encoding -> mbclen */
int rb_enc_mbclen(const char*, rb_encoding*);
int rb_enc_mbclen(const char*, const char *, rb_encoding*);

/* code,encoding -> codelen */
int rb_enc_codelen(int, rb_encoding*);
Expand Down
8 changes: 4 additions & 4 deletions include/ruby/oniguruma.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ typedef struct {
typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);

typedef struct OnigEncodingTypeST {
int (*mbc_enc_len)(const OnigUChar* p);
int (*mbc_enc_len)(const OnigUChar* p,const OnigUChar* e);
const char* name;
int max_enc_len;
int min_enc_len;
Expand Down Expand Up @@ -255,11 +255,11 @@ ONIG_EXTERN OnigEncodingType OnigEncodingGB18030;
#define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII


#define enc_len(enc,p) ONIGENC_MBC_ENC_LEN(enc, p)
#define enc_len(enc,p,e) ONIGENC_MBC_ENC_LEN(enc, p, e)

#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF)
#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1)
#define ONIGENC_IS_MBC_HEAD(enc,p) (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
#define ONIGENC_IS_MBC_HEAD(enc,p,e) (ONIGENC_MBC_ENC_LEN(enc,p,e) != 1)
#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128)
#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128)
#define ONIGENC_IS_MBC_WORD(enc,s,end) \
Expand All @@ -281,7 +281,7 @@ ONIG_EXTERN OnigEncodingType OnigEncodingGB18030;
#define ONIGENC_STEP_BACK(enc,start,s,n) \
onigenc_step_back((enc),(start),(s),(n))

#define ONIGENC_MBC_ENC_LEN(enc,p) (enc)->mbc_enc_len(p)
#define ONIGENC_MBC_ENC_LEN(enc,p,e) (enc)->mbc_enc_len(p,e)
#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len)
#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc)
#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
Expand Down
4 changes: 2 additions & 2 deletions include/ruby/regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ extern "C" {

ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding;

#define ismbchar(p, enc) (mbclen((p),(enc)) != 1)
#define mbclen(p,enc) rb_enc_mbclen((p), (enc))
#define ismbchar(p, e, enc) (mbclen((p),(e),(enc)) != 1)
#define mbclen(p,e,enc) rb_enc_mbclen((p),(e),(enc))

#endif /* ifndef ONIG_RUBY_M17N */

Expand Down
29 changes: 16 additions & 13 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -4558,10 +4558,10 @@ ripper_dispatch_delayed_token(struct parser_params *parser, int t)
# define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
#endif

#define parser_mbclen() mbclen((lex_p-1),parser->enc)
#define is_identchar(p, enc) (rb_enc_isalnum(*p, enc) || (*p) == '_' || ismbchar(p, enc))
#define parser_ismbchar() ismbchar((lex_p-1), parser->enc)
#define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),parser->enc))
#define parser_mbclen() mbclen((lex_p-1),lex_pend,parser->enc)
#define is_identchar(p,e,enc) (rb_enc_isalnum(*p,enc) || (*p) == '_' || ismbchar(p,e,enc))
#define parser_ismbchar() ismbchar((lex_p-1), lex_pend, parser->enc)
#define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,parser->enc))

static int
parser_yyerror(struct parser_params *parser, const char *msg)
Expand Down Expand Up @@ -5995,7 +5995,7 @@ parser_yylex(struct parser_params *parser)
}
}
else if ((rb_enc_isalnum(c, parser->enc) || c == '_') &&
lex_p < lex_pend && is_identchar(lex_p, parser->enc)) {
lex_p < lex_pend && is_identchar(lex_p, lex_pend, parser->enc)) {
goto ternary;
}
else if (c == '\\') {
Expand Down Expand Up @@ -8328,7 +8328,7 @@ internal_id_gen(struct parser_params *parser)
}

static int
is_special_global_name(const char *m, rb_encoding *enc)
is_special_global_name(const char *m, const char *e, rb_encoding *enc)
{
switch (*m) {
case '~': case '*': case '$': case '?': case '!': case '@':
Expand All @@ -8340,7 +8340,7 @@ is_special_global_name(const char *m, rb_encoding *enc)
break;
case '-':
++m;
if (is_identchar(m, enc)) m += rb_enc_mbclen(m, enc);
if (is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
break;
default:
if (!rb_enc_isdigit(*m, enc)) return 0;
Expand All @@ -8353,6 +8353,7 @@ int
rb_symname_p(const char *name)
{
const char *m = name;
const char *e = m + strlen(m);
int localid = Qfalse;
rb_encoding *enc = rb_enc_from_index(0);

Expand All @@ -8362,7 +8363,7 @@ rb_symname_p(const char *name)
return Qfalse;

case '$':
if (is_special_global_name(++m, enc)) return Qtrue;
if (is_special_global_name(++m, e, enc)) return Qtrue;
goto id;

case '@':
Expand Down Expand Up @@ -8411,8 +8412,9 @@ rb_symname_p(const char *name)
default:
localid = !rb_enc_isupper(*m, enc);
id:
if (*m != '_' && !rb_enc_isalpha(*m, enc) && !ismbchar(m, enc)) return Qfalse;
while (is_identchar(m, enc)) m += rb_enc_mbclen(m, enc);
if (*m != '_' && !rb_enc_isalpha(*m, enc) && !ismbchar(m, e, enc))
return Qfalse;
while (is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
if (localid) {
switch (*m) {
case '!': case '?': case '=': ++m;
Expand All @@ -8427,6 +8429,7 @@ ID
rb_intern3(const char *name, long len, rb_encoding *enc)
{
const char *m = name;
const char *e = m + len;
VALUE str;
ID id;
int last;
Expand All @@ -8445,7 +8448,7 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
switch (*m) {
case '$':
id |= ID_GLOBAL;
if (is_special_global_name(++m, enc)) goto new_id;
if (is_special_global_name(++m, e, enc)) goto new_id;
break;
case '@':
if (m[1] == '@') {
Expand Down Expand Up @@ -8490,8 +8493,8 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
break;
}
if (!rb_enc_isdigit(*m, enc)) {
while (m <= name + last && is_identchar(m, enc)) {
m += rb_enc_mbclen(m, enc);
while (m <= name + last && is_identchar(m, e, enc)) {
m += rb_enc_mbclen(m, e, enc);
}
}
if (m - name < len) id = ID_JUNK;
Expand Down
26 changes: 13 additions & 13 deletions re.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ rb_reg_expr_str(VALUE str, const char *s, long len)

p = s; pend = p + len;
while (p<pend) {
if (*p == '/' || (!rb_enc_isprint(*p, enc) && !ismbchar(p, enc))) {
if (*p == '/' || (!rb_enc_isprint(*p, enc) && !ismbchar(p, pend, enc))) {
need_escape = 1;
break;
}
p += mbclen(p, enc);
p += mbclen(p, pend, enc);
}
if (!need_escape) {
rb_str_buf_cat(str, s, len);
Expand All @@ -406,7 +406,7 @@ rb_reg_expr_str(VALUE str, const char *s, long len)
p = s;
while (p<pend) {
if (*p == '\\') {
int n = mbclen(p+1, enc) + 1;
int n = mbclen(p+1, pend, enc) + 1;
rb_str_buf_cat(str, p, n);
p += n;
continue;
Expand All @@ -416,9 +416,9 @@ rb_reg_expr_str(VALUE str, const char *s, long len)
rb_str_buf_cat(str, &c, 1);
rb_str_buf_cat(str, p, 1);
}
else if (ismbchar(p, enc)) {
rb_str_buf_cat(str, p, mbclen(p, enc));
p += mbclen(p, enc);
else if (ismbchar(p, pend, enc)) {
rb_str_buf_cat(str, p, mbclen(p, pend, enc));
p += mbclen(p, pend, enc);
continue;
}
else if (rb_enc_isprint(*p, enc)) {
Expand Down Expand Up @@ -1906,8 +1906,8 @@ rb_reg_quote(VALUE str)
send = s + RSTRING_LEN(str);
for (; s < send; s++) {
c = *s;
if (ismbchar(s, enc)) {
int n = mbclen(s, enc);
if (ismbchar(s, send, enc)) {
int n = mbclen(s, send, enc);

while (n-- && s < send)
s++;
Expand Down Expand Up @@ -1935,8 +1935,8 @@ rb_reg_quote(VALUE str)

for (; s < send; s++) {
c = *s;
if (ismbchar(s, enc)) {
int n = mbclen(s, enc);
if (ismbchar(s, send, enc)) {
int n = mbclen(s, send, enc);

while (n-- && s < send)
*t++ = *s++;
Expand Down Expand Up @@ -2180,8 +2180,8 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
while (s < e) {
char *ss = s++;

if (ismbchar(ss, enc)) {
s += mbclen(ss, enc) - 1;
if (ismbchar(ss, e, enc)) {
s += mbclen(ss, e, enc) - 1;
continue;
}
if (*ss != '\\' || s == e) continue;
Expand Down Expand Up @@ -2214,7 +2214,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
name_end = name = s + 1;
while (name_end < e) {
if (*name_end == '>') break;
name_end += mbclen(name_end, enc);
name_end += mbclen(name_end, e, enc);
}
if (name_end < e) {
no = name_to_backref_number(regs, regexp, name, name_end);
Expand Down
Loading

0 comments on commit edd7c78

Please sign in to comment.