method
squeeze!
v1_8_7_330 -
Show latest stable
- Class:
String
squeeze!(...)public
Squeezes str in place, returning either str, or nil if no changes were made.
/*
* call-seq:
* str.squeeze!([other_str]*) => str or nil
*
* Squeezes <i>str</i> in place, returning either <i>str</i>, or
* <code>nil</code> if no changes were made.
*/
static VALUE
rb_str_squeeze_bang(argc, argv, str)
int argc;
VALUE *argv;
VALUE str;
{
char squeez[256];
char *s, *send, *t;
int c, save, modify = 0;
int init = 1;
int i;
if (argc == 0) {
for (i=0; i<256; i++) {
squeez[i] = 1;
}
}
else {
for (i=0; i<argc; i++) {
VALUE s = argv[i];
StringValue(s);
tr_setup_table(s, squeez, init);
init = 0;
}
}
rb_str_modify(str);
s = t = RSTRING(str)->ptr;
if (!s || RSTRING(str)->len == 0) return Qnil;
send = s + RSTRING(str)->len;
save = -1;
while (s < send) {
c = *s++ & 0xff;
if (c != save || !squeez[c]) {
*t++ = save = c;
}
}
*t = '\0';
if (t - RSTRING(str)->ptr != RSTRING(str)->len) {
RSTRING(str)->len = t - RSTRING(str)->ptr;
modify = 1;
}
if (modify) return str;
return Qnil;
} Related methods
- Instance methods
- %
- *
- +
- <<
- <=>
- ==
- =~
- []
- []=
- block_scanf
- bytes
- bytesize
- capitalize
- capitalize!
- casecmp
- center
- chars
- chomp
- chomp!
- chop
- chop
- chop!
- chop!
- concat
- count
- crypt
- delete
- delete
- delete!
- delete!
- downcase
- downcase!
- dump
- each
- each_byte
- each_char
- each_char
- each_line
- empty?
- end_regexp
- end_with?
- eql?
- gsub
- gsub!
- hash
- hex
- include?
- index
- initialize_copy
- insert
- inspect
- intern
- is_binary_data?
- is_complex_yaml?
- iseuc
- issjis
- isutf8
- jcount
- jlength
- jsize
- kconv
- length
- lines
- ljust
- lstrip
- lstrip!
- match
- mbchar?
- next
- next!
- oct
- partition
- replace
- reverse
- reverse!
- rindex
- rjust
- rpartition
- rstrip
- rstrip!
- scan
- scanf
- shellescape
- shellsplit
- size
- slice
- slice!
- split
- squeeze
- squeeze
- squeeze!
- squeeze!
- start_with?
- strip
- strip!
- sub
- sub!
- succ
- succ
- succ!
- succ!
- sum
- swapcase
- swapcase!
- to_f
- to_i
- to_s
- to_str
- to_sym
- to_yaml
- toeuc
- tojis
- tosjis
- toutf16
- toutf8
- tr
- tr
- tr!
- tr!
- tr_s
- tr_s
- tr_s!
- tr_s!
- unpack
- upcase
- upcase!
- upto
- Class methods
- new
- yaml_new
- Private methods
-
_expand_ch -
_regex_quote -
expand_ch_hash -
original_succ -
original_succ!