Check if string is all-header in Emacs lisp?

everything. I was wondering if Emacs lisp has a built-in function to verify that the string is entirely made up of capital letters. Here is what I am using now:

(setq capital-letters (string-to-list "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))

(defun chars-are-capitalized (list-of-characters)
  "Returns true if every character in a list of characters is a capital         
letter. As a special case, the empty list returns true."
  (cond
   ((equal list-of-characters nil) t)
   ((not (member (car list-of-characters) capital-letters)) nil)
   (t (chars-are-capitalized (cdr list-of-characters)))))

(defun string-is-capitalized (string)
  "Returns true if every character in a string is a capital letter. The         
empty string returns true."
  (chars-are-capitalized (string-to-list string)))

It works fine (although it relies on the assumption that I will only use ASCII characters), but I was wondering if I was missing some obvious function that I should know about.

+3
source share
4 answers

For other answers:

  • upcase : , , (, ), ( Emacs ).

  • string-match - . , , case-fold-search nil, Emacs . string-match-p , . (Emacs , string-match, , , .)

  • - . "^...$" , Emacs - , . - unquote , .

, :

(defun string-is-capitalized (str)
  (let ((case-fold-search nil))
    (string-match-p "\\`[A-Z]*\\'" str)))

(BTW, Emacs Lisp -p , string-capitalized-p.)

+9

, , , :

(defun string-all-caps-p (string)
  "Return non-nil iff STRING is all capital letters."
  (save-match-data
    (let ((case-fold-search nil))
      (string-match "\\`[A-Z]+\\'" string))))

: ` ' .

A-Z ( , , , , ):

(defun string-has-no-lowercase (string)
  "Return true iff STRING has no lowercase"
  (equal (upcase string) string))
+6

s.el s-uppercase?:

(s-uppercase "GOT TO. THIS AMERICA, MAN.") ; t
(s-uppercase "You cannot lose if you do not play.") ; nil

:

(defun s-uppercase? (s)
  (let ((case-fold-search nil))
    (not (string-match-p "[[:lower:]]" s))))

[[:lower:]] - Emacs- , . string-match-p , , nil, . , , , t. string-match-p , case-fold-search.

Emacs , let. , case-fold-search, , .

+2
source

just a wild hunch, but what if you make a copy of the line, return it (I really don’t know much about lisp, but a quick google search said there is an up function, and then check if the two lines are the same? If they are, then the source should be in all cases: P

0
source

Source: https://habr.com/ru/post/1729841/


All Articles