diff --git a/src/gemini/gemini-parser.lisp b/src/gemini/gemini-parser.lisp index 54fe2b2..4f5aadd 100644 --- a/src/gemini/gemini-parser.lisp +++ b/src/gemini/gemini-parser.lisp @@ -405,6 +405,9 @@ :initarg :source-line-id :accessor source-line-id))) +(defmethod print-object ((object with-raw-text) stream) + (format stream "sid: ~a raw-text: ~a" (source-line-id object) (raw-text object))) + (defclass with-group-id () ((group-id :initform nil diff --git a/src/package.lisp b/src/package.lisp index cad2525..73a794a 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -403,6 +403,7 @@ :maybe-percent-encode :display-corrupting-utf8-p :remove-corrupting-utf8-chars + :match-words :emojip :starting-emoji)) diff --git a/src/tests/text-utils-tests.lisp b/src/tests/text-utils-tests.lisp index 120dab3..06d3998 100644 --- a/src/tests/text-utils-tests.lisp +++ b/src/tests/text-utils-tests.lisp @@ -45,3 +45,12 @@ '(((((:a . "1") (:b . "12") (:c . "1")) ((:a . "2") (:b . "3") (:c . "4 "))) (((:a . " 5") (:b . "6") (:c . "7")) ((:padding . " "))))) :test #'string=))) + +(deftest match-words (text-utils-suite) + (assert-true (match-words '("a" "b" "c") '("a" "b" "c"))) + (assert-true (match-words '("a" "b" "c" "d") '("a" "b" "c"))) + (assert-true (match-words '("a" "foo" "bar" "d") '("foo" "bar"))) + (assert-true (match-words '("a" "b" "c" "d") '("c" "d"))) + (assert-false (match-words '("a" "b" "c" "d") '("b" "a"))) + (assert-false (match-words '("a" "b" "c" "d") '("a" "b" "x"))) + (assert-false (match-words '("a" "b" "c" "d") '("a" "b" "c" "d" "e")))) diff --git a/src/text-utils.lisp b/src/text-utils.lisp index 51aa2f1..db7a26d 100644 --- a/src/text-utils.lisp +++ b/src/text-utils.lisp @@ -759,3 +759,12 @@ printed in the box column by column; in the example above the results are: (defmethod remove-corrupting-utf8-chars ((object sequence)) (remove-if #'display-corrupting-utf8-p object)) + +(defun match-words (words probe &optional (test #'string=)) + (loop for start-words = words then (rest start-words) + while start-words do + (if (<= (length probe) + (length start-words)) + (let ((slice (subseq start-words 0 (length probe)))) + (tree-equal slice probe :test test)) + (return-from match-words nil))))