Method: String#lstrip!
- Defined in:
- string.c
permalink #lstrip! ⇒ self?
Removes leading whitespace from the receiver. Returns the altered receiver, or nil
if no change was made. See also String#rstrip! and String#strip!.
Refer to String#strip for the definition of whitespace.
" hello ".lstrip! #=> "hello "
"hello ".lstrip! #=> nil
"hello".lstrip! #=> nil
9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 |
# File 'string.c', line 9297
static VALUE
rb_str_lstrip_bang(VALUE str)
{
rb_encoding *enc;
char *start, *s;
long olen, loffset;
str_modify_keep_cr(str);
enc = STR_ENC_GET(str);
RSTRING_GETMEM(str, start, olen);
loffset = lstrip_offset(str, start, start+olen, enc);
if (loffset > 0) {
long len = olen-loffset;
s = start + loffset;
memmove(start, s, len);
STR_SET_LEN(str, len);
#if !SHARABLE_MIDDLE_SUBSTRING
TERM_FILL(start+len, rb_enc_mbminlen(enc));
#endif
return str;
}
return Qnil;
}
|