Skip to content

Commit

Permalink
complete 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bacarella committed Dec 21, 2011
1 parent 3897544 commit 692f67b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions 1_strings.clj
Original file line number Diff line number Diff line change
Expand Up @@ -571,19 +571,34 @@
(printf "%s\n" (unexpand line)))))
;; -----------------------------

;; 1.8 Expanding and Compressing Tabs
;; @@PLEAC@@_1.8 Expanding and Compressing Tabs

(ns pleac-example-1-8
[:require [clojure.contrib [str-utils2 :as s]]])

(defn expand-tabs [string & num-spaces]
(let [num-spaces (or (first num-spaces) 8)
pattern #"\t"
replacement (apply str (repeat num-spaces " "))]
(s/replace string pattern replacement)))

(defn compress-tabs [string & num-spaces]
(let [num-spaces (or (first num-spaces) 8)
pattern (apply str (repeat num-spaces " "))
replacement "\t"]
(s/replace string pattern replacement)))

;; 1.9 Expanding Variables in User Input

;; @@PLEAC@@_1.10 Controlling Case

(.toUpperCase "foo") ;; -> "FOO"
(.toLowerCase "FOO") ;; -> "foo"

;; 1.11 Interpolating Functions and Expressions Within Strings

;; @@PLEAC@@_1.12 Indenting Here Documents

@@INCOMPLETE@@
(ns pleac-example-1-12
[:require [clojure.contrib [str-utils2 :as s]]])
(def var
Expand All @@ -592,6 +607,8 @@
goes here
" re "\n")))
@@INCOMPLETE@@
;; 1.13 Reformatting Paragraphs
;; 1.14 Escaping Characters
Expand Down Expand Up @@ -619,3 +636,10 @@
;; -----------------------------
;; 1.16 Parsing Comma-Separated Data
(ns pleac-example-1-16)
;; 1.17 Soundex Matching
;; 1.18 Program: fixstyle
;; 1.19 Program: psgrep

0 comments on commit 692f67b

Please sign in to comment.