diff options
Diffstat (limited to 'src/cljcc/util.clj')
| -rw-r--r-- | src/cljcc/util.clj | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cljcc/util.clj b/src/cljcc/util.clj index 7f59407..351b11f 100644 --- a/src/cljcc/util.clj +++ b/src/cljcc/util.clj @@ -87,19 +87,32 @@ (defn matches-regex [re s] (not (nil? (re-matches re s)))) +(def unsigned-long-re-without-wordbreak #"[0-9]+([lL][uU]|[uU][lL])") +(def signed-long-re-without-wordbreak #"[0-9]+[lL]") +(def unsigned-int-re-without-wordbreak #"[0-9]+[uU]") +(def signed-int-re-without-wordbreak #"[0-9]+") +(def floating-point-constant-without-wordbreak #"([0-9]*\.[0-9]+|[0-9]+\.?)[Ee][+-]?[0-9]+|[0-9]*\.[0-9]+|[0-9]+\.") + (def unsigned-long-re #"([0-9]+([lL][uU]|[uU][lL]))[^\w.]") (def signed-long-re #"([0-9]+[lL])[^\w.]") (def unsigned-int-re #"([0-9]+[uU])[^\w.]") (def signed-int-re #"([0-9]+)[^\w.]") (def floating-point-constant #"(([0-9]*\.[0-9]+|[0-9]+\.?)[Ee][+-]?[0-9]+|[0-9]*\.[0-9]+|[0-9]+\.)[^\w.]") +(defn- re-find-indexed [re s] + (let [matcher (re-matcher re s)] + (when (.find matcher) + [(.group matcher 1) + (.start matcher 1) + (.end matcher 1)]))) + (defn match-regex "Returns matched string and remaining string tuple, otherwise returns nil. The first match by re-finds must be the starting subsequence, otherwise false." [re s] - (when-let [matched (second (re-find re s))] - (when (str/starts-with? s matched) + (when-let [[matched start-index _] (re-find-indexed re s)] + (when (and (= 0 start-index) (str/starts-with? s matched)) [matched (str/replace-first s matched "")]))) (defn read-number |
