#| -*-Scheme-*-
-$Id: runtime.pkg,v 14.685 2008/09/21 23:50:31 cph Exp $
+$Id: runtime.pkg,v 14.686 2008/09/23 23:59:19 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
(vector-8b? string?)
allocate-external-string
burst-string
+ camel-case-string->lisp
char->string
decorated-string-append
error:not-string
guarantee-substring-start-index
guarantee-xstring
hexadecimal->vector-8b
+ lisp-string->camel-case
list->string
make-string
make-vector-8b
#| -*-Scheme-*-
-$Id: string.scm,v 14.69 2008/07/23 11:10:56 cph Exp $
+$Id: string.scm,v 14.70 2008/09/23 23:59:23 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
(%substring-upcase! string index (fix:+ index 1))
(%substring-downcase! string (fix:+ index 1) end)))))
\f
+;;;; CamelCase support
+
+(define (camel-case-string->lisp string)
+ (call-with-input-string string
+ (lambda (input)
+ (call-with-narrow-output-string
+ (lambda (output)
+ (let loop ((prev #f))
+ (let ((c (read-char input)))
+ (if (not (eof-object? c))
+ (begin
+ (if (and prev (char-upper-case? c))
+ (write-char #\- output))
+ (write-char (char-downcase c) output)
+ (loop c))))))))))
+
+(define (lisp-string->camel-case string #!optional upcase-initial?)
+ (call-with-input-string string
+ (lambda (input)
+ (call-with-narrow-output-string
+ (lambda (output)
+ (let loop
+ ((upcase?
+ (if (default-object? upcase-initial?)
+ #t
+ upcase-initial?)))
+ (let ((c (read-char input)))
+ (if (not (eof-object? c))
+ (if (char-alphabetic? c)
+ (begin
+ (write-char (if upcase? (char-upcase c) c) output)
+ (loop #f))
+ (begin
+ (if (or (char-numeric? c)
+ (eq? c #\_))
+ (write-char c output))
+ (loop #t)))))))))))
+\f
;;;; Replace
(define (string-replace string char1 char2)