[uim-commit] r2306 - in branches/r5rs/sigscheme: . test

kzk at freedesktop.org kzk at freedesktop.org
Thu Dec 1 08:39:16 PST 2005


Author: kzk
Date: 2005-12-01 08:39:11 -0800 (Thu, 01 Dec 2005)
New Revision: 2306

Modified:
   branches/r5rs/sigscheme/operations.c
   branches/r5rs/sigscheme/test/test-string.scm
Log:
* sigscheme/operations.c
  - (ScmOp_string_filld): handle empty string more easy way

* sigscheme/test/test-string.scm
  - add testcase for string-fill!


Modified: branches/r5rs/sigscheme/operations.c
===================================================================
--- branches/r5rs/sigscheme/operations.c	2005-12-01 16:29:34 UTC (rev 2305)
+++ branches/r5rs/sigscheme/operations.c	2005-12-01 16:39:11 UTC (rev 2306)
@@ -1427,6 +1427,10 @@
     ASSERT_MUTABLEP(str);
     ASSERT_CHARP(ch);
 
+    str_len = SCM_STRING_LEN(str);
+    if (str_len == 0)
+        return Scm_NewMutableStringCopying("");
+
     /* FIXME: support stateful encoding */
     next = SCM_CHARCODEC_INT2STR(Scm_current_char_codec, ch_str,
                                  SCM_CHAR_VALUE(ch), SCM_MB_STATELESS);
@@ -1435,7 +1439,6 @@
 
     /* create new str */
     char_size = next - ch_str;
-    str_len   = SCM_STRING_LEN(str);
     new_str   = realloc(SCM_STRING_STR(str), str_len * char_size + 1);
     for (p = new_str; p < &new_str[char_size * str_len]; p += char_size) {
         strcpy(p, ch_str);

Modified: branches/r5rs/sigscheme/test/test-string.scm
===================================================================
--- branches/r5rs/sigscheme/test/test-string.scm	2005-12-01 16:29:34 UTC (rev 2305)
+++ branches/r5rs/sigscheme/test/test-string.scm	2005-12-01 16:39:11 UTC (rev 2306)
@@ -248,10 +248,16 @@
 ;; string-fill!
 ;;;; immutable
 (assert-error "string-fill! immutable" (lambda ()
+					 (string-fill! "" #\j)))
+(assert-error "string-fill! immutable" (lambda ()
 					 (string-fill! "foo" #\j)))
 (assert-error "string-fill! immutable" (lambda ()
 					 (string-fill! (string->symbol 'foo) #\j)))
 ;;;; mutable
+(assert-equal? "string-fill! mutable" "" (begin
+					   (define tmpstr (string-copy ""))
+					   (string-fill! tmpstr #\j)
+					   tmpstr))
 (assert-equal? "string-fill! mutable" "jjjjj" (begin
 						(define tmpstr (string-copy "abcde"))
 						(string-fill! tmpstr #\j)



More information about the uim-commit mailing list