From d3fed5aff6ebd29e5dff8e528461b666f9b468cc Mon Sep 17 00:00:00 2001 From: cage Date: Sun, 13 Oct 2024 12:24:10 +0200 Subject: [PATCH] - made optional character '#' when specifying a starting folder from command line (option '-f'). --- src/command-line.lisp | 2 ++ src/db.lisp | 9 +++++++++ src/message-rendering-utils.lisp | 11 +++-------- src/package.lisp | 8 +++++++- src/text-utils.lisp | 17 +++++++++++++---- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/command-line.lisp b/src/command-line.lisp index fde5dc2..c4bdc26 100644 --- a/src/command-line.lisp +++ b/src/command-line.lisp @@ -222,6 +222,8 @@ (set-option-variable options :gemini-gui-server *rpc-server-mode*) (set-option-variable options :gemini-gui *rpc-client-mode*) (set-option-variable options :folder *start-folder*) + (when (string-not-empty-p *start-folder*) + (setf *start-folder* (db:add-folder-prefix *start-folder*))) (set-option-variable options :open-net-address *net-address*) (set-option-variable options :timeline *start-timeline*) (set-option-variable options :reset-timeline-pagination *reset-timeline-pagination*) diff --git a/src/db.lisp b/src/db.lisp index 3166fc3..7c4012e 100644 --- a/src/db.lisp +++ b/src/db.lisp @@ -3527,3 +3527,12 @@ Note: `status-id' must identify at least a row in the database." (progn (db:update-db (api-client:get-remote-status parent-id)) (get-cache parent-id)))))) + +(defun has-folder-prefix-p (string) + (starts-with-prefix-p +folder-tag-prefix+ string)) + +(defun add-folder-prefix (folder-name) + (add-prefix-once +folder-tag-prefix+ folder-name)) + +(defun strip-folder-prefix (maybe-folder) + (strip-prefix +folder-tag-prefix+ maybe-folder)) diff --git a/src/message-rendering-utils.lisp b/src/message-rendering-utils.lisp index 59bd7dc..31ce093 100644 --- a/src/message-rendering-utils.lisp +++ b/src/message-rendering-utils.lisp @@ -19,18 +19,13 @@ (define-constant +temp-mention-prefix+ "/at/" :test #'string=) (defun mention-p (maybe-mention) - (scan (strcat "^" +mention-prefix+) - maybe-mention)) + (starts-with-prefix-p +mention-prefix+ maybe-mention)) (defun add-mention-prefix (username) - (if (mention-p username) - username - (strcat +mention-prefix+ username))) + (add-prefix-once +mention-prefix+ username)) (defun strip-mention-prefix (maybe-mention) - (if (not (mention-p maybe-mention)) - maybe-mention - (subseq maybe-mention (length +mention-prefix+)))) + (strip-prefix +mention-prefix+ maybe-mention)) (defun find-first-mention-in-message (message-body) (when message-body diff --git a/src/package.lisp b/src/package.lisp index 18ffe5a..73b4998 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -455,6 +455,9 @@ :+integer-regexp+ :*blanks* :uchar-length + :starts-with-prefix-p + :strip-prefix + :add-prefix-once :utf8-encoded-p :clean-unprintable-chars :to-s @@ -1205,7 +1208,10 @@ :gempub-metadata-find :gempub-metadata-id->path :gempub-metadata-id->row - :get-parent-status-row)) + :get-parent-status-row + :has-folder-prefix-p + :add-folder-prefix + :strip-folder-prefix)) (defpackage :date-formatter (:use diff --git a/src/text-utils.lisp b/src/text-utils.lisp index 681d4ac..cd044f8 100644 --- a/src/text-utils.lisp +++ b/src/text-utils.lisp @@ -38,6 +38,19 @@ (a:define-constant +integer-regexp+ "0|[1-9][0-9]+|[1-9]" :test 'string=) +(defun starts-with-prefix-p (prefix string) + (cl-ppcre:scan (strcat "^" prefix) string)) + +(defun strip-prefix (prefix string) + (if (starts-with-prefix-p prefix string) + (subseq string (length prefix)) + string)) + +(defun add-prefix-once (prefix string) + (if (starts-with-prefix-p prefix string) + string + (strcat prefix string))) + (defun uchar-length (leading-byte) (let ((ones (do* ((ct 7 (1- ct)) (bit (ldb (byte 1 ct) leading-byte) @@ -110,10 +123,6 @@ (declare (optimize (debug 0) (safety 0) (speed 3))) (reduce (lambda (a b) (concatenate 'string a b)) chunks)) -(defun strip-prefix (string prefix) - (let ((re (strcat "^" prefix))) - (cl-ppcre:regex-replace re string ""))) - (defun strip-withespaces (string) (let ((re "\\s")) (cl-ppcre:regex-replace re string "")))