Back

upper-case (clj)

(source)

function

(upper-case s)
Converts string to all upper-case.

Examples

clojure
(ns clojure.test-clojure.string
  (:require [clojure.string :as s])
  (:use clojure.test))

(deftest t-replace
  (is (= "faabar" (s/replace "foobar" \o \a)))
  (is (= "foobar" (s/replace "foobar" \z \a)))
  (is (= "barbarbar" (s/replace "foobarfoo" "foo" "bar")))
  (is (= "foobarfoo" (s/replace "foobarfoo" "baz" "bar")))
  (is (= "f$$d" (s/replace "food" "o" "$")))
  (is (= "f\\\\d" (s/replace "food" "o" "\\")))
  (is (= "barbarbar" (s/replace "foobarfoo" #"foo" "bar")))
  (is (= "foobarfoo" (s/replace "foobarfoo" #"baz" "bar")))
  (is (= "f$$d" (s/replace "food" #"o" (s/re-quote-replacement "$"))))
  (is (= "f\\\\d" (s/replace "food" #"o" (s/re-quote-replacement "\\"))))
  (is (= "FOObarFOO" (s/replace "foobarfoo" #"foo" s/upper-case)))
  (is (= "foobarfoo" (s/replace "foobarfoo" #"baz" s/upper-case)))
  (is (= "OObarOO" (s/replace "foobarfoo" #"f(o+)" (fn [[m g1]] (s/upper-case g1)))))
  (is (= "baz\\bang\\" (s/replace "bazslashbangslash" #"slash" (constantly "\\")))))

(deftest t-replace-first
  (is (= "faobar" (s/replace-first "foobar" \o \a)))
  (is (= "foobar" (s/replace-first "foobar" \z \a)))
  (is (= "z.ology" (s/replace-first "zoology" \o \.)))
  (is (= "barbarfoo" (s/replace-first "foobarfoo" "foo" "bar")))
  (is (= "foobarfoo" (s/replace-first "foobarfoo" "baz" "bar")))
  (is (= "f$od" (s/replace-first "food" "o" "$")))
  (is (= "f\\od" (s/replace-first "food" "o" "\\")))
  (is (= "barbarfoo" (s/replace-first "foobarfoo" #"foo" "bar")))
  (is (= "foobarfoo" (s/replace-first "foobarfoo" #"baz" "bar")))
  (is (= "f$od" (s/replace-first "food" #"o" (s/re-quote-replacement "$"))))
  (is (= "f\\od" (s/replace-first "food" #"o" (s/re-quote-replacement "\\"))))
  (is (= "FOObarfoo" (s/replace-first "foobarfoo" #"foo" s/upper-case)))
  (is (= "foobarfoo" (s/replace-first "foobarfoo" #"baz" s/upper-case)))
  (is (= "OObarfoo" (s/replace-first "foobarfoo" #"f(o+)" (fn [[m g1]] (s/upper-case g1)))))
  (is (= "baz\\bangslash" (s/replace-first "bazslashbangslash" #"slash" (constantly "\\")))))

(deftest t-upper-case
  (is (= "FOOBAR" (s/upper-case "Foobar"))))

(deftest nil-handling
  (are [f args] (thrown? NullPointerException (apply f args))
       s/reverse [nil]
       s/replace [nil #"foo" "bar"]
       s/replace-first [nil #"foo" "bar"]
       s/re-quote-replacement [nil]
       s/capitalize [nil]
       s/upper-case [nil]
       s/lower-case [nil]
       s/split [nil #"-"]
       s/split [nil #"-" 1]
       s/trim [nil]
       s/triml [nil]
       s/trimr [nil]
       s/trim-newline [nil]))

(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}]))
logseq/logseq
(ns frontend.components.server
  (:require
    [clojure.string :as string]
    [rum.core :as rum]
    [electron.ipc :as ipc]
    [medley.core :as medley]
    [promesa.core :as p]
    [frontend.state :as state]
    [frontend.util :as util]
    [frontend.handler.notification :as notification]
    [frontend.ui :as ui]))

             {:title   "Server configurations"
              :options {:on-click #(state/set-modal!
                                     (fn [close]
                                       (panel-of-configs close))
                                     {:center? true})}
              :icon    (ui/icon "server-cog")}])
       {:links-header
        [:div.links-header.flex.justify-center.py-2
         [:span.ml-1.text-sm
          (if-not running?
            (string/upper-case (or (:status server-state) "stopped"))
            [:a.hover:underline {:href href} href])]]})]))
xtdb/xtdb
(ns xtdb.config
  (:require [clojure.spec.alpha :as s]
            [clojure.java.io :as io]
            [clojure.edn :as edn]
            [clojure.string :as str])
  (:import java.util.Properties
           (java.io File)
           (java.nio.file Path Paths)
           (java.time Duration)
           (java.util.concurrent TimeUnit)))

(s/def ::time-unit
  (s/and (s/conformer (fn [t]
                        (cond
                          (instance? TimeUnit t) t
                          (string? t) (TimeUnit/valueOf (str/upper-case t)))))
         #(instance? TimeUnit %)))
nextjournal/clerk
(ns viewer-classes
  {:nextjournal.clerk/visibility {:code :hide}
   :nextjournal.clerk/doc-css-class [:justify-center :bg-slate-200 :dark:bg-slate-900 :py-8 :min-h-screen]}
  (:require [babashka.fs :as fs]
            [nextjournal.clerk :as clerk]
            [clojure.string :as str]))

^{::clerk/viewer clerk/table
  ::clerk/css-class [:max-w-2xl :mx-auto :bg-white :p-4 :rounded-lg :shadow-lg :mt-4]}
(def dataset
  (->> (slurp (if (fs/exists? "/usr/share/dict/words")
                "/usr/share/dict/words"
                "https://gist.githubusercontent.com/wchargin/8927565/raw/d9783627c731268fb2935a731a618aa8e95cf465/words"))
       str/split-lines
       (group-by (comp keyword str/upper-case str first))
       (into (sorted-map))))
lspector/Clojush
(ns clojush.instructions.string
  (:use [clojush pushstate globals]
        [clojure.string :only [split trim]]
        clojush.instructions.vectors)
  (:require [clojure.string :as string]))

(define-registered
  string_uppercase
  ^{:stack-types [:string]}
  (fn [state]
    (if (empty? (:string state))
      state
      (let [up (top-item :string state)]
        (->> state
             (pop-item :string)
             (push-item (string/upper-case up) :string))))))
babashka/process
;; wd - wee dummy - an os-agnostic bb script launched by our unit tests
(require '[clojure.java.io :as io]
         '[clojure.java.shell :as shell]
         '[clojure.string :as str] )

;; the naivest of cmd line parsing
(doseq [[cmd val] (partition-all 2 1 *command-line-args*)]
  (case cmd
    ":out" (println val)
    ":err" (binding [*out* *err*] (println val))
    ":ls" (pr (->> val io/file (.listFiles) (map str) sort))
    ":env" (pr (->> (System/getenv) (into {})))
    ":echo" (io/copy System/in System/out)
    ":grep" (doseq [l (->> *in* io/reader line-seq (filter #(str/includes? % val)))]
              (println l))
    ":upper" (doseq [l (->> *in* io/reader line-seq)]
               (println (str/upper-case l)))
    ;; macos and linux only
    ":ps-me" (let [pid (.pid (java.lang.ProcessHandle/current))]
               (pr {:args (-> (shell/sh "ps" "-o" "args=" (str pid)) :out str/trim)}))
    ":sleep" (Thread/sleep (parse-long val))
    ":exit" (System/exit (parse-long val))
    nil))