Function: cape--case-replace

cape--case-replace is a byte-compiled function defined in cape.el.

Signature

(cape--case-replace FLAG INPUT STR)

Documentation

Replace case of STR depending on INPUT and FLAG.

Source Code

;; Defined in ~/.emacs.d/elpa/cape-20260804.2303/cape.el
(defun cape--case-replace (flag input str)
  "Replace case of STR depending on INPUT and FLAG."
  (or (and (if (eq flag 'case-replace) case-replace flag)
           (string-prefix-p input str t)
           (cond
            ((let (case-fold-search) (string-match-p "\\`[[:upper:]]" input))
             (save-match-data
               ;; Ensure that single character uppercase input does not lead to
               ;; an all uppercase result.
               (when (and (= (length input) 1) (> (length str) 1))
                 (setq input (concat input (substring str 1 2))))
               (and (string-match input input)
                    (replace-match str nil nil input))))
            ((let (case-fold-search)
               (and (string-match-p "\\`[[:lower:]]*\\'" input)
                    (not (string-match-p "\\`[[:lower:]]*\\'" str))))
             (downcase str))))
      str))