Permalink
Browse files
Remove a bunch of redundant utils functions.
- Loading branch information...
|
|
@@ -1,18 +1,19 @@ |
|
|
(ns clj-stacktrace.core
|
|
|
- (:require [clj-stacktrace.utils :as utils]))
|
|
|
+ (:require [clojure.string :as string]))
|
|
|
|
|
|
(defn- clojure-code?
|
|
|
"Returns true if the filename is non-null and indicates a clj source file."
|
|
|
[class-name file]
|
|
|
- (or (utils/re-match? #"^user" class-name)
|
|
|
+ (or (re-find #"^user" class-name)
|
|
|
(= file "NO_SOURCE_FILE")
|
|
|
- (and file (utils/re-match? #"\.clj$" file))))
|
|
|
+ (and file (re-find #"\.clj$" file))))
|
|
|
|
|
|
(defn- clojure-ns
|
|
|
"Returns the clojure namespace name implied by the bytecode class name."
|
|
|
[class-name]
|
|
|
- (utils/re-gsub #"_" "-" (or (utils/re-get #"([^$]+)\$" class-name 1)
|
|
|
- (utils/re-get #"(.+)\.[^.]+$" class-name 1))))
|
|
|
+ (string/replace (or (get (re-find #"([^$]+)\$" class-name) 1)
|
|
|
+ (get (re-find #"(.+)\.[^.]+$" class-name) 1))
|
|
|
+ #"_" "-"))
|
|
|
|
|
|
;; drop everything before and including the first $
|
|
|
;; drop everything after and including and the second $
|
|
|
@@ -36,14 +37,14 @@ |
|
|
"Returns the clojure function name implied by the bytecode class name."
|
|
|
[class-name]
|
|
|
(reduce
|
|
|
- (fn [base-name [pattern sub]] (utils/re-gsub pattern sub base-name))
|
|
|
+ (fn [base-name [pattern sub]] (string/replace base-name pattern sub))
|
|
|
class-name
|
|
|
clojure-fn-subs))
|
|
|
|
|
|
(defn- clojure-anon-fn?
|
|
|
"Returns true if the bytecode class name implies an anonymous inner fn."
|
|
|
[class-name]
|
|
|
- (utils/re-match? #"\$.*\$" class-name))
|
|
|
+ (boolean (re-find #"\$.*\$" class-name)))
|
|
|
|
|
|
(defn parse-trace-elem
|
|
|
"Returns a map of information about the java trace element.
|
|
|
|
|
|
@@ -25,12 +25,12 @@ |
|
|
:magenta Anything else - i.e. Clojure libraries and app code."
|
|
|
[elem]
|
|
|
(if (:java elem)
|
|
|
- (if (utils/re-match? #"^clojure\." (:class elem))
|
|
|
+ (if (re-find #"^clojure\." (:class elem))
|
|
|
:cyan
|
|
|
:blue)
|
|
|
(cond (nil? (:ns elem)) :yellow
|
|
|
- (utils/re-match? #"^(user|repl)" (:ns elem)) :yellow
|
|
|
- (utils/re-match? #"^clojure\." (:ns elem)) :magenta
|
|
|
+ (re-find #"^(user|repl)" (:ns elem)) :yellow
|
|
|
+ (re-find #"^clojure\." (:ns elem)) :magenta
|
|
|
:user-code :green)))
|
|
|
|
|
|
(defn source-str [parsed]
|
|
|
|
|
|
@@ -1,38 +1,5 @@ |
|
|
(ns clj-stacktrace.utils)
|
|
|
|
|
|
-(defn re-gsub
|
|
|
- "Simple version of re-gsub that only supports string replacements."
|
|
|
- [^java.util.regex.Pattern regex replacement ^String string]
|
|
|
- (.. regex (matcher string) (replaceAll replacement)))
|
|
|
-
|
|
|
-(defn re-without
|
|
|
- "Returns a String with the given pattern re-gsub'd out the given string."
|
|
|
- [pattern string]
|
|
|
- (re-gsub pattern "" string))
|
|
|
-
|
|
|
-(defn re-match?
|
|
|
- "Returns true iff the given string contains a match for the given pattern."
|
|
|
- [^java.util.regex.Pattern pattern string]
|
|
|
- (.find (.matcher pattern string)))
|
|
|
-
|
|
|
-(defn re-get
|
|
|
- "Returns the nth captured group resulting from matching the given pattern
|
|
|
- against the given string, or nil if no match is found."
|
|
|
- [re s n]
|
|
|
- (let [m (re-matcher re s)]
|
|
|
- (if (.find m)
|
|
|
- (.group m n))))
|
|
|
-
|
|
|
-(defn high
|
|
|
- "Like max, but for collections."
|
|
|
- [vals]
|
|
|
- (apply max vals))
|
|
|
-
|
|
|
-(defn zip
|
|
|
- "Zip collections into tuples."
|
|
|
- [& colls]
|
|
|
- (apply map list colls))
|
|
|
-
|
|
|
(defn rjust
|
|
|
"If width is greater than the length of s, returns a new string
|
|
|
of length width with s right justified within it, otherwise returns s."
|
|
|
|
0 comments on commit
35fa30d