Mercurial > emacs
comparison lispref/strings.texi @ 72267:698c7a5192be
(Formatting Strings): Warn against arbitrary strings as first arg to `format'.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 04 Aug 2006 10:42:14 +0000 |
parents | 1df664b7bac5 |
children | 296fad9dbeb0 |
comparison
equal
deleted
inserted
replaced
72266:436c014d941c | 72267:698c7a5192be |
---|---|
699 in the copy with encodings of the corresponding @var{objects}. The | 699 in the copy with encodings of the corresponding @var{objects}. The |
700 arguments @var{objects} are the computed values to be formatted. | 700 arguments @var{objects} are the computed values to be formatted. |
701 | 701 |
702 The characters in @var{string}, other than the format specifications, | 702 The characters in @var{string}, other than the format specifications, |
703 are copied directly into the output; if they have text properties, | 703 are copied directly into the output; if they have text properties, |
704 these are copied into the output also. | |
705 @end defun | 704 @end defun |
706 | 705 |
707 @cindex @samp{%} in format | 706 @cindex @samp{%} in format |
708 @cindex format specification | 707 @cindex format specification |
709 A format specification is a sequence of characters beginning with a | 708 A format specification is a sequence of characters beginning with a |
715 @example | 714 @example |
716 @group | 715 @group |
717 (format "The value of fill-column is %d." fill-column) | 716 (format "The value of fill-column is %d." fill-column) |
718 @result{} "The value of fill-column is 72." | 717 @result{} "The value of fill-column is 72." |
719 @end group | 718 @end group |
719 @end example | |
720 | |
721 Since @code{format} interprets @samp{%} characters as format | |
722 specifications, you should @emph{never} pass an arbitrary string as | |
723 the first argument. This is particularly true when the string is | |
724 generated by some Lisp code. Unless the string is @emph{known} to | |
725 never include any @samp{%} characters, pass @code{"%s"}, described | |
726 below, as the first argument, and the string as the second, like this: | |
727 | |
728 @example | |
729 (format "%s" @var{arbitrary-string}) | |
720 @end example | 730 @end example |
721 | 731 |
722 If @var{string} contains more than one format specification, the | 732 If @var{string} contains more than one format specification, the |
723 format specifications correspond to successive values from | 733 format specifications correspond to successive values from |
724 @var{objects}. Thus, the first format specification in @var{string} | 734 @var{objects}. Thus, the first format specification in @var{string} |