method
chomp!
Related methods
- Class methods (3)
-
new
-
try_convert
-
yaml_new
- Instance methods (148)
-
<<
-
<=>
-
=~
-
==
-
===
-
[]
-
[]=
-
*
-
%
-
+
-
ascii_only?
-
block_scanf
-
bytes
-
bytesize
-
byteslice
(>= v1_9_3_125)
-
capitalize
-
capitalize!
-
casecmp
-
center
-
chars
-
chomp
-
chomp!
-
chop
-
chop!
-
chr
-
clear
-
codepoints
-
concat
-
count
-
crypt
-
delete
-
delete!
-
downcase
-
downcase!
-
dump
-
each
(<= v1_8_7_330)
-
each_byte
-
each_char
-
each_codepoint
-
each_line
-
empty?
-
encode
-
encode!
-
encoding
-
end_regexp
(<= v1_8_7_330)
-
end_with?
-
eql?
-
_expand_ch
(<= v1_8_7_330)
-
expand_ch_hash
(<= v1_8_7_330)
-
ext
(>= v1_9_3_125)
-
force_encoding
-
getbyte
-
gsub
-
gsub!
-
hash
-
hex
-
include?
-
index
-
initialize_copy
-
insert
-
inspect
-
intern
-
is_binary_data?
-
is_complex_yaml?
-
iseuc
-
isjis
-
issjis
-
isutf8
-
jcount
(<= v1_8_7_330)
-
jlength
(<= v1_8_7_330)
-
jsize
(<= v1_8_7_330)
-
kconv
-
length
-
lines
-
ljust
-
lstrip
-
lstrip!
-
match
-
mbchar?
(<= v1_8_7_330)
-
next
-
next!
-
oct
-
ord
-
original_succ
(<= v1_8_7_330)
-
original_succ!
(<= v1_8_7_330)
-
parse_csv
-
partition
-
pathmap
(>= v1_9_3_125)
-
pathmap_explode
(>= v1_9_3_125)
-
pathmap_partial
(>= v1_9_3_125)
-
pathmap_replace
(>= v1_9_3_125)
-
prepend
(>= v1_9_3_125)
-
quote
(<= v1_8_6_287)
-
_regex_quote
(<= v1_8_7_330)
-
replace
-
reverse
-
reverse!
-
rindex
-
rjust
-
rpartition
-
rstrip
-
rstrip!
-
scan
-
scanf
-
setbyte
-
shellescape
-
shellsplit
-
size
-
slice
-
slice!
-
split
-
squeeze
-
squeeze!
-
start_with?
-
strip
-
strip!
-
sub
-
sub!
-
succ
-
succ!
-
sum
-
swapcase
-
swapcase!
-
to_c
-
to_d
-
toeuc
-
to_f
-
to_i
-
tojis
-
tolocale
-
to_r
-
to_s
-
tosjis
-
to_str
-
to_sym
-
toutf16
-
toutf32
-
toutf8
-
to_yaml
-
tr
-
tr!
-
tr_s
-
tr_s!
-
unpack
-
upcase
-
upcase!
-
upto
-
valid_encoding?
= private
= protected
chomp!(p1 = v1)
public
Modifies str in place as described for String#chomp, returning str, or nil if no modifications were made.
Show source
static VALUE rb_str_chomp_bang(int argc, VALUE *argv, VALUE str) { rb_encoding *enc; VALUE rs; int newline; char *p, *pp, *e; long len, rslen; len = RSTRING_LEN(str); if (len == 0) return Qnil; p = RSTRING_PTR(str); e = p + len; if (argc == 0) { rs = rb_rs; if (rs == rb_default_rs) { smart_chomp: str_modify_keep_cr(str); enc = rb_enc_get(str); if (rb_enc_mbminlen(enc) > 1) { pp = rb_enc_left_char_head(p, e-rb_enc_mbminlen(enc), e, enc); if (rb_enc_is_newline(pp, e, enc)) { e = pp; } pp = e - rb_enc_mbminlen(enc); if (pp >= p) { pp = rb_enc_left_char_head(p, pp, e, enc); if (rb_enc_ascget(pp, e, 0, enc) == '\r') { e = pp; } } if (e == RSTRING_END(str)) { return Qnil; } len = e - RSTRING_PTR(str); STR_SET_LEN(str, len); } else { if (RSTRING_PTR(str)[len-1] == '\n') { STR_DEC_LEN(str); if (RSTRING_LEN(str) > 0 && RSTRING_PTR(str)[RSTRING_LEN(str)-1] == '\r') { STR_DEC_LEN(str); } } else if (RSTRING_PTR(str)[len-1] == '\r') { STR_DEC_LEN(str); } else { return Qnil; } } RSTRING_PTR(str)[RSTRING_LEN(str)] = '\0'; return str; } } else { rb_scan_args(argc, argv, "01", &rs); } if (NIL_P(rs)) return Qnil; StringValue(rs); rslen = RSTRING_LEN(rs); if (rslen == 0) { while (len>0 && p[len-1] == '\n') { len--; if (len>0 && p[len-1] == '\r') len--; } if (len < RSTRING_LEN(str)) { str_modify_keep_cr(str); STR_SET_LEN(str, len); RSTRING_PTR(str)[len] = '\0'; return str; } return Qnil; } if (rslen > len) return Qnil; newline = RSTRING_PTR(rs)[rslen-1]; if (rslen == 1 && newline == '\n') goto smart_chomp; enc = rb_enc_check(str, rs); if (is_broken_string(rs)) { return Qnil; } pp = e - rslen; if (p[len-1] == newline && (rslen <= 1 || memcmp(RSTRING_PTR(rs), pp, rslen) == 0)) { if (rb_enc_left_char_head(p, pp, e, enc) != pp) return Qnil; rb_str_modify(str); STR_SET_LEN(str, RSTRING_LEN(str) - rslen); RSTRING_PTR(str)[RSTRING_LEN(str)] = '\0'; return str; } return Qnil; }


