Ignore:
Timestamp:
04/04/21 07:26:31 (4 months ago)
Author:
Kon Lovett
Message:

add semantic-version & support

File:
1 edited

Legend:

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

    r39822 r39830  
    1 ;;;; string-utils.scm  -*- scheme -*-
     1;;;; string-utils.scm  -*- Scheme -*-
    22;;;; Kon Lovett, Jan '21
    33;;;; Kon Lovett, Jul '18
     
    77
    88(;export
     9  string-unzip
     10  string-zip
    911  string-trim-whitespace-both
    1012  list-as-string
     
    2224        (chicken sort)
    2325        (only (chicken port) with-output-to-string)
     26        (only (chicken string) string-split)
    2427        (only (srfi 1) first any append! reverse! map! append-map filter)
    2528        (only utf8-srfi-13
    26           string-null? string-take string-prefix-length string-trim-both string-pad string-reverse)
     29          string-filter string-index string-null? string-take string-prefix-length
     30          string-trim-both string-pad string-reverse)
    2731        (only utf8-srfi-14 char-set:whitespace)
    2832        (only type-checks check-list check-char check-string check-fixnum))
     
    4347;;
    4448
     49(: string-unzip (string string -> (list-of string) (list-of string)))
     50(: string-zip ((list-of string) (list-of string) -> string))
     51
    4552(: string-trim-whitespace-both (string -> string))
    4653(: list-as-string (list -> string))
     
    5562(: string-longest-prefix (string (list-of string) -> (or boolean string)))
    5663(: string-longest-suffix (string (list-of string) -> (or boolean string)))
     64
     65;;
     66
     67;NOTE irregex-split doesn't preserve "missing" so punct vs parts is ambiguous
     68
     69;"..." => parts punct
     70;"a.b.c" => ("." ".") + ("a" "b" "c")
     71(define (string-unzip str punct-str)
     72  (let (
     73    (parts (string-split str punct-str #t))
     74    (punct (map string (string->list (string-filter (cut string-index punct-str <>) str)))) )
     75    (values parts punct) ) )
     76
     77;punct parts => ?
     78(define (string-zip parts punct)
     79  (let loop ((punct punct) (parts parts) (ls '()))
     80    (cond
     81      ((and (null? punct) (null? parts))
     82        (apply string-append (reverse! ls)) )
     83      ((= (length punct) (length parts))
     84        (loop (cdr punct) parts (cons (car punct) ls)) )
     85      (else
     86        (loop punct (cdr parts) (cons (car parts) ls)) ) ) ) )
    5787
    5888;;
Note: See TracChangeset for help on using the changeset viewer.