Back
blank? (clj)
(source)function
(blank? s)
True if s is nil, empty, or contains only whitespace.
Examples
clojure
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest char-sequence-handling
(are [result f args] (let [[^CharSequence s & more] args]
(= result (apply f (StringBuffer. s) more)))
"paz" s/reverse ["zap"]
"foo:bar" s/replace ["foo-bar" \- \:]
"ABC" s/replace ["abc" #"\w" s/upper-case]
"faa" s/replace ["foo" #"o" (StringBuffer. "a")]
"baz::quux" s/replace-first ["baz--quux" #"--" "::"]
"baz::quux" s/replace-first ["baz--quux" (StringBuffer. "--") (StringBuffer. "::")]
"zim-zam" s/replace-first ["zim zam" #" " (StringBuffer. "-")]
"\\\\ \\$" s/re-quote-replacement ["\\ $"]
"Pow" s/capitalize ["POW"]
"BOOM" s/upper-case ["boom"]
"whimper" s/lower-case ["whimPER"]
["foo" "bar"] s/split ["foo-bar" #"-"]
"calvino" s/trim [" calvino "]
"calvino " s/triml [" calvino "]
" calvino" s/trimr [" calvino "]
"the end" s/trim-newline ["the end\r\n\r\r\n"]
true s/blank? [" "]
["a" "b"] s/split-lines ["a\nb"]
"fa la la" s/escape ["fo lo lo" {\o \a}]))
(deftest t-blank
(is (s/blank? nil))
(is (s/blank? ""))
(is (s/blank? " "))
(is (s/blank? " \t \n \r "))
(is (not (s/blank? " foo "))))
clojure
(ns clojure.test-clojure.java.process
(:require
[clojure.test :refer :all]
[clojure.java.process :as p]
[clojure.string :as str]))
(deftest test-stderr-redirect
;; capture to stdout and return string
(is (not (str/blank? (p/exec "bash" "-c" "ls"))))
;; redirect, then capture to string
(is (not (str/blank? (p/exec {:err :stdout} "bash" "-c" "ls >&2")))))
metabase/metabase
(ns change.strict
(:require
[clojure.spec.alpha :as s]
[clojure.string :as str]
[column.strict]))
(s/def :custom-change/class (every-pred string? (complement str/blank?)))
metabase/metabase
(ns metabase-enterprise.sso.api.saml
"`/api/saml` endpoints"
(:require
[clojure.string :as str]
[compojure.core :refer [PUT]]
[metabase.api.common :as api]
[metabase.models.setting :as setting]
[metabase.public-settings.premium-features :as premium-features]
[metabase.util.i18n :refer [tru]]
[saml20-clj.core :as saml]))
(api/defendpoint PUT "/settings"
"Update SAML related settings. You must be a superuser to do this."
[:as {settings :body}]
{settings :map}
(api/check-superuser)
(premium-features/assert-has-feature :sso-saml (tru "SAML-based authentication"))
(let [filename (:saml-keystore-path settings)
password (:saml-keystore-password settings)
alias (:saml-keystore-alias settings)]
(if (or (every? str/blank? [filename password alias])
(saml/has-private-key? {:filename filename
:password password
:alias alias}))
(setting/set-many! settings)
;; test failed, return result message
{:status 400
:body "Error finding private key in provided keystore and alias."})))
logseq/logseq
(ns frontend.components.git
(:require [rum.core :as rum]
[frontend.ui :as ui]
[frontend.util :as util]
[clojure.string :as string]
[frontend.handler.shell :as shell]
[frontend.handler.file :as file]
[frontend.state :as state]))
[:div.mt-5.sm:mt-4.flex
(ui/button
"Submit"
{:on-click (fn []
(let [username @username
email @email]
(when (and (not (string/blank? username))
(not (string/blank? email)))
(shell/set-git-username-and-email username email))))})]]))
functional-koans/clojure-koans
(ns koans.02-strings
(:require [koan-engine.core :refer :all]
[clojure.string :as string]))
"Some strings may be blank"
(= __ (string/blank? ""))
"Even if at first glance they aren't"
(= __ (string/blank? " \n \t "))
"However, most strings aren't blank"
(= __ (string/blank? "hello?\nare you out there?")))
babashka/babashka
(import (java.net ServerSocket))
(require '[clojure.java.io :as io]
'[clojure.string :as string])
(with-open [server-socket (new ServerSocket 8080)
client-socket (.accept server-socket)]
(loop []
(let [out (io/writer (.getOutputStream client-socket))
in (io/reader (.getInputStream client-socket))
[req-line & _headers] (loop [headers []]
(let [line (.readLine in)]
(if (string/blank? line)
headers
(recur (conj headers line)))))
[_ _ path _] (re-find #"([^\s]+)\s([^\s]+)\s([^\s]+)" req-line)
f (io/file (format "./%s" path))
status (if (.exists f)
200
404)
html (fn html-fn [tag & body]
(let [attrs? (map? (first body))
attrs-str (str (when attrs?
(format " %s" (string/join " " (for [[k v] (first body)]
(format "%s=%s" (name k) (name v)))))))]
(format "<%s%s>%s</%s>"
(name tag)
attrs-str
(string/join (if attrs? (rest body) body))
(name tag))))
body (cond
(not (.exists f)) (str path " not exist")
(.isFile f) (slurp f)
(.isDirectory f) (format "<!DOCTYPE html>\n%s"
(html :html
(html :head
(html :title path))
(html :body
(html :h1 path)
(html :tt
(apply html :pre
(for [i (.list f)]
(html :div
(html
:a
{:href
(str (when (> (count path) 1) path) "/" i)} i)))))))))]
(prn path)
(.write out (format "HTTP/1.1 %s OK\r\nContent-Length: %s\r\n\r\n%s"
status
(count body)
body))
(.flush out))
(recur)))