Function: c-ml-string-in-end-delim

c-ml-string-in-end-delim is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-ml-string-in-end-delim BEG END OPEN-DELIM)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-ml-string-in-end-delim (beg end open-delim)
  ;; If the region (BEG END) intersects or touches a possible multiline string
  ;; terminator, return a cons of the position of the start and end of the
  ;; first such terminator.  The syntax-table text properties must be in a
  ;; consistent state when using this function.  OPEN-DELIM is the three
  ;; element dotted list of the start, end, and double quote position of the
  ;; multiline string opener that BEG is in, or nil if it isn't in one.
  (save-excursion
    (goto-char beg)
    (when open-delim
      ;; If BEG is in an opener, move back to a position we know to be "safe".
      (if (<= beg (cadr open-delim))
	  (goto-char (cadr open-delim))
	(c-ml-string-back-to-neutral (car open-delim))))

    (let (saved-match-data)
      (or
       ;; If we might be in the middle of "context" bytes at the start of a
       ;; closer, move to after the closer.
       (and c-ml-string-back-closer-re
	    (looking-at c-ml-string-any-closer-re)
	    (eq (c-in-literal) 'string)
	    (setq saved-match-data (match-data))
	    (goto-char (match-end 0)))

       ;; Otherwise, move forward over closers while we haven't yet reached END,
       ;; until we're after BEG.
       (progn
	 (while
	     (let (found)
	       (while			; Go over a single real closer.
		   (and
		    (search-forward-regexp
		     c-ml-string-any-closer-re
		     (min (+ end c-ml-string-max-closer-len-no-leader)
			  (point-max))
		     t)
		    (save-excursion
		      (goto-char (match-end 1))
		      (if (c-in-literal) ; a pseudo closer.
			  t
			(setq saved-match-data (match-data))
			(setq found t)
			nil))))
	       (and found
		    (<= (point) beg))
	       ;; (not (save-excursion
	       ;;        (goto-char (match-beginning 2))
	       ;;        (c-literal-start)))
	       ))))
      (set-match-data saved-match-data))

    ;; Test whether we've found the sought closing delimiter.
    (unless (or (null (match-data))
		(and (not (eobp))
		     (<= (point) beg))
		(> (match-beginning 0) beg)
		(progn (goto-char (match-beginning 2))
		       (not (c-literal-start))))
      (cons (match-beginning 1) (match-end 1)))))