* pack.c (pack_pack): always add with null for 'Z'.
* pack.c (pack_unpack): terminated by null for 'Z'. [ruby-talk:98281] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
93472ba0ed
commit
67ffc9d9e1
@ -1,3 +1,9 @@
|
|||||||
|
Thu May 13 11:04:08 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* pack.c (pack_pack): always add with null for 'Z'.
|
||||||
|
|
||||||
|
* pack.c (pack_unpack): terminated by null for 'Z'. [ruby-talk:98281]
|
||||||
|
|
||||||
Wed May 12 19:59:43 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed May 12 19:59:43 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/mkmf.rb (have_type, check_sizeof): replace unusable characters.
|
* lib/mkmf.rb (have_type, check_sizeof): replace unusable characters.
|
||||||
|
24
pack.c
24
pack.c
@ -434,7 +434,7 @@ static unsigned long utf8_to_uv _((char*,long*));
|
|||||||
* w | BER-compressed integer\fnm
|
* w | BER-compressed integer\fnm
|
||||||
* X | Back up a byte
|
* X | Back up a byte
|
||||||
* x | Null byte
|
* x | Null byte
|
||||||
* Z | Same as ``A''
|
* Z | Same as ``a'', except that null is added with *
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -523,8 +523,11 @@ pack_pack(ary, fmt)
|
|||||||
case 'a': /* arbitrary binary string (null padded) */
|
case 'a': /* arbitrary binary string (null padded) */
|
||||||
case 'A': /* ASCII string (space padded) */
|
case 'A': /* ASCII string (space padded) */
|
||||||
case 'Z': /* null terminated ASCII string */
|
case 'Z': /* null terminated ASCII string */
|
||||||
if (plen >= len)
|
if (plen >= len) {
|
||||||
rb_str_buf_cat(res, ptr, len);
|
rb_str_buf_cat(res, ptr, len);
|
||||||
|
if (p[-1] == '*' && type == 'Z')
|
||||||
|
rb_str_buf_cat(res, nul10, 1);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
rb_str_buf_cat(res, ptr, plen);
|
rb_str_buf_cat(res, ptr, plen);
|
||||||
len -= plen;
|
len -= plen;
|
||||||
@ -1173,6 +1176,7 @@ infected_str_new(ptr, len, str)
|
|||||||
*
|
*
|
||||||
* "abc \0\0abc \0\0".unpack('A6Z6') #=> ["abc", "abc "]
|
* "abc \0\0abc \0\0".unpack('A6Z6') #=> ["abc", "abc "]
|
||||||
* "abc \0\0".unpack('a3a3') #=> ["abc", " \000\000"]
|
* "abc \0\0".unpack('a3a3') #=> ["abc", " \000\000"]
|
||||||
|
* "abc \0abc \0".unpack('Z*Z*') #=> ["abc ", "abc "]
|
||||||
* "aa".unpack('b8B8') #=> ["10000110", "01100001"]
|
* "aa".unpack('b8B8') #=> ["10000110", "01100001"]
|
||||||
* "aaa".unpack('h2H2c') #=> ["16", "61", 97]
|
* "aaa".unpack('h2H2c') #=> ["16", "61", 97]
|
||||||
* "\xfe\xff\xfe\xff".unpack('sS') #=> [-2, 65534]
|
* "\xfe\xff\xfe\xff".unpack('sS') #=> [-2, 65534]
|
||||||
@ -1284,6 +1288,7 @@ infected_str_new(ptr, len, str)
|
|||||||
* x | --- | skip forward one character
|
* x | --- | skip forward one character
|
||||||
* -------+---------+-----------------------------------------
|
* -------+---------+-----------------------------------------
|
||||||
* Z | String | with trailing nulls removed
|
* Z | String | with trailing nulls removed
|
||||||
|
* | | upto first null with *
|
||||||
* -------+---------+-----------------------------------------
|
* -------+---------+-----------------------------------------
|
||||||
* @ | --- | skip to the offset given by the
|
* @ | --- | skip to the offset given by the
|
||||||
* | | length argument
|
* | | length argument
|
||||||
@ -1375,17 +1380,14 @@ pack_unpack(str, fmt)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Z':
|
case 'Z':
|
||||||
if (len > send - s) len = send - s;
|
|
||||||
{
|
{
|
||||||
long end = len;
|
char *t = s;
|
||||||
char *t = s + len - 1;
|
|
||||||
|
|
||||||
while (t >= s) {
|
if (len > send-s) len = send-s;
|
||||||
if (*t) break;
|
while (t < s+len && *t) t++;
|
||||||
t--; len--;
|
rb_ary_push(ary, infected_str_new(s, t-s, str));
|
||||||
}
|
if (t < send) t++;
|
||||||
rb_ary_push(ary, infected_str_new(s, len, str));
|
s = star ? t : s+len;
|
||||||
s += end;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user