Back

escape (clj)

(source)

function

(escape s cmap)
Return a new string, using cmap to escape each character ch from s as follows: If (cmap ch) is nil, append ch to the new string. If (cmap ch) is non-nil, append (str (cmap ch)) instead.

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-escape
  (is (= "<foo&bar>"
         (s/escape "<foo&bar>" {\& "&amp;" \< "&lt;" \> "&gt;"})))
  (is (= " \\\"foo\\\" "
         (s/escape " \"foo\" " {\" "\\\""})))
  (is (= "faabor"
         (s/escape "foobar" {\a \o, \o \a}))))
metabase/metabase
  TODO -- since this is no longer strictly a 'util' namespace (most `:sql-jdbc` drivers need to implement one or
  methods from here) let's rename this `metabase.driver.sql.unprepare` when we get a chance."
  (:require
   [clojure.string :as str]
   [java-time.api :as t]
   [metabase.driver :as driver]
   [metabase.driver.sql.util :as sql.u]
   [metabase.util :as u]
   [metabase.util.i18n :refer [trs]]
   [metabase.util.log :as log])
  (:import
   (java.time Instant LocalDate LocalDateTime LocalTime OffsetDateTime OffsetTime ZonedDateTime)))

(defmethod unprepare-value [:sql String]
  [_ s]
  ;; escape single-quotes like Cam's String -> Cam''s String
  (str \' (sql.u/escape-sql s :ansi) \'))
pallet/pallet
(ns pallet.crate.etc-default
  "Generation and installation of /etc/default-style files."
  (:require
   [clojure.string :as string]
   [pallet.actions :refer [remote-file]]
   [pallet.crate :refer [defplan]]
   [pallet.script.lib :as lib]
   [pallet.stevedore :as stevedore]
   [pallet.stevedore :refer [with-source-line-comments]]
   [pallet.utils :refer [apply-map]]))

(defplan write
  "Writes a KEY=value file to /etc/default/~{filename}, or ~{filename} if
   filename starts with a /.  Note that all values are quoted, and quotes in
   values are escaped, but otherwise, values are written literally.

(defplan write-opts
  "Writes a KEY=value file to /etc/default/~{filename}, or ~{filename} if
   filename starts with a /.  Note that all values are quoted, and quotes in
   values are escaped, but otherwise, values are written literally.
hraberg/deuce
(ns deuce.emacs.print
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c]
            [clojure.string :as s]
            [deuce.emacs.buffer :as buffer]
            [deuce.emacs.data :as data]
            [deuce.emacs.editfns :as editfns]
            [deuce.emacs.fns :as fns])
  (:refer-clojure :exclude [print]))

(defvar print-escape-multibyte nil
  "Non-nil means print multibyte characters in strings as \\xXXXX.
  (XXXX is the hex representation of the character code.)
  This affects only `prin1'.")

(defvar print-escape-newlines nil
  "Non-nil means print newlines in strings as `\\n'.
  Also print formfeeds as `\\f'.")

(defvar print-escape-nonascii nil
  "Non-nil means print unibyte non-ASCII chars in strings as \\OOO.
  (OOO is the octal representation of the character code.)
  Only single-byte characters are affected, and only in `prin1'.
  When the output goes in a multibyte buffer, this feature is
  enabled regardless of the value of the variable.")

(defun prin1-to-string (object &optional noescape)
  "Return a string containing the printed representation of OBJECT.
  OBJECT can be any Lisp object.  This function outputs quoting characters
  when necessary to make output that `read' can handle, whenever possible,
  unless the optional second argument NOESCAPE is non-nil.  For complex objects,
  the behavior is controlled by `print-level' and `print-length', which see.
Cirru/calcit-editor

(ns app.comp.abstract
  (:require [clojure.string :as string]
            [hsl.core :refer [hsl]]
            [respo-ui.core :as ui]
            [respo.core :refer [defcomp <> span div pre input button a]]
            [respo.comp.inspect :refer [comp-inspect]]
            [respo.comp.space :refer [=<]]
            [app.style :as style]
            [app.comp.modal :refer [comp-modal]]
            [keycode.core :as keycode]))

(defcomp
 comp-abstract
 (states close-modal!)
 (comp-modal
  close-modal!
  (let [cursor (:cursor states), state (or (:data states) "style-")]
    (div
     {}
     (input
      {:style style/input,
       :class-name "el-abstract",
       :value state,
       :on-input (fn [e d!] (d! cursor (:value e))),
       :on-keydown (fn [e d!]
         (cond
           (= keycode/return (:key-code e))
             (if (not (string/blank? state))
               (do (d! :analyze/abstract-def state) (d! cursor nil) (close-modal! d!)))
           (= (:keycode e) keycode/escape) (close-modal! d!)))})
     (=< nil 8)
     (button
      {:style style/button,
       :inner-text "Submit",
       :on-click (fn [e d!]
         (if (not (string/blank? state))
           (do (d! :analyze/abstract-def state) (d! cursor nil) (close-modal! d!))))})))))
green-coder/girouette
(ns ^:no-doc girouette.tw.transform
  (:require [clojure.string :as str]
            [girouette.tw.common :refer [value-unit->css div-100 div-4 mul-100]]))


   {:id :transform-origin
    :since-version [:tw 2]
    :rules  "
    transform-origin = <'origin-'> ('top-left'| 'top' | 'top-right' |
                                    'left' | 'center' | 'right' |
                                    'bottom-left' | 'bottom' | 'bottom-right')
    "
    :garden (fn [{[direction] :component-data}]
              {:transform-origin (str/escape direction {\- \space})})}