diff options
author | Rahguzar <rahguzar@zohomail.eu> | 2024-01-05 22:09:27 +0100 |
---|---|---|
committer | Rahguzar <rahguzar@zohomail.eu> | 2024-01-06 11:51:13 +0100 |
commit | 4a8a102b3b4f8483af5b688e7ea480ff6b8dc2ed (patch) | |
tree | 730ad451540b0c2e79fbdf268cf4994bfb2563cb /lisp/mastodon-toot.el | |
parent | 6fc44fe225ad229500509af6a985f58c6805481d (diff) |
Count characters directly from string
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r-- | lisp/mastodon-toot.el | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index f60f314..51990fd 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1669,20 +1669,13 @@ REPLY-REGION is a string to be injected into the buffer." URLs always = 23, and domain names of handles are not counted. This is how mastodon does it. CW is the content warning, which contributes to the character count." - (with-temp-buffer - (switch-to-buffer (current-buffer)) - (insert toot-string) - (goto-char (point-min)) - ;; handle URLs - (while (search-forward-regexp mastodon-toot-url-regex nil t) - ; "\\w+://[^ \n]*" old regex - (replace-match "xxxxxxxxxxxxxxxxxxxxxxx")) ; 23 x's - ;; handle @handles - (goto-char (point-min)) - (while (search-forward-regexp mastodon-toot-handle-regex nil t) - (replace-match (match-string 2))) ; replace with handle only + (let* ((url-replacement (make-string 23 ?x)) + (count-str (replace-regexp-in-string ; handle @handles + mastodon-toot-handle-regex "\2" + (replace-regexp-in-string ; handle URLs + mastodon-toot-url-regex url-replacement toot-string)))) (+ (length cw) - (length (buffer-substring (point-min) (point-max)))))) + (length count-str)))) ;;; DRAFTS |