From 942c6d754985ae15b519570cc003156c425f328a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 29 Oct 2018 11:07:37 -0700 Subject: [PATCH] neater --- sugar/file.rkt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sugar/file.rkt b/sugar/file.rkt index f3d1251..a6cac19 100644 --- a/sugar/file.rkt +++ b/sugar/file.rkt @@ -8,10 +8,12 @@ ;; this is identical to `filename-extension` in `racket/path` ;; but will not treat hidden files as an extension (which is a bug) (define (filename-extension name) - (define filename (file-name-from-path name)) - (define bytes (and filename (path->bytes filename))) - (match (and bytes (regexp-match #rx#".[.]([^.]+)$" bytes)) - [(list _ second) second] + (match (file-name-from-path name) + [(? path-for-some-system? filename) + (=> resume) + (match (regexp-match #rx#".[.]([^.]+)$" (path->bytes filename)) + [(list _ second) second] + [_ (resume)])] [_ #false])) (module+ test @@ -52,7 +54,7 @@ (raise-argument-error 'has-binary-ext? "pathish?" x)) (for/or ([ext (in-list binary-extensions)] #:when (has-ext? (->path x) ext)) - #true)) + #true)) ;; put extension on path ;; use local contract here because this function is used within module