comparison man/lispref/strings.texi @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children c3cf7db99b98
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
1 @c -*-texinfo-*- 1 @c -*-texinfo-*-
2 @c This is part of the XEmacs Lisp Reference Manual. 2 @c This is part of the XEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 @c See the file lispref.texi for copying conditions. 4 @c See the file lispref.texi for copying conditions.
5 @setfilename ../../info/strings.info 5 @setfilename ../../info/strings.info
6 @node Strings and Characters, Lists, Numbers, Top 6 @node Strings and Characters, Lists, Numbers, Top
7 @chapter Strings and Characters 7 @chapter Strings and Characters
8 @cindex strings 8 @cindex strings
136 @result{} "" 136 @result{} ""
137 @end example 137 @end example
138 138
139 Analogous functions operating on other data types include @code{list}, 139 Analogous functions operating on other data types include @code{list},
140 @code{cons} (@pxref{Building Lists}), @code{vector} (@pxref{Vectors}) 140 @code{cons} (@pxref{Building Lists}), @code{vector} (@pxref{Vectors})
141 and @code{bit-vector} (@pxref{Bit Vectors}). This function has not been 141 and @code{bit-vector} (@pxref{Bit Vectors}). This function has not been
142 available in XEmacs prior to 21.0 and FSF Emacs prior to 20.3. 142 available in XEmacs prior to 21.0 and FSF Emacs prior to 20.3.
143 @end defun 143 @end defun
144 144
145 @defun make-string count character 145 @defun make-string length character
146 This function returns a string made up of @var{count} repetitions of 146 This function returns a new string consisting entirely of @var{length}
147 @var{character}. If @var{count} is negative, an error is signaled. 147 successive copies of @var{character}. @var{length} must be a
148 non-negative integer.
148 149
149 @example 150 @example
150 (make-string 5 ?x) 151 (make-string 5 ?x)
151 @result{} "xxxxx" 152 @result{} "xxxxx"
152 (make-string 0 ?x) 153 (make-string 0 ?x)
177 from the string @code{"abcdefg"}. The index 3 marks the character 178 from the string @code{"abcdefg"}. The index 3 marks the character
178 position up to which the substring is copied. The character whose index 179 position up to which the substring is copied. The character whose index
179 is 3 is actually the fourth character in the string. 180 is 3 is actually the fourth character in the string.
180 181
181 A negative number counts from the end of the string, so that @minus{}1 182 A negative number counts from the end of the string, so that @minus{}1
182 signifies the index of the last character of the string. For example: 183 signifies the index of the last character of the string. For example:
183 184
184 @example 185 @example
185 @group 186 @group
186 (substring "abcdefg" -3 -1) 187 (substring "abcdefg" -3 -1)
187 @result{} "ef" 188 @result{} "ef"
310 @end defun 311 @end defun
311 312
312 @node Character Codes 313 @node Character Codes
313 @section Character Codes 314 @section Character Codes
314 315
315 @defun char-int ch 316 @defun char-int character
316 This function converts a character into an equivalent integer. 317 This function converts a character into an equivalent integer.
317 The resulting integer will always be non-negative. The integers in 318 The resulting integer will always be non-negative. The integers in
318 the range 0 - 255 map to characters as follows: 319 the range 0 - 255 map to characters as follows:
319 320
320 @table @asis 321 @table @asis
355 @need 2000 356 @need 2000
356 @node Text Comparison 357 @node Text Comparison
357 @section Comparison of Characters and Strings 358 @section Comparison of Characters and Strings
358 @cindex string equality 359 @cindex string equality
359 360
360 @defun char-equal character1 character2 361 @defun char-equal character1 character2 &optional buffer
361 This function returns @code{t} if the arguments represent the same 362 This function returns @code{t} if the arguments represent the same
362 character, @code{nil} otherwise. This function ignores differences 363 character, @code{nil} otherwise. This function ignores differences
363 in case if @code{case-fold-search} is non-@code{nil}. 364 in case if the value of @code{case-fold-search} is non-@code{nil} in
365 @var{buffer}, which defaults to the current buffer.
364 366
365 @example 367 @example
366 (char-equal ?x ?x) 368 (char-equal ?x ?x)
367 @result{} t 369 @result{} t
368 (let ((case-fold-search t)) 370 (let ((case-fold-search t))
458 (string< "abc" "") 460 (string< "abc" "")
459 @result{} nil 461 @result{} nil
460 (string< "abc" "ab") 462 (string< "abc" "ab")
461 @result{} nil 463 @result{} nil
462 (string< "" "") 464 (string< "" "")
463 @result{} nil 465 @result{} nil
464 @end group 466 @end group
465 @end example 467 @end example
466 @end defun 468 @end defun
467 469
468 @defun string-lessp string1 string2 470 @defun string-lessp string1 string2
558 See also the function @code{format} in @ref{Formatting Strings}. 560 See also the function @code{format} in @ref{Formatting Strings}.
559 @end defun 561 @end defun
560 562
561 @defun string-to-number string &optional base 563 @defun string-to-number string &optional base
562 @cindex string to number 564 @cindex string to number
563 This function returns the numeric value of the characters in 565 This function returns the numeric value represented by @var{string},
564 @var{string}, read in @var{base}. It skips spaces and tabs at the 566 read in @var{base}. It skips spaces and tabs at the beginning of
565 beginning of @var{string}, then reads as much of @var{string} as it can 567 @var{string}, then reads as much of @var{string} as it can interpret as
566 interpret as a number. (On some systems it ignores other whitespace at 568 a number. (On some systems it ignores other whitespace at the
567 the beginning, not just spaces and tabs.) If the first character after 569 beginning, not just spaces and tabs.) If the first character after the
568 the ignored whitespace is not a digit or a minus sign, this function 570 ignored whitespace is not a digit or a minus sign, this function returns
569 returns 0. 571 0.
570 572
571 If @var{base} is not specified, it defaults to ten. With @var{base} 573 If @var{base} is not specified, it defaults to ten. With @var{base}
572 other than ten, only integers can be read. 574 other than ten, only integers can be read.
573 575
574 @example 576 @example
635 formatting feature described here; they differ from @code{format} only 637 formatting feature described here; they differ from @code{format} only
636 in how they use the result of formatting. 638 in how they use the result of formatting.
637 639
638 @defun format string &rest objects 640 @defun format string &rest objects
639 This function returns a new string that is made by copying 641 This function returns a new string that is made by copying
640 @var{string} and then replacing any format specification 642 @var{string} and then replacing any format specification
641 in the copy with encodings of the corresponding @var{objects}. The 643 in the copy with encodings of the corresponding @var{objects}. The
642 arguments @var{objects} are the computed values to be formatted. 644 arguments @var{objects} are the computed values to be formatted.
643 @end defun 645 @end defun
644 646
645 @cindex @samp{%} in format 647 @cindex @samp{%} in format
743 @result{} "The name of this buffer is strings.texi." 745 @result{} "The name of this buffer is strings.texi."
744 746
745 (format "The buffer object prints as %s." (current-buffer)) 747 (format "The buffer object prints as %s." (current-buffer))
746 @result{} "The buffer object prints as #<buffer strings.texi>." 748 @result{} "The buffer object prints as #<buffer strings.texi>."
747 749
748 (format "The octal value of %d is %o, 750 (format "The octal value of %d is %o,
749 and the hex value is %x." 18 18 18) 751 and the hex value is %x." 18 18 18)
750 @result{} "The octal value of 18 is 22, 752 @result{} "The octal value of 18 is 22,
751 and the hex value is 12." 753 and the hex value is 12."
752 @end group 754 @end group
753 @end example 755 @end example
754 756
755 There are many additional flags and specifications that can occur 757 There are many additional flags and specifications that can occur
780 A @dfn{repositioning} specification changes which argument to 782 A @dfn{repositioning} specification changes which argument to
781 @code{format} is used by the current and all following format 783 @code{format} is used by the current and all following format
782 specifications. Normally the first specification uses the first 784 specifications. Normally the first specification uses the first
783 argument, the second specification uses the second argument, etc. Using 785 argument, the second specification uses the second argument, etc. Using
784 a repositioning specification, you can change this. By placing a number 786 a repositioning specification, you can change this. By placing a number
785 @var{N} followed by a @samp{$} between the @samp{%} and the format 787 @var{n} followed by a @samp{$} between the @samp{%} and the format
786 character, you cause the specification to use the @var{N}th argument. 788 character, you cause the specification to use the @var{n}th argument.
787 The next specification will use the @var{N}+1'th argument, etc. 789 The next specification will use the @var{n}+1'th argument, etc.
788 790
789 For example: 791 For example:
790 792
791 @example 793 @example
792 @group 794 @group
844 of 7. In the first case, the string inserted in place of @samp{%7s} has 846 of 7. In the first case, the string inserted in place of @samp{%7s} has
845 only 3 letters, so 4 blank spaces are inserted for padding. In the 847 only 3 letters, so 4 blank spaces are inserted for padding. In the
846 second case, the string @code{"specification"} is 13 letters wide but is 848 second case, the string @code{"specification"} is 13 letters wide but is
847 not truncated. In the third case, the padding is on the right. 849 not truncated. In the third case, the padding is on the right.
848 850
849 @smallexample 851 @smallexample
850 @group 852 @group
851 (format "The word `%7s' actually has %d letters in it." 853 (format "The word `%7s' actually has %d letters in it."
852 "foo" (length "foo")) 854 "foo" (length "foo"))
853 @result{} "The word ` foo' actually has 3 letters in it." 855 @result{} "The word ` foo' actually has 3 letters in it."
854 @end group 856 @end group
855 857
856 @group 858 @group
857 (format "The word `%7s' actually has %d letters in it." 859 (format "The word `%7s' actually has %d letters in it."
858 "specification" (length "specification")) 860 "specification" (length "specification"))
859 @result{} "The word `specification' actually has 13 letters in it." 861 @result{} "The word `specification' actually has 13 letters in it."
860 @end group 862 @end group
861 863
862 @group 864 @group
863 (format "The word `%-7s' actually has %d letters in it." 865 (format "The word `%-7s' actually has %d letters in it."
864 "foo" (length "foo")) 866 "foo" (length "foo"))
865 @result{} "The word `foo ' actually has 3 letters in it." 867 @result{} "The word `foo ' actually has 3 letters in it."
866 @end group 868 @end group
867 @end smallexample 869 @end smallexample
868 870
869 @cindex format precision 871 @cindex format precision
870 @cindex precision of formatted numbers 872 @cindex precision of formatted numbers
897 conversions. 899 conversions.
898 @end itemize 900 @end itemize
899 901
900 @node Character Case 902 @node Character Case
901 @section Character Case 903 @section Character Case
902 @cindex upper case 904 @cindex upper case
903 @cindex lower case 905 @cindex lower case
904 @cindex character case 906 @cindex character case
905 907
906 The character case functions change the case of single characters or 908 The character case functions change the case of single characters or
907 of the contents of strings. The functions convert only alphabetic 909 of the contents of strings. The functions convert only alphabetic
908 characters (the letters @samp{A} through @samp{Z} and @samp{a} through 910 characters (the letters @samp{A} through @samp{Z} and @samp{a} through
909 @samp{z}); other characters are not altered. The functions do not 911 @samp{z}); other characters are not altered. The functions do not
910 modify the strings that are passed to them as arguments. 912 modify the strings that are passed to them as arguments.
911 913
912 The examples below use the characters @samp{X} and @samp{x} which have 914 The examples below use the characters @samp{X} and @samp{x} which have
913 @sc{ascii} codes 88 and 120 respectively. 915 @sc{ascii} codes 88 and 120 respectively.
914 916
915 @defun downcase string-or-char 917 @defun downcase string-or-char &optional buffer
916 This function converts a character or a string to lower case. 918 This function converts a character or a string to lower case.
917 919
918 When the argument to @code{downcase} is a string, the function creates 920 When the argument to @code{downcase} is a string, the function creates
919 and returns a new string in which each letter in the argument that is 921 and returns a new string in which each letter in the argument that is
920 upper case is converted to lower case. When the argument to 922 upper case is converted to lower case. When the argument to
921 @code{downcase} is a character, @code{downcase} returns the 923 @code{downcase} is a character, @code{downcase} returns the
922 corresponding lower case character. (This value is actually an integer 924 corresponding lower case character. (This value is actually an integer
923 under XEmacs 19.) If the original character is lower case, or is not a 925 under XEmacs 19.) If the original character is lower case, or is not a
924 letter, then the value equals the original character. 926 letter, then the value equals the original character.
925 927
928 Optional second arg @var{buffer} specifies which buffer's case tables to
929 use, and defaults to the current buffer.
930
926 @example 931 @example
927 (downcase "The cat in the hat") 932 (downcase "The cat in the hat")
928 @result{} "the cat in the hat" 933 @result{} "the cat in the hat"
929 934
930 (downcase ?X) 935 (downcase ?X)
932 @result{} 120 ;; @r{Under XEmacs 19.} 937 @result{} 120 ;; @r{Under XEmacs 19.}
933 938
934 @end example 939 @end example
935 @end defun 940 @end defun
936 941
937 @defun upcase string-or-char 942 @defun upcase string-or-char &optional buffer
938 This function converts a character or a string to upper case. 943 This function converts a character or a string to upper case.
939 944
940 When the argument to @code{upcase} is a string, the function creates 945 When the argument to @code{upcase} is a string, the function creates
941 and returns a new string in which each letter in the argument that is 946 and returns a new string in which each letter in the argument that is
942 lower case is converted to upper case. 947 lower case is converted to upper case.
944 When the argument to @code{upcase} is a character, @code{upcase} returns 949 When the argument to @code{upcase} is a character, @code{upcase} returns
945 the corresponding upper case character. (This value is actually an 950 the corresponding upper case character. (This value is actually an
946 integer under XEmacs 19.) If the original character is upper case, or 951 integer under XEmacs 19.) If the original character is upper case, or
947 is not a letter, then the value equals the original character. 952 is not a letter, then the value equals the original character.
948 953
954 Optional second arg @var{buffer} specifies which buffer's case tables to
955 use, and defaults to the current buffer.
956
949 @example 957 @example
950 (upcase "The cat in the hat") 958 (upcase "The cat in the hat")
951 @result{} "THE CAT IN THE HAT" 959 @result{} "THE CAT IN THE HAT"
952 960
953 (upcase ?x) 961 (upcase ?x)
954 @result{} ?X ;; @r{Under XEmacs 20.} 962 @result{} ?X ;; @r{Under XEmacs 20.}
955 @result{} 88 ;; @r{Under XEmacs 19.} 963 @result{} 88 ;; @r{Under XEmacs 19.}
956 @end example 964 @end example
957 @end defun 965 @end defun
958 966
959 @defun capitalize string-or-char 967 @defun capitalize string-or-char &optional buffer
960 @cindex capitalization 968 @cindex capitalization
961 This function capitalizes strings or characters. If 969 This function capitalizes strings or characters. If
962 @var{string-or-char} is a string, the function creates and returns a new 970 @var{string-or-char} is a string, the function creates and returns a new
963 string, whose contents are a copy of @var{string-or-char} in which each 971 string, whose contents are a copy of @var{string-or-char} in which each
964 word has been capitalized. This means that the first character of each 972 word has been capitalized. This means that the first character of each
970 table (@pxref{Syntax Class Table}). 978 table (@pxref{Syntax Class Table}).
971 979
972 When the argument to @code{capitalize} is a character, @code{capitalize} 980 When the argument to @code{capitalize} is a character, @code{capitalize}
973 has the same result as @code{upcase}. 981 has the same result as @code{upcase}.
974 982
983 Optional second arg @var{buffer} specifies which buffer's case tables to
984 use, and defaults to the current buffer.
985
975 @example 986 @example
976 (capitalize "The cat in the hat") 987 (capitalize "The cat in the hat")
977 @result{} "The Cat In The Hat" 988 @result{} "The Cat In The Hat"
978 989
979 (capitalize "THE 77TH-HATTED CAT") 990 (capitalize "THE 77TH-HATTED CAT")
1043 @defun case-table-p object 1054 @defun case-table-p object
1044 This predicate returns non-@code{nil} if @var{object} is a valid case 1055 This predicate returns non-@code{nil} if @var{object} is a valid case
1045 table. 1056 table.
1046 @end defun 1057 @end defun
1047 1058
1048 @defun set-standard-case-table table 1059 @defun set-standard-case-table case-table
1049 This function makes @var{table} the standard case table, so that it will 1060 This function makes @var{case-table} the standard case table, so that it
1050 apply to any buffers created subsequently. 1061 will apply to any buffers created subsequently.
1051 @end defun 1062 @end defun
1052 1063
1053 @defun standard-case-table 1064 @defun standard-case-table
1054 This returns the standard case table. 1065 This returns the standard case table.
1055 @end defun 1066 @end defun
1056 1067
1057 @defun current-case-table 1068 @defun current-case-table &optional buffer
1058 This function returns the current buffer's case table. 1069 This function returns the case table of @var{buffer}, which defaults to
1059 @end defun 1070 the current buffer.
1060 1071 @end defun
1061 @defun set-case-table table 1072
1062 This sets the current buffer's case table to @var{table}. 1073 @defun set-case-table case-table
1074 This sets the current buffer's case table to @var{case-table}.
1063 @end defun 1075 @end defun
1064 1076
1065 The following three functions are convenient subroutines for packages 1077 The following three functions are convenient subroutines for packages
1066 that define non-@sc{ascii} character sets. They modify a string 1078 that define non-@sc{ascii} character sets. They modify a string
1067 @var{downcase-table} provided as an argument; this should be a string to 1079 @var{downcase-table} provided as an argument; this should be a string to
1169 Used for syntax tables, which specify the syntax of a particular 1181 Used for syntax tables, which specify the syntax of a particular
1170 character. Higher-level Lisp functions are provided for 1182 character. Higher-level Lisp functions are provided for
1171 working with syntax tables. The valid values are integers. 1183 working with syntax tables. The valid values are integers.
1172 @end table 1184 @end table
1173 1185
1174 @defun char-table-type table 1186 @defun char-table-type char-table
1175 This function returns the type of char table @var{table}. 1187 This function returns the type of char table @var{char-table}.
1176 @end defun 1188 @end defun
1177 1189
1178 @defun char-table-type-list 1190 @defun char-table-type-list
1179 This function returns a list of the recognized char table types. 1191 This function returns a list of the recognized char table types.
1180 @end defun 1192 @end defun
1190 This function makes a new, empty char table of type @var{type}. 1202 This function makes a new, empty char table of type @var{type}.
1191 @var{type} should be a symbol, one of @code{char}, @code{category}, 1203 @var{type} should be a symbol, one of @code{char}, @code{category},
1192 @code{display}, @code{generic}, or @code{syntax}. 1204 @code{display}, @code{generic}, or @code{syntax}.
1193 @end defun 1205 @end defun
1194 1206
1195 @defun put-char-table range val table 1207 @defun put-char-table range value char-table
1196 This function sets the value for chars in @var{range} to be @var{val} in 1208 This function sets the value for chars in @var{range} to be @var{value} in
1197 @var{table}. 1209 @var{char-table}.
1198 1210
1199 @var{range} specifies one or more characters to be affected and should be 1211 @var{range} specifies one or more characters to be affected and should be
1200 one of the following: 1212 one of the following:
1201 1213
1202 @itemize @bullet 1214 @itemize @bullet
1209 (only allowed when @sc{mule} support is present) 1221 (only allowed when @sc{mule} support is present)
1210 @item 1222 @item
1211 A single character 1223 A single character
1212 @end itemize 1224 @end itemize
1213 1225
1214 @var{val} must be a value appropriate for the type of @var{table}. 1226 @var{value} must be a value appropriate for the type of @var{char-table}.
1215 @end defun 1227 @end defun
1216 1228
1217 @defun get-char-table ch table 1229 @defun get-char-table character char-table
1218 This function finds the value for char @var{ch} in @var{table}. 1230 This function finds the value for @var{character} in @var{char-table}.
1219 @end defun 1231 @end defun
1220 1232
1221 @defun get-range-char-table range table &optional multi 1233 @defun get-range-char-table range char-table &optional multi
1222 This function finds the value for a range in @var{table}. If there is 1234 This function finds the value for a range in @var{char-table}. If there is
1223 more than one value, @var{multi} is returned (defaults to @code{nil}). 1235 more than one value, @var{multi} is returned (defaults to @code{nil}).
1224 @end defun 1236 @end defun
1225 1237
1226 @defun reset-char-table table 1238 @defun reset-char-table char-table
1227 This function resets a char table to its default state. 1239 This function resets @var{char-table} to its default state.
1228 @end defun 1240 @end defun
1229 1241
1230 @defun map-char-table function table &optional range 1242 @defun map-char-table function char-table &optional range
1231 This function maps @var{function} over entries in @var{table}, calling 1243 This function maps @var{function} over entries in @var{char-table}, calling
1232 it with two args, each key and value in the table. 1244 it with two args, each key and value in the table.
1233 1245
1234 @var{range} specifies a subrange to map over and is in the same format 1246 @var{range} specifies a subrange to map over and is in the same format
1235 as the @var{range} argument to @code{put-range-table}. If omitted or 1247 as the @var{range} argument to @code{put-range-table}. If omitted or
1236 @code{t}, it defaults to the entire table. 1248 @code{t}, it defaults to the entire table.