32 lines
670 B
Racket
32 lines
670 B
Racket
#lang racket/base
|
|
|
|
(require net/url)
|
|
|
|
(provide input-prompt
|
|
valid-http-or-file-url?
|
|
)
|
|
|
|
(define (input-prompt p #:loop-until [until (λ (x) x)])
|
|
(let loop ()
|
|
(display p)
|
|
(flush-output)
|
|
(let ((inp (read-line)))
|
|
(let ((i (until inp)))
|
|
(if i
|
|
i
|
|
(loop)))
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
|
|
(define (valid-http-or-file-url? value)
|
|
(if (not (string? value))
|
|
#f
|
|
(with-handlers ([exn:fail? (λ (exn) #f)])
|
|
(let ((url (string->url value)))
|
|
(and
|
|
(member (url-scheme url) '("http" "https" "file"))
|
|
(string? (url-host url))
|
|
(not (string=? (url-host url) ""))))))) |