Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / mann / string.n
CommitLineData
920dae64
AT
1'\"
2'\" Copyright (c) 1993 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\"
5'\" See the file "license.terms" for information on usage and redistribution
6'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7'\"
8'\" RCS: @(#) $Id: string.n,v 1.17.2.3 2004/10/27 14:23:58 dkf Exp $
9'\"
10'\" The definitions below are for supplemental macros used in Tcl/Tk
11'\" manual entries.
12'\"
13'\" .AP type name in/out ?indent?
14'\" Start paragraph describing an argument to a library procedure.
15'\" type is type of argument (int, etc.), in/out is either "in", "out",
16'\" or "in/out" to describe whether procedure reads or modifies arg,
17'\" and indent is equivalent to second arg of .IP (shouldn't ever be
18'\" needed; use .AS below instead)
19'\"
20'\" .AS ?type? ?name?
21'\" Give maximum sizes of arguments for setting tab stops. Type and
22'\" name are examples of largest possible arguments that will be passed
23'\" to .AP later. If args are omitted, default tab stops are used.
24'\"
25'\" .BS
26'\" Start box enclosure. From here until next .BE, everything will be
27'\" enclosed in one large box.
28'\"
29'\" .BE
30'\" End of box enclosure.
31'\"
32'\" .CS
33'\" Begin code excerpt.
34'\"
35'\" .CE
36'\" End code excerpt.
37'\"
38'\" .VS ?version? ?br?
39'\" Begin vertical sidebar, for use in marking newly-changed parts
40'\" of man pages. The first argument is ignored and used for recording
41'\" the version when the .VS was added, so that the sidebars can be
42'\" found and removed when they reach a certain age. If another argument
43'\" is present, then a line break is forced before starting the sidebar.
44'\"
45'\" .VE
46'\" End of vertical sidebar.
47'\"
48'\" .DS
49'\" Begin an indented unfilled display.
50'\"
51'\" .DE
52'\" End of indented unfilled display.
53'\"
54'\" .SO
55'\" Start of list of standard options for a Tk widget. The
56'\" options follow on successive lines, in four columns separated
57'\" by tabs.
58'\"
59'\" .SE
60'\" End of list of standard options for a Tk widget.
61'\"
62'\" .OP cmdName dbName dbClass
63'\" Start of description of a specific option. cmdName gives the
64'\" option's name as specified in the class command, dbName gives
65'\" the option's name in the option database, and dbClass gives
66'\" the option's class in the option database.
67'\"
68'\" .UL arg1 arg2
69'\" Print arg1 underlined, then print arg2 normally.
70'\"
71'\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $
72'\"
73'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
74.if t .wh -1.3i ^B
75.nr ^l \n(.l
76.ad b
77'\" # Start an argument description
78.de AP
79.ie !"\\$4"" .TP \\$4
80.el \{\
81. ie !"\\$2"" .TP \\n()Cu
82. el .TP 15
83.\}
84.ta \\n()Au \\n()Bu
85.ie !"\\$3"" \{\
86\&\\$1 \\fI\\$2\\fP (\\$3)
87.\".b
88.\}
89.el \{\
90.br
91.ie !"\\$2"" \{\
92\&\\$1 \\fI\\$2\\fP
93.\}
94.el \{\
95\&\\fI\\$1\\fP
96.\}
97.\}
98..
99'\" # define tabbing values for .AP
100.de AS
101.nr )A 10n
102.if !"\\$1"" .nr )A \\w'\\$1'u+3n
103.nr )B \\n()Au+15n
104.\"
105.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
106.nr )C \\n()Bu+\\w'(in/out)'u+2n
107..
108.AS Tcl_Interp Tcl_CreateInterp in/out
109'\" # BS - start boxed text
110'\" # ^y = starting y location
111'\" # ^b = 1
112.de BS
113.br
114.mk ^y
115.nr ^b 1u
116.if n .nf
117.if n .ti 0
118.if n \l'\\n(.lu\(ul'
119.if n .fi
120..
121'\" # BE - end boxed text (draw box now)
122.de BE
123.nf
124.ti 0
125.mk ^t
126.ie n \l'\\n(^lu\(ul'
127.el \{\
128.\" Draw four-sided box normally, but don't draw top of
129.\" box if the box started on an earlier page.
130.ie !\\n(^b-1 \{\
131\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
132.\}
133.el \}\
134\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
135.\}
136.\}
137.fi
138.br
139.nr ^b 0
140..
141'\" # VS - start vertical sidebar
142'\" # ^Y = starting y location
143'\" # ^v = 1 (for troff; for nroff this doesn't matter)
144.de VS
145.if !"\\$2"" .br
146.mk ^Y
147.ie n 'mc \s12\(br\s0
148.el .nr ^v 1u
149..
150'\" # VE - end of vertical sidebar
151.de VE
152.ie n 'mc
153.el \{\
154.ev 2
155.nf
156.ti 0
157.mk ^t
158\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
159.sp -1
160.fi
161.ev
162.\}
163.nr ^v 0
164..
165'\" # Special macro to handle page bottom: finish off current
166'\" # box/sidebar if in box/sidebar mode, then invoked standard
167'\" # page bottom macro.
168.de ^B
169.ev 2
170'ti 0
171'nf
172.mk ^t
173.if \\n(^b \{\
174.\" Draw three-sided box if this is the box's first page,
175.\" draw two sides but no top otherwise.
176.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
178.\}
179.if \\n(^v \{\
180.nr ^x \\n(^tu+1v-\\n(^Yu
181\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
182.\}
183.bp
184'fi
185.ev
186.if \\n(^b \{\
187.mk ^y
188.nr ^b 2
189.\}
190.if \\n(^v \{\
191.mk ^Y
192.\}
193..
194'\" # DS - begin display
195.de DS
196.RS
197.nf
198.sp
199..
200'\" # DE - end display
201.de DE
202.fi
203.RE
204.sp
205..
206'\" # SO - start of list of standard options
207.de SO
208.SH "STANDARD OPTIONS"
209.LP
210.nf
211.ta 5.5c 11c
212.ft B
213..
214'\" # SE - end of list of standard options
215.de SE
216.fi
217.ft R
218.LP
219See the \\fBoptions\\fR manual entry for details on the standard options.
220..
221'\" # OP - start of full description for a single option
222.de OP
223.LP
224.nf
225.ta 4c
226Command-Line Name: \\fB\\$1\\fR
227Database Name: \\fB\\$2\\fR
228Database Class: \\fB\\$3\\fR
229.fi
230.IP
231..
232'\" # CS - begin code excerpt
233.de CS
234.RS
235.nf
236.ta .25i .5i .75i 1i
237..
238'\" # CE - end code excerpt
239.de CE
240.fi
241.RE
242..
243.de UL
244\\$1\l'|0\(ul'\\$2
245..
246.TH string n 8.1 Tcl "Tcl Built-In Commands"
247.BS
248'\" Note: do not modify the .SH NAME line immediately below!
249.SH NAME
250string \- Manipulate strings
251.SH SYNOPSIS
252\fBstring \fIoption arg \fR?\fIarg ...?\fR
253.BE
254
255.SH DESCRIPTION
256.PP
257Performs one of several string operations, depending on \fIoption\fR.
258The legal \fIoption\fRs (which may be abbreviated) are:
259.TP
260\fBstring bytelength \fIstring\fR
261Returns a decimal string giving the number of bytes used to represent
262\fIstring\fR in memory. Because UTF\-8 uses one to three bytes to
263represent Unicode characters, the byte length will not be the same as
264the character length in general. The cases where a script cares about
265the byte length are rare. In almost all cases, you should use the
266\fBstring length\fR operation (including determining the length of a
267Tcl ByteArray object). Refer to the \fBTcl_NumUtfChars\fR manual
268entry for more details on the UTF\-8 representation.
269.TP
270\fBstring compare\fR ?\fB\-nocase\fR? ?\fB\-length int\fR? \fIstring1 string2\fR
271Perform a character-by-character comparison of strings \fIstring1\fR
272and \fIstring2\fR. Returns \-1, 0, or 1, depending on whether
273\fIstring1\fR is lexicographically less than, equal to, or greater
274than \fIstring2\fR. If \fB\-length\fR is specified, then only the
275first \fIlength\fR characters are used in the comparison. If
276\fB\-length\fR is negative, it is ignored. If \fB\-nocase\fR is
277specified, then the strings are compared in a case-insensitive manner.
278.TP
279\fBstring equal\fR ?\fB\-nocase\fR? ?\fB-length int\fR? \fIstring1 string2\fR
280Perform a character-by-character comparison of strings \fIstring1\fR
281and \fIstring2\fR. Returns 1 if \fIstring1\fR and \fIstring2\fR are
282identical, or 0 when not. If \fB\-length\fR is specified, then only
283the first \fIlength\fR characters are used in the comparison. If
284\fB\-length\fR is negative, it is ignored. If \fB\-nocase\fR is
285specified, then the strings are compared in a case-insensitive manner.
286.TP
287\fBstring first \fIstring1 string2\fR ?\fIstartIndex\fR?
288Search \fIstring2\fR for a sequence of characters that exactly match
289the characters in \fIstring1\fR. If found, return the index of the
290first character in the first such match within \fIstring2\fR. If not
291found, return \-1. If \fIstartIndex\fR is specified (in any of the
292forms accepted by the \fBindex\fR method), then the search is
293constrained to start with the character in \fIstring2\fR specified by
294the index. For example,
295.RS
296.CS
297\fBstring first a 0a23456789abcdef 5\fR
298.CE
299will return \fB10\fR, but
300.CS
301\fBstring first a 0123456789abcdef 11\fR
302.CE
303will return \fB\-1\fR.
304.RE
305.TP
306\fBstring index \fIstring charIndex\fR
307Returns the \fIcharIndex\fR'th character of the \fIstring\fR argument.
308A \fIcharIndex\fR of 0 corresponds to the first character of the
309string. \fIcharIndex\fR may be specified as follows:
310.RS
311.IP \fIinteger\fR 10
312The char specified at this integral index.
313.IP \fBend\fR 10
314The last char of the string.
315.IP \fBend\-\fIinteger\fR 10
316The last char of the string minus the specified integer offset
317(e.g. \fBend\-1\fR would refer to the "c" in "abcd").
318.PP
319If \fIcharIndex\fR is less than 0 or greater than or equal to the
320length of the string then an empty string is returned.
321.RE
322.TP
323\fBstring is \fIclass\fR ?\fB\-strict\fR? ?\fB\-failindex \fIvarname\fR? \fIstring\fR
324Returns 1 if \fIstring\fR is a valid member of the specified character
325class, otherwise returns 0. If \fB\-strict\fR is specified, then an
326empty string returns 0, otherwise and empty string will return 1 on
327any class. If \fB\-failindex\fR is specified, then if the function
328returns 0, the index in the string where the class was no longer valid
329will be stored in the variable named \fIvarname\fR. The \fIvarname\fR
330will not be set if the function returns 1. The following character
331classes are recognized (the class name can be abbreviated):
332.RS
333.IP \fBalnum\fR 12
334Any Unicode alphabet or digit character.
335.IP \fBalpha\fR 12
336Any Unicode alphabet character.
337.IP \fBascii\fR 12
338Any character with a value less than \\u0080 (those that are in the
3397\-bit ascii range).
340.IP \fBboolean\fR 12
341Any of the forms allowed to \fBTcl_GetBoolean\fR.
342.IP \fBcontrol\fR 12
343Any Unicode control character.
344.IP \fBdigit\fR 12
345Any Unicode digit character. Note that this includes characters
346outside of the [0\-9] range.
347.IP \fBdouble\fR 12
348Any of the valid forms for a double in Tcl, with optional surrounding
349whitespace. In case of under/overflow in the value, 0 is returned and
350the \fIvarname\fR will contain \-1.
351.IP \fBfalse\fR 12
352Any of the forms allowed to \fBTcl_GetBoolean\fR where the value is
353false.
354.IP \fBgraph\fR 12
355Any Unicode printing character, except space.
356.IP \fBinteger\fR 12
357Any of the valid forms for an ordinary integer in Tcl, with optional
358surrounding whitespace. In case of under/overflow in the value, 0 is
359returned and the \fIvarname\fR will contain \-1.
360.IP \fBlower\fR 12
361Any Unicode lower case alphabet character.
362.IP \fBprint\fR 12
363Any Unicode printing character, including space.
364.IP \fBpunct\fR 12
365Any Unicode punctuation character.
366.IP \fBspace\fR 12
367Any Unicode space character.
368.IP \fBtrue\fR 12
369Any of the forms allowed to \fBTcl_GetBoolean\fR where the value is
370true.
371.IP \fBupper\fR 12
372Any upper case alphabet character in the Unicode character set.
373.IP \fBwordchar\fR 12
374Any Unicode word character. That is any alphanumeric character, and
375any Unicode connector punctuation characters (e.g. underscore).
376.IP \fBxdigit\fR 12
377Any hexadecimal digit character ([0\-9A\-Fa\-f]).
378.PP
379In the case of \fBboolean\fR, \fBtrue\fR and \fBfalse\fR, if the
380function will return 0, then the \fIvarname\fR will always be set to
3810, due to the varied nature of a valid boolean value.
382.RE
383.TP
384\fBstring last \fIstring1 string2\fR ?\fIlastIndex\fR?
385Search \fIstring2\fR for a sequence of characters that exactly match
386the characters in \fIstring1\fR. If found, return the index of the
387first character in the last such match within \fIstring2\fR. If there
388is no match, then return \-1. If \fIlastIndex\fR is specified (in any
389of the forms accepted by the \fBindex\fR method), then only the
390characters in \fIstring2\fR at or before the specified \fIlastIndex\fR
391will be considered by the search. For example,
392.RS
393.CS
394\fBstring last a 0a23456789abcdef 15\fR
395.CE
396will return \fB10\fR, but
397.CS
398\fBstring last a 0a23456789abcdef 9\fR
399.CE
400will return \fB1\fR.
401.RE
402.TP
403\fBstring length \fIstring\fR
404Returns a decimal string giving the number of characters in
405\fIstring\fR. Note that this is not necessarily the same as the
406number of bytes used to store the string. If the object is a
407ByteArray object (such as those returned from reading a binary encoded
408channel), then this will return the actual byte length of the object.
409.TP
410\fBstring map\fR ?\fB\-nocase\fR? \fImapping string\fR
411Replaces substrings in \fIstring\fR based on the key-value pairs in
412\fImapping\fR. \fImapping\fR is a list of \fIkey value key value ...\fR
413as in the form returned by \fBarray get\fR. Each instance of a
414key in the string will be replaced with its corresponding value. If
415\fB\-nocase\fR is specified, then matching is done without regard to
416case differences. Both \fIkey\fR and \fIvalue\fR may be multiple
417characters. Replacement is done in an ordered manner, so the key
418appearing first in the list will be checked first, and so on.
419\fIstring\fR is only iterated over once, so earlier key replacements
420will have no affect for later key matches. For example,
421.RS
422.CS
423\fBstring map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc\fR
424.CE
425will return the string \fB01321221\fR.
426.PP
427Note that if an earlier \fIkey\fR is a prefix of a later one, it will
428completely mask the later one. So if the previous example is
429reordered like this,
430.CS
431\fBstring map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc\fR
432.CE
433it will return the string \fB02c322c222c\fR.
434.RE
435.TP
436\fBstring match\fR ?\fB\-nocase\fR? \fIpattern\fR \fIstring\fR
437See if \fIpattern\fR matches \fIstring\fR; return 1 if it does, 0 if
438it doesn't. If \fB\-nocase\fR is specified, then the pattern attempts
439to match against the string in a case insensitive manner. For the two
440strings to match, their contents must be identical except that the
441following special sequences may appear in \fIpattern\fR:
442.RS
443.IP \fB*\fR 10
444Matches any sequence of characters in \fIstring\fR, including a null
445string.
446.IP \fB?\fR 10
447Matches any single character in \fIstring\fR.
448.IP \fB[\fIchars\fB]\fR 10
449Matches any character in the set given by \fIchars\fR. If a sequence
450of the form \fIx\fB\-\fIy\fR appears in \fIchars\fR, then any
451character between \fIx\fR and \fIy\fR, inclusive, will match. When
452used with \fB\-nocase\fR, the end points of the range are converted to
453lower case first. Whereas {[A\-z]} matches '_' when matching
454case-sensitively ('_' falls between the 'Z' and 'a'), with
455\fB\-nocase\fR this is considered like {[A\-Za\-z]} (and probably what
456was meant in the first place).
457.IP \fB\e\fIx\fR 10
458Matches the single character \fIx\fR. This provides a way of avoiding
459the special interpretation of the characters \fB*?[]\e\fR in
460\fIpattern\fR.
461.RE
462.TP
463\fBstring range \fIstring first last\fR
464Returns a range of consecutive characters from \fIstring\fR, starting
465with the character whose index is \fIfirst\fR and ending with the
466character whose index is \fIlast\fR. An index of 0 refers to the first
467character of the string. \fIfirst\fR and \fIlast\fR may be specified
468as for the \fBindex\fR method. If \fIfirst\fR is less than zero then
469it is treated as if it were zero, and if \fIlast\fR is greater than or
470equal to the length of the string then it is treated as if it were
471\fBend\fR. If \fIfirst\fR is greater than \fIlast\fR then an empty
472string is returned.
473.TP
474\fBstring repeat \fIstring count\fR
475Returns \fIstring\fR repeated \fIcount\fR number of times.
476.TP
477\fBstring replace \fIstring first last\fR ?\fInewstring\fR?
478Removes a range of consecutive characters from \fIstring\fR, starting
479with the character whose index is \fIfirst\fR and ending with the
480character whose index is \fIlast\fR. An index of 0 refers to the
481first character of the string. \fIFirst\fR and \fIlast\fR may be
482specified as for the \fBindex\fR method. If \fInewstring\fR is
483specified, then it is placed in the removed character range. If
484\fIfirst\fR is less than zero then it is treated as if it were zero,
485and if \fIlast\fR is greater than or equal to the length of the string
486then it is treated as if it were \fBend\fR. If \fIfirst\fR is greater
487than \fIlast\fR or the length of the initial string, or \fIlast\fR is
488less than 0, then the initial string is returned untouched.
489.TP
490\fBstring tolower \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR?
491Returns a value equal to \fIstring\fR except that all upper (or title)
492case letters have been converted to lower case. If \fIfirst\fR is
493specified, it refers to the first char index in the string to start
494modifying. If \fIlast\fR is specified, it refers to the char index in
495the string to stop at (inclusive). \fIfirst\fR and \fIlast\fR may be
496specified as for the \fBindex\fR method.
497.TP
498\fBstring totitle \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR?
499Returns a value equal to \fIstring\fR except that the first character
500in \fIstring\fR is converted to its Unicode title case variant (or
501upper case if there is no title case variant) and the rest of the
502string is converted to lower case. If \fIfirst\fR is specified, it
503refers to the first char index in the string to start modifying. If
504\fIlast\fR is specified, it refers to the char index in the string to
505stop at (inclusive). \fIfirst\fR and \fIlast\fR may be specified as
506for the \fBindex\fR method.
507.TP
508\fBstring toupper \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR?
509Returns a value equal to \fIstring\fR except that all lower (or title)
510case letters have been converted to upper case. If \fIfirst\fR is
511specified, it refers to the first char index in the string to start
512modifying. If \fIlast\fR is specified, it refers to the char index in
513the string to stop at (inclusive). \fIfirst\fR and \fIlast\fR may be
514specified as for the \fBindex\fR method.
515.TP
516\fBstring trim \fIstring\fR ?\fIchars\fR?
517Returns a value equal to \fIstring\fR except that any leading or
518trailing characters from the set given by \fIchars\fR are removed. If
519\fIchars\fR is not specified then white space is removed (spaces,
520tabs, newlines, and carriage returns).
521.TP
522\fBstring trimleft \fIstring\fR ?\fIchars\fR?
523Returns a value equal to \fIstring\fR except that any leading
524characters from the set given by \fIchars\fR are removed. If
525\fIchars\fR is not specified then white space is removed (spaces,
526tabs, newlines, and carriage returns).
527.TP
528\fBstring trimright \fIstring\fR ?\fIchars\fR?
529Returns a value equal to \fIstring\fR except that any trailing
530characters from the set given by \fIchars\fR are removed. If
531\fIchars\fR is not specified then white space is removed (spaces,
532tabs, newlines, and carriage returns).
533.TP
534\fBstring wordend \fIstring charIndex\fR
535Returns the index of the character just after the last one in the word
536containing character \fIcharIndex\fR of \fIstring\fR. \fIcharIndex\fR
537may be specified as for the \fBindex\fR method. A word is
538considered to be any contiguous range of alphanumeric (Unicode letters
539or decimal digits) or underscore (Unicode connector punctuation)
540characters, or any single character other than these.
541.TP
542\fBstring wordstart \fIstring charIndex\fR
543Returns the index of the first character in the word containing
544character \fIcharIndex\fR of \fIstring\fR. \fIcharIndex\fR may be
545specified as for the \fBindex\fR method. A word is considered to be any
546contiguous range of alphanumeric (Unicode letters or decimal digits)
547or underscore (Unicode connector punctuation) characters, or any
548single character other than these.
549.SH EXAMPLE
550Test if the string in the variable \fIstring\fR is a proper non-empty
551prefix of the string \fBfoobar\fR.
552.CS
553set length [\fBstring length\fR $string]
554if {$length == 0} {
555 set isPrefix 0
556} else {
557 set isPrefix [\fBstring equal\fR -length $string $string "foobar"]
558}
559.CE
560
561.SH "SEE ALSO"
562expr(n), list(n)
563
564.SH KEYWORDS
565case conversion, compare, index, match, pattern, string, word, equal, ctype