string-copy

This commit is contained in:
Danny Yoo 2011-11-07 18:53:53 -05:00
parent e417662c31
commit db278efcd1
8 changed files with 22 additions and 5 deletions

View File

@ -108,6 +108,8 @@
'hash-remove! 'hash-remove!
'hash-remove 'hash-remove
'equal-hash-code 'equal-hash-code
'string-copy
)) ))
(define-predicate KernelPrimitiveName? KernelPrimitiveName) (define-predicate KernelPrimitiveName? KernelPrimitiveName)

View File

@ -791,7 +791,15 @@
if (M.a === 3) { if (M.a === 3) {
end = baselib.numbers.toFixnum(checkNatural(M, 'substring', 2)); end = baselib.numbers.toFixnum(checkNatural(M, 'substring', 2));
} }
return str.substring(start, end); return baselib.strings.makeMutableString((str.substring(start, end)).split(""));
});
installPrimitiveProcedure(
'string-copy',
1,
function(M) {
var str = checkString(M, 'substring', 0).toString();
return baselib.strings.makeMutableString(str.substring(0, str.length).split(""));
}); });

View File

@ -96,7 +96,7 @@
}; };
Str.prototype.replace = function (expr, newStr) { Str.prototype.replace = function (expr, newStr) {
return Str.fromString( this.toString().replace(expr, newStr) ); return Str.fromString(this.toString().replace(expr, newStr) );
}; };
@ -117,11 +117,11 @@
}; };
Str.prototype.toUpperCase = function () { Str.prototype.toUpperCase = function () {
return Str.fromString( this.chars.join("").toUpperCase() ); return Str.fromString(this.chars.join("").toUpperCase() );
}; };
Str.prototype.toLowerCase = function () { Str.prototype.toLowerCase = function () {
return Str.fromString( this.chars.join("").toLowerCase() ); return Str.fromString(this.chars.join("").toLowerCase() );
}; };
Str.prototype.match = function (regexpr) { Str.prototype.match = function (regexpr) {

View File

@ -431,6 +431,7 @@ box?
string-ci<=? string-ci<=?
string-ci>=? string-ci>=?
string-copy
substring substring
string-append string-append
string->list string->list

View File

@ -0,0 +1,3 @@
#lang planet dyoo/whalesong/cs019
.. ;; should raise a teaching syntax error

View File

@ -11,6 +11,7 @@
"" ""
"l" "l"
"lo" "lo"
"hello world"
"" ""
"hello" "hello"
"" ""

View File

@ -14,6 +14,8 @@
(substring "hello world" 3 4) (substring "hello world" 3 4)
(substring "hello world" 3 5) (substring "hello world" 3 5)
(string-copy "hello world")
(list->string '()) (list->string '())
(list->string '(#\h #\e #\l #\l #\o)) (list->string '(#\h #\e #\l #\l #\o))

View File

@ -6,4 +6,4 @@
(provide version) (provide version)
(: version String) (: version String)
(define version "1.62") (define version "1.64")