mirror of
https://github.com/ruby/ruby.git
synced 2026-01-28 04:54:23 +00:00
[DOC] Tweaks for String#scrub (#14892)
This commit is contained in:
parent
862b42a52c
commit
cb52809ca1
@ -1,25 +1,22 @@
|
||||
Returns a copy of +self+ with each invalid byte sequence replaced
|
||||
by the given +replacement_string+.
|
||||
|
||||
With no block given and no argument, replaces each invalid sequence
|
||||
with the default replacement string
|
||||
(<tt>"<22>"</tt> for a Unicode encoding, <tt>'?'</tt> otherwise):
|
||||
With no block given, replaces each invalid sequence
|
||||
with the given +default_replacement_string+
|
||||
(by default, <tt>"<22>"</tt> for a Unicode encoding, <tt>'?'</tt> otherwise):
|
||||
|
||||
s = "foo\x81\x81bar"
|
||||
s.scrub # => "foo<6F><6F>bar"
|
||||
"foo\x81\x81bar"scrub # => "foo<6F><6F>bar"
|
||||
"foo\x81\x81bar".force_encoding('US-ASCII').scrub # => "foo??bar"
|
||||
"foo\x81\x81bar".scrub('xyzzy') # => "fooxyzzyxyzzybar"
|
||||
|
||||
With no block given and argument +replacement_string+ given,
|
||||
replaces each invalid sequence with that string:
|
||||
With a block given, calls the block with each invalid sequence,
|
||||
and replaces that sequence with the return value of the block:
|
||||
|
||||
"foo\x81\x81bar".scrub('xyzzy') # => "fooxyzzyxyzzybar"
|
||||
"foo\x81\x81bar".scrub {|sequence| p sequence; 'XYZZY' } # => "fooXYZZYXYZZYbar"
|
||||
|
||||
With a block given, replaces each invalid sequence with the value
|
||||
of the block:
|
||||
|
||||
"foo\x81\x81bar".scrub {|bytes| p bytes; 'XYZZY' }
|
||||
# => "fooXYZZYXYZZYbar"
|
||||
|
||||
Output:
|
||||
Output :
|
||||
|
||||
"\x81"
|
||||
"\x81"
|
||||
|
||||
Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String].
|
||||
|
||||
4
string.c
4
string.c
@ -11911,8 +11911,8 @@ enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl, int cr)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* scrub(replacement_string = default_replacement) -> new_string
|
||||
* scrub{|bytes| ... } -> new_string
|
||||
* scrub(replacement_string = default_replacement_string) -> new_string
|
||||
* scrub{|sequence| ... } -> new_string
|
||||
*
|
||||
* :include: doc/string/scrub.rdoc
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user