summaryrefslogtreecommitdiff
path: root/s.el
diff options
context:
space:
mode:
authorexpez <expez@expez.com>2013-12-23 15:08:31 +0100
committerexpez <expez@expez.com>2013-12-23 15:08:31 +0100
commit6d572325e705e3011c444a659890ca3520fba545 (patch)
treeb3db36a9d6b18fa102b35453695ab2f4587376dd /s.el
parentcdd0a24e8d5fa4d55f3e07f829bface0407c0adb (diff)
Add s-count-matches
s-count-matches does the same as count-matches, but instead of counting occurrences of regexp following point it takes a string argument.
Diffstat (limited to 's.el')
-rw-r--r--s.el12
1 files changed, 11 insertions, 1 deletions
diff --git a/s.el b/s.el
index b3c8840..0636596 100644
--- a/s.el
+++ b/s.el
@@ -367,7 +367,7 @@ Each element itself is a list of matches, as per
`match-string'. Multiple matches at the same position will be
ignored after the first."
(let ((all-strings ())
- (i 0))
+ (i 0))
(while (and (< i (length string))
(string-match regex string i))
(setq i (1+ (match-beginning 0)))
@@ -542,5 +542,15 @@ the variable `s-lex-value-as-lisp' is `t' and then they are
interpolated with \"%S\"."
(s-lex-fmt|expand format-str))
+(defun s-count-matches (regexp s &optional start end)
+ "Count occurrences of `regexp' in `s'.
+
+`start', inclusive, and `end', exclusive, delimit the part of `s'
+to match. "
+ (with-temp-buffer
+ (insert s)
+ (goto-char (point-min))
+ (count-matches regexp (or start 1) (or end (point-max)))))
+
(provide 's)
;;; s.el ends here