Changeset 39830 in project


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

add semantic-version & support

Location:
release/5/string-utils/trunk
Files:
1 added
3 edited

Legend:

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

    r39822 r39830  
    1010 (test-dependencies test)
    1111 (components
     12  (extension semantic-version
     13    (types-file)
     14    (component-dependencies string-interpolator string-interpolation-syntax)
     15    (csc-options "-O3" "-d1" "-strict-types" "-no-procedure-checks-for-toplevel-bindings") )
    1216  (extension string-interpolation-syntax
    1317    (types-file)
  • 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;;
  • release/5/string-utils/trunk/tests/string-utils-test.scm

    r39544 r39830  
    132132  (test "fooba" (string-longest-common-prefix '("foobaz" "foobar")))
    133133  (test "foo" (string-longest-common-suffix '("bazfoo" "barfoo")))
     134
     135  (test '(("a" "b" "c") ("." ",")) (receive (string-unzip "a.b,c" ",.")))
     136  (test "a.b,c" (string-zip '("a" "b" "c") '("." ",")))
     137)
     138
     139;;
     140
     141(import semantic-version)
     142
     143(test-group "semantic-version"
     144
     145  (test-assert (version-valid? '("a" "b" "c") '("." ",")))
     146  (test '(("a" "b" "c") ("." ",")) (receive (version-split "a.b,c" )))
     147  (test "a.b,c" (version-combine '("a" "b" "c") '("." ",")))
     148
     149  (test '("a" "1" "b") (version-inc '("a" "2" "b") 1 -1))
     150  (test '("1" "2" "4") (version-inc '("1" "2" "3")))
    134151)
    135152
Note: See TracChangeset for help on using the changeset viewer.