Changeset 35802 in project


Ignore:
Timestamp:
07/08/18 02:47:10 (13 days ago)
Author:
kon
Message:

fix ret typs, faster unistr

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/string-utils/trunk/unicode-utils.scm

    r35787 r35802  
    88(declare
    99  (bound-to-procedure
     10    ##sys#size
    1011    ##sys#string-append
    1112    ##sys#char->utf8-string
    1213    ##sys#unicode-surrogate?
    13     ##sys#surrogates->codepoint))
     14    ##sys#surrogates->codepoint
     15    ##sys#fragments->string))
    1416
    1517(module unicode-utils
     
    4244      (and (fx< 0 x) (fx< x #x80)) ) ) )
    4345
    44 (: unicode-char->string (char --> string))
     46(: unicode-char->string (char -> string))
    4547;
    4648(define (unicode-char->string ch)
     
    4850
    4951;inefficient
    50 (: unicode-string (#!rest (list-of char) --> string))
     52(: unicode-string (#!rest (list-of char) -> string))
    5153;
    5254(define (unicode-string . chs)
     
    5961      (*unicode-string chs) ) ) )
    6062
    61 (: unicode-make-string (fixnum #!optional char --> string))
     63(: unicode-make-string (fixnum #!optional char -> string))
    6264;
    6365(define (unicode-make-string len #!optional (fill #\space))
     
    7577    (##sys#unicode-surrogate? n) ) )
    7678
    77 (: unicode-surrogates->codepoint (fixnum fixnum --> (or boolean fixnum)))
     79(: unicode-surrogates->codepoint (fixnum fixnum -> (or boolean fixnum)))
    7880;
    7981(define (unicode-surrogates->codepoint hi lo)
     
    8284    (check-natural-fixnum 'unicode-surrogates->codepoint lo "low")) )
    8385
    84 (: *unicode-make-string (fixnum char --> string))
     86(: *unicode-make-string (fixnum char -> string))
    8587;
    8688(define (*unicode-make-string len fill)
     
    9395      (*unicode-string (make-list len fill)) ) ) )
    9496
    95 ;inefficient
    96 (: *unicode-string ((list-of char) --> string))
     97(: *unicode-string ((list-of char) -> string))
    9798;
    9899(define (*unicode-string chs)
     
    103104      (##sys#char->utf8-string (car chs)) )
    104105    (else
    105       (string-concatenate (map ##sys#char->utf8-string chs)) ) ) )
     106      (let ((chs (map ##sys#char->utf8-string chs)))
     107        (##sys#fragments->string
     108          (foldl (lambda (l s) (fx+ l (##sys#size s))) 0 chs)
     109          chs) ) ) ) )
    106110
    107111) ;module unicode-utils
Note: See TracChangeset for help on using the changeset viewer.