method
squeeze!
Related methods
- Class methods (3)
-
new
-
try_convert
-
yaml_new
(<= v1_9_1_378)
- 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?
(<= v1_9_1_378)
-
is_complex_yaml?
(<= v1_9_1_378)
-
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
(<= v1_9_1_378)
-
tr
-
tr!
-
tr_s
-
tr_s!
-
unpack
-
upcase
-
upcase!
-
upto
-
valid_encoding?
= private
= protected
squeeze!(*args)
public
Squeezes str in place, returning either str, or nil if no changes were made.
Show source
static VALUE rb_str_squeeze_bang(int argc, VALUE *argv, VALUE str) { char squeez[256]; rb_encoding *enc = 0; VALUE del = 0, nodel = 0; char *s, *send, *t; int i, modify = 0; int ascompat, singlebyte = single_byte_optimizable(str); unsigned int save; if (argc == 0) { enc = STR_ENC_GET(str); } else { for (i=0; i<argc; i++) { VALUE s = argv[i]; StringValue(s); enc = rb_enc_check(str, s); if (singlebyte && !single_byte_optimizable(s)) singlebyte = 0; tr_setup_table(s, squeez, i==0, &del, &nodel, enc); } } str_modify_keep_cr(str); s = t = RSTRING_PTR(str); if (!s || RSTRING_LEN(str) == 0) return Qnil; send = RSTRING_END(str); save = -1; ascompat = rb_enc_asciicompat(enc); if (singlebyte) { while (s < send) { unsigned int c = *(unsigned char*)s++; if (c != save || (argc > 0 && !squeez[c])) { *t++ = save = c; } } } else { while (s < send) { unsigned int c; int clen; if (ascompat && (c = *(unsigned char*)s) < 0x80) { if (c != save || (argc > 0 && !squeez[c])) { *t++ = save = c; } s++; } else { c = rb_enc_codepoint_len(s, send, &clen, enc); if (c != save || (argc > 0 && !tr_find(c, squeez, del, nodel))) { if (t != s) rb_enc_mbcput(c, t, enc); save = c; t += clen; } s += clen; } } } *t = '\0'; if (t - RSTRING_PTR(str) != RSTRING_LEN(str)) { STR_SET_LEN(str, t - RSTRING_PTR(str)); modify = 1; } if (modify) return str; return Qnil; }


