summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/string.c b/string.c
index 73742cc38f..51147f36ec 100644
--- a/string.c
+++ b/string.c
@@ -201,6 +201,7 @@ rb_str_new4(orig)
else {
str = str_new4(klass, orig);
}
+ OBJ_INFECT(str, orig);
OBJ_FREEZE(str);
return str;
}
@@ -1323,7 +1324,7 @@ rb_str_match_m(argc, argv, str)
{
VALUE re;
if (argc < 1)
- rb_raise(rb_eArgError, "wrong number of arguments(%d for 1)", argc);
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
re = argv[0];
argv[0] = str;
return rb_funcall2(get_pat(re, 0), rb_intern("match"), argc, argv);
@@ -4378,7 +4379,7 @@ rb_str_crypt(str, salt)
StringValue(salt);
if (RSTRING(salt)->len < 2)
- rb_raise(rb_eArgError, "salt too short(need >=2 bytes)");
+ rb_raise(rb_eArgError, "salt too short (need >=2 bytes)");
if (RSTRING(str)->ptr) s = RSTRING(str)->ptr;
else s = "";
@@ -4504,7 +4505,6 @@ rb_str_justify(argc, argv, str, jflag)
rb_scan_args(argc, argv, "11", &w, &pad);
width = NUM2LONG(w);
- if (width < 0 || RSTRING(str)->len >= width) return rb_str_dup(str);
if (argc == 2) {
StringValue(pad);
f = RSTRING(pad)->ptr;
@@ -4513,6 +4513,7 @@ rb_str_justify(argc, argv, str, jflag)
rb_raise(rb_eArgError, "zero width padding");
}
}
+ if (width < 0 || RSTRING(str)->len >= width) return rb_str_dup(str);
res = rb_str_new5(str, 0, width);
p = RSTRING(res)->ptr;
if (jflag != 'l') {
@@ -4560,14 +4561,15 @@ rb_str_justify(argc, argv, str, jflag)
/*
* call-seq:
- * str.ljust(integer) => new_str
+ * str.ljust(integer, padstr=' ') => new_str
*
* If <i>integer</i> is greater than the length of <i>str</i>, returns a new
* <code>String</code> of length <i>integer</i> with <i>str</i> left justified
- * and space padded; otherwise, returns <i>str</i>.
+ * and padded with <i>padstr</i>; otherwise, returns <i>str</i>.
*
- * "hello".ljust(4) #=> "hello"
- * "hello".ljust(20) #=> "hello "
+ * "hello".ljust(4) #=> "hello"
+ * "hello".ljust(20) #=> "hello "
+ * "hello".ljust(20, '1234') #=> "hello123412341234123"
*/
static VALUE
@@ -4582,14 +4584,15 @@ rb_str_ljust(argc, argv, str)
/*
* call-seq:
- * str.rjust(integer) => new_str
+ * str.rjust(integer, padstr=' ') => new_str
*
* If <i>integer</i> is greater than the length of <i>str</i>, returns a new
* <code>String</code> of length <i>integer</i> with <i>str</i> right justified
- * and space padded; otherwise, returns <i>str</i>.
+ * and padded with <i>padstr</i>; otherwise, returns <i>str</i>.
*
- * "hello".rjust(4) #=> "hello"
- * "hello".rjust(20) #=> " hello"
+ * "hello".rjust(4) #=> "hello"
+ * "hello".rjust(20) #=> " hello"
+ * "hello".rjust(20, '1234') #=> "123412341234123hello"
*/
static VALUE
@@ -4604,14 +4607,15 @@ rb_str_rjust(argc, argv, str)
/*
* call-seq:
- * str.center(integer) => new_str
+ * str.center(integer, padstr) => new_str
*
* If <i>integer</i> is greater than the length of <i>str</i>, returns a new
- * <code>String</code> of length <i>integer</i> with <i>str</i> centered
- * between spaces; otherwise, returns <i>str</i>.
+ * <code>String</code> of length <i>integer</i> with <i>str</i> centered and
+ * padded with <i>padstr</i>; otherwise, returns <i>str</i>.
*
- * "hello".center(4) #=> "hello"
- * "hello".center(20) #=> " hello "
+ * "hello".center(4) #=> "hello"
+ * "hello".center(20) #=> " hello "
+ * "hello".center(20, '123') #=> "1231231hello12312312"
*/
static VALUE