Back
capitalize (clj)
(source)function
(capitalize s)
Converts first character of the string to upper-case, all other
characters to lower-case.
Examples
clojure
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-capitalize
(is (= "Foobar" (s/capitalize "foobar")))
(is (= "Foobar" (s/capitalize "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.journal
(:require [clojure.string :as string]
[frontend.components.page :as page]
[frontend.components.reference :as reference]
[frontend.components.scheduled-deadlines :as scheduled]
[frontend.date :as date]
[frontend.db :as db]
[frontend.db-mixins :as db-mixins]
[frontend.db.model :as model]
[frontend.handler.page :as page-handler]
[frontend.state :as state]
[logseq.graph-parser.util :as gp-util]
[frontend.ui :as ui]
[frontend.util :as util]
[frontend.util.text :as text-util]
[goog.object :as gobj]
[reitit.frontend.easy :as rfe]
[rum.core :as rum]))
(ui/foldable
[:a.initial-color.title.journal-title
{:href (rfe/href :page {:name page})
:on-mouse-down (fn [e]
(when (util/right-click? e)
(state/set-state! :page-title/context {:page page})))
:on-click (fn [e]
(when (gobj/get e "shiftKey")
(when-let [page page-entity]
(state/sidebar-add-block!
(state/get-current-repo)
(:db/id page)
:page))
(.preventDefault e)))}
[:h1.title
(gp-util/capitalize-all title)]]
mtgred/netrunner
(ns game.cards.upgrades
(:require
[clojure.string :as str]
[cond-plus.core :refer [cond+]]
[game.core.access :refer [access-bonus set-only-card-to-access
installed-access-trigger
steal-cost-bonus]]
[game.core.bad-publicity :refer [lose-bad-publicity]]
[game.core.board :refer [all-active-installed all-installed card->server
get-remotes server->zone server-list]]
[game.core.card :refer [agenda? asset? can-be-advanced?
corp-installable-type? corp? get-card get-counters get-zone
has-subtype? ice? in-discard? in-hand? installed? operation? program? resource? rezzed?
runner? upgrade?]]
[game.core.cost-fns :refer [install-cost rez-cost]]
[game.core.costs :refer [total-available-credits]]
[game.core.damage :refer [damage]]
[game.core.def-helpers :refer [corp-rez-toast defcard offer-jack-out
reorder-choice get-x-fn]]
[game.core.drawing :refer [draw]]
[game.core.effects :refer [register-lingering-effect]]
[game.core.eid :refer [effect-completed get-ability-targets is-basic-advance-action? make-eid]]
[game.core.engine :refer [dissoc-req pay register-default-events
register-events resolve-ability unregister-events]]
[game.core.events :refer [first-event? first-run-event? turn-events]]
[game.core.expose :refer [expose-prevent]]
[game.core.finding :refer [find-cid find-latest]]
[game.core.flags :refer [clear-persistent-flag! is-scored? register-persistent-flag!
register-run-flag!]]
[game.core.gaining :refer [gain-credits lose-clicks lose-credits]]
[game.core.hand-size :refer [corp-hand-size+]]
[game.core.ice :refer [all-subs-broken? get-run-ices pump-ice resolve-subroutine!
unbroken-subroutines-choice update-all-ice update-all-icebreakers]]
[game.core.installing :refer [corp-install corp-install-list]]
[game.core.moving :refer [mill move remove-from-currently-drawing
swap-cards swap-ice trash trash-cards]]
[game.core.optional :refer [get-autoresolve set-autoresolve]]
[game.core.payment :refer [can-pay? cost-value]]
[game.core.play-instants :refer [play-instant]]
[game.core.prompts :refer [cancellable clear-wait-prompt]]
[game.core.props :refer [add-counter add-prop set-prop]]
[game.core.purging :refer [purge]]
[game.core.revealing :refer [reveal]]
[game.core.rezzing :refer [rez]]
[game.core.runs :refer [end-run force-ice-encounter jack-out redirect-run
set-next-phase start-next-phase]]
[game.core.say :refer [system-msg]]
[game.core.servers :refer [central->zone from-same-server? in-same-server?
is-central? protecting-same-server? same-server?
target-server unknown->kw zone->name]]
[game.core.shuffling :refer [shuffle!]]
[game.core.tags :refer [gain-tags]]
[game.core.threat :refer [threat-level]]
[game.core.to-string :refer [card-str]]
[game.core.toasts :refer [toast]]
[game.core.update :refer [update!]]
[game.macros :refer [continue-ability effect msg req wait-for]]
[game.utils :refer :all]
[jinteki.utils :refer :all]))
(defcard "Black Level Clearance"
{:events [{:event :successful-run
:async true
:interactive (req true)
:player :runner
:req (req this-server)
:msg (msg "force the Runner to " (decapitalize target))
:prompt "Choose one"
:waiting-prompt true
:choices ["Take 1 core damage" "Jack out"]
:effect (req (if (= target "Take 1 core damage")
(damage state :runner eid :brain 1 {:card card})
(wait-for
(jack-out state :runner (make-eid state))
(wait-for
(gain-credits state :corp 5)
(wait-for
(draw state :corp 1)
(system-msg state :corp
(str "gains 5 [Credits] and draws 1 card. "
"Black Level Clearance is trashed"))
(trash state :corp eid card {:cause-card card}))))))}]})
(defcard "Cayambe Grid"
(let [ability {:interactive (req (->> (all-installed state :corp)
(filter #(and (ice? %)
(same-server? card %)))
count
pos?))
:label "place 1 advancement counter (start of turn)"
:async true
:effect
(effect
(continue-ability
(when (->> (all-installed state :corp)
(filter #(and (ice? %)
(same-server? card %)))
count
pos?)
{:prompt (str "Place 1 advancement counter on an ice protecting " (zone->name (second (get-zone card))))
:choices {:card #(and (ice? %)
(same-server? % card))}
:msg (msg "place 1 advancement counter on " (card-str state target))
:effect (effect (add-prop target :advance-counter 1 {:placed true}))})
card nil))}]
{:events [(assoc ability :event :corp-turn-begins)
{:event :approach-server
:interactive (req true)
:req (req this-server)
:async true
:effect
(effect
(continue-ability
(let [cost (->> (get-run-ices state)
(filter #(pos? (get-counters % :advancement)))
count
(* 2))]
{:async true
:player :runner
:waiting-prompt true
:prompt "Choose one"
:choices [(when (can-pay? state :runner (assoc eid :source card :source-type :ability) card nil [:credit cost])
(str "Pay " cost " [Credits]"))
"End the run"]
:msg (msg (if (= target "End the run")
(decapitalize target)
(str "force the Runner to " (decapitalize target))))
:effect (req (if (= target "End the run")
(end-run state side eid card)
(wait-for (pay state :runner (make-eid state eid) card :credit cost)
(system-msg state :runner (:msg async-result))
(effect-completed state side eid))))})
card nil))}]
:abilities [ability]}))
(defcard "Giordano Memorial Field"
{:events [{:event :successful-run
:interactive (req true)
:async true
:req (req this-server)
:effect (effect
(continue-ability
(let [credit-cost (* 2 (count (:scored runner)))]
{:player :runner
:async true
:waiting-prompt true
:prompt "Choose one"
:choices [(when (can-pay? state :runner eid card nil :credit credit-cost)
(str "Pay " credit-cost " [Credits]"))
"End the run"]
:msg (msg (if (= "End the run" target)
(decapitalize target)
(str "force the runner to " (decapitalize target))))
:effect (req (if (= "End the run" target)
(end-run state :corp eid card)
(wait-for (pay state :runner (make-eid state eid) card :credit credit-cost)
(system-msg state :runner (:msg async-result))
(effect-completed state side eid))))})
card nil))}]})
(defcard "Increased Drop Rates"
{:flags {:rd-reveal (req true)}
:on-access {:interactive (req true)
:player :runner
:async true
:waiting-prompt true
:msg (msg (if (= target "The Corp removes 1 bad publicity")
"remove 1 bad publicity"
(str "force the Runner to " (decapitalize target))))
:prompt "Choose one"
:choices ["Take 1 tag" "The Corp removes 1 bad publicity"]
:effect (req (if (= target "Take 1 tag")
(gain-tags state side eid 1 {:unpreventable true})
(do (lose-bad-publicity state :corp 1)
(effect-completed state side eid))))}})
(defcard "K. P. Lynn"
{:events [{:event :pass-all-ice
:req (req this-server)
:player :runner
:waiting-prompt true
:prompt "Choose one"
:choices ["Take 1 tag" "End the run"]
:async true
:msg (msg (if (= target "End the run")
(decapitalize target)
(str "force the Runner to " (decapitalize target))))
:effect (req (if (= target "Take 1 tag")
(gain-tags state :runner eid 1)
(end-run state side eid card)))}]})
(defcard "Mr. Hendrik"
(installed-access-trigger
2
{:async true
;; Adding a msg to print the ability's cost
:msg "force the Runner to suffer a core damage or lose all remaining [Click]"
:effect
(effect (continue-ability {:player :runner
:prompt "Choose one"
:waiting-prompt true
:choices (req ["Suffer 1 core damage"
(when (pos? (:click runner))
"Lose all remaining [Click]")])
:async true
:msg (msg (if (= target "Suffer 1 core damage")
"do 1 core damage"
(str "force the Runner to " (decapitalize target))))
:effect (req (if (= target "Suffer 1 core damage")
(damage state :corp eid :brain 1 {:card card})
(do (lose-clicks state :runner (:click runner))
(effect-completed state side eid))))}
card nil))}))
(defcard "Tempus"
{:flags {:rd-reveal (req true)}
:on-access {:interactive (req true)
:trace {:req (req (not (in-discard? card)))
:base 3
:successful
{:waiting-prompt true
:prompt "Choose one"
:player :runner
:choices (req [(when (<= 2 (:click runner))
"Lose [Click][Click]")
"Suffer 1 core damage"])
:async true
:msg (msg "force the Runner to " (decapitalize target))
:effect (req (if (and (= target "Lose [Click][Click]")
(<= 2 (:click runner)))
(do (lose-clicks state :runner 2)
(effect-completed state side eid))
(damage state side eid :brain 1 {:card card})))}}}})
(defcard "Tranquility Home Grid"
{:install-req (req (remove #{"HQ" "R&D" "Archives"} targets))
:events [{:event :corp-install
:interactive (req true)
:req (req (and (or (asset? (:card context))
(agenda? (:card context))
(upgrade? (:card context)))
(in-same-server? card (:card context))
(first-event? state :corp :corp-install #(in-same-server? card (:card (first %))))))
:prompt "Choose one"
:waiting-prompt true
:choices ["Gain 2 [Credits]" "Draw 1 card"]
:msg (msg (decapitalize target))
:async true
:effect (req (if (= target "Gain 2 [Credits]")
(gain-credits state side eid 2)
(draw state side eid 1)))}]})
mtgred/netrunner
(ns game.cards.hardware
(:require
[clojure.set :as set]
[clojure.string :as str]
[game.core.access :refer [access-bonus access-card breach-server
get-only-card-to-access]]
[game.core.actions :refer [play-ability]]
[game.core.board :refer [all-active all-active-installed all-installed]]
[game.core.card :refer [active? corp? event? facedown? get-card get-counters get-title
get-zone hardware? has-subtype? ice? in-deck? in-discard?
in-hand? in-scored? installed? program? resource? rezzed?
runner? virus-program? faceup?]]
[game.core.card-defs :refer [card-def]]
[game.core.cost-fns :refer [all-stealth install-cost
rez-additional-cost-bonus rez-cost trash-cost]]
[game.core.damage :refer [chosen-damage damage damage-prevent
enable-runner-damage-choice runner-can-choose-damage?]]
[game.core.def-helpers :refer [breach-access-bonus defcard offer-jack-out
reorder-choice trash-on-empty get-x-fn]]
[game.core.drawing :refer [draw]]
[game.core.effects :refer [register-lingering-effect
unregister-effects-for-card unregister-lingering-effects]]
[game.core.eid :refer [effect-completed make-eid make-result]]
[game.core.engine :refer [can-trigger? not-used-once? register-events
register-once register-suppress resolve-ability trigger-event
unregister-floating-events unregister-suppress-by-uuid]]
[game.core.events :refer [event-count first-event? first-trash? no-event?
run-events]]
[game.core.expose :refer [expose]]
[game.core.finding :refer [find-card find-latest]]
[game.core.flags :refer [can-trash? card-flag? in-corp-scored? register-run-flag!
zone-locked?]]
[game.core.gaining :refer [gain-clicks gain-credits lose-clicks
lose-credits]]
[game.core.hand-size :refer [hand-size runner-hand-size+]]
[game.core.hosting :refer [host]]
[game.core.ice :refer [all-subs-broken? any-subs-broken? break-sub pump
reset-all-ice update-all-ice update-all-icebreakers
update-breaker-strength]]
[game.core.installing :refer [runner-can-install? runner-can-pay-and-install? runner-install]]
[game.core.link :refer [get-link link+]]
[game.core.memory :refer [caissa-mu+ mu+ update-mu virus-mu+]]
[game.core.moving :refer [mill move swap-agendas trash trash-cards]]
[game.core.optional :refer [get-autoresolve never? set-autoresolve]]
[game.core.payment :refer [build-cost-string can-pay? cost-value]]
[game.core.play-instants :refer [play-instant]]
[game.core.prompts :refer [cancellable clear-wait-prompt]]
[game.core.props :refer [add-counter add-icon remove-icon]]
[game.core.revealing :refer [reveal]]
[game.core.rezzing :refer [derez rez]]
[game.core.runs :refer [bypass-ice end-run end-run-prevent
get-current-encounter jack-out make-run
successful-run-replace-breach total-cards-accessed]]
[game.core.say :refer [system-msg]]
[game.core.servers :refer [target-server is-central?]]
[game.core.shuffling :refer [shuffle!]]
[game.core.tags :refer [gain-tags lose-tags tag-prevent]]
[game.core.to-string :refer [card-str]]
[game.core.toasts :refer [toast]]
[game.core.update :refer [update!]]
[game.core.virus :refer [count-virus-programs number-of-virus-counters]]
[game.macros :refer [continue-ability effect msg req wait-for]]
[game.utils :refer :all]
[jinteki.utils :refer :all]
[game.core.set-aside :refer [set-aside get-set-aside]]
[game.core.sabotage :refer [sabotage-ability]]
[game.core.mark :refer [identify-mark-ability]]))
(defcard "Blackguard"
{:static-abilities [(mu+ 2)]
:events [{:event :expose
:msg (msg "attempt to force the rez of " (:title target))
:async true
:effect (req (let [c target
cname (:title c)
cost (rez-cost state side target)
additional-costs (rez-additional-cost-bonus state side target)]
(if (seq additional-costs)
(continue-ability
state side
{:optional
{:waiting-prompt true
:prompt (msg (build-cost-string [:credit cost])
", plus " (decapitalize (build-cost-string additional-costs))
" as an additional cost to rez " cname "?")
:player :corp
:yes-ability {:async true
:effect (effect (rez :corp eid c))}
:no-ability {:msg (msg "declines to pay additional costs"
" and is not forced to rez " cname)}}}
card nil)
(rez state :corp eid target))))}]})
(defcard "Chop Bot 3000"
(let [ability {:req (req (>= (count (all-installed state :runner)) 2))
:label "Trash another installed card to draw 1 card or remove 1 tag"
:once :per-turn
:choices {:card #(and (runner? %)
(installed? %))
:not-self true}
:async true
:effect (req (wait-for (trash state :runner target {:unpreventable true :cause-card card})
(continue-ability
state side
(let [trashed-card target
tags (pos? (count-real-tags state))]
{:prompt "Choose one"
:waiting-prompt true
:choices ["Draw 1 card"
(when tags "Remove 1 tag")]
:async true
:msg (msg "trash " (:title trashed-card) " and " (decapitalize target))
:effect (req (if (= target "Draw 1 card")
(draw state :runner eid 1)
(lose-tags state :runner eid 1)))})
card nil)))}]
{:flags {:runner-phase-12 (req (>= (count (all-installed state :runner)) 2))}
:events [(assoc ability
:event :runner-turn-begins
:interactive (req true))]
:abilities [ability]}))
hraberg/deuce
(ns deuce.emacs.casefiddle
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[clojure.string :as s])
(:refer-clojure :exclude []))
(defun upcase-word (arg)
"Convert following word (or ARG words) to upper case, moving over.
With negative argument, convert previous words but do not move.
See also `capitalize-word'."
(interactive "p"))
(defun upcase (obj)
"Convert argument to upper case and return that.
The argument may be a character or string. The result has the same type.
The argument object is not altered--the value is a copy.
See also `capitalize', `downcase' and `upcase-initials'."
(if ((some-fn char? integer?) obj)
(int (Character/toUpperCase (int obj)))
(s/upper-case obj)))
(defun capitalize-word (arg)
"Capitalize the following word (or ARG words), moving over.
This gives the word(s) a first character in upper case
and the rest lower case.
With negative argument, capitalize previous words but do not move."
(interactive "p"))
(defun capitalize-region (beg end)
"Convert the region to capitalized form.
Capitalized form means each word's first character is upper case
and the rest of it is lower case.
In programs, give two arguments, the starting and ending
character positions to operate on."
(interactive "r"))
(defun upcase-region (beg end)
"Convert the region to upper case. In programs, wants two arguments.
These arguments specify the starting and ending character numbers of
the region to operate on. When used as a command, the text between
point and the mark is operated on.
See also `capitalize-region'."
(interactive "r"))
(defun capitalize (obj)
"Convert argument to capitalized form and return that.
This means that each word's first character is upper case
and the rest is lower case.
The argument may be a character or string. The result has the same type.
The argument object is not altered--the value is a copy."
(s/capitalize obj))
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_capitalize
^{:stack-types [:string]}
(fn [state]
(if (empty? (:string state))
state
(let [cap (top-item :string state)]
(->> state
(pop-item :string)
(push-item (string/capitalize cap) :string))))))