* doc/lispref/strings.texi (Creating Strings): Document it.
* lisp/emacs-lisp/subr-x.el (string-chop-newline): Add new function.
absolute value).
@end defun
+@defun string-chop-newline string
+Remove the final newline, if any, from @var{string}.
+@end defun
+
@node Modifying Strings
@section Modifying Strings
@cindex modifying strings
+++
*** A number of new string manipulation functions have been added.
'string-clean-whitespace', 'string-fill', 'string-limit',
-'string-lines', 'string-pad' and 'string-slice'.
+'string-lines', 'string-pad', 'string-chop-newline' and 'string-slice'.
+++
*** New variable 'current-minibuffer-command'.
(string-remove-prefix
:no-manual t
:eval (string-remove-prefix "foo" "foobar"))
+ (string-chop-newline
+ :eval (string-chop-newline "foo\n"))
(string-clean-whitespace
:eval (string-clean-whitespace " foo bar "))
(string-fill
(and (> length 0)
(make-string pad-length (or padding ?\s)))))))
+(defun string-chop-newline (string)
+ "Remove the final newline (if any) from STRING."
+ (replace-regexp-in-string "\n\\'" "" string))
+
(defun replace-region-contents (beg end replace-fn
&optional max-secs max-costs)
"Replace the region between BEG and END using REPLACE-FN.
(should (equal (string-pad "foo" -5 ?-) "--foo"))
(should (equal (string-pad "foo" 2 ?-) "foo")))
+(ert-deftest subr-string-chop-newline ()
+ (should (equal (string-chop-newline "foo\n") "foo"))
+ (should (equal (string-chop-newline "foo\nbar\n") "foo\nbar"))
+ (should (equal (string-chop-newline "foo\nbar") "foo\nbar")))
+
(provide 'subr-x-tests)
;;; subr-x-tests.el ends here