home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
400-499
/
ff473.lzh
/
CNewsSrc
/
cnews_src.lzh
/
man
/
split.man
< prev
next >
Wrap
Text File
|
1991-01-05
|
4KB
|
133 lines
SPLIT(3) C LIBRARY FUNCTIONS SPLIT(3)
NNNNAAAAMMMMEEEE
split - split string into fields
SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
iiiinnnntttt sssspppplllliiiitttt((((ssssttttrrrriiiinnnngggg,,,, ffffiiiieeeellllddddssss,,,, nnnnffffiiiieeeellllddddssss,,,, sssseeeeppppaaaarrrraaaattttoooorrrrssss))))
cccchhhhaaaarrrr ****ssssttttrrrriiiinnnngggg;;;;
cccchhhhaaaarrrr ****ffffiiiieeeellllddddssss[[[[]]]];;;;
iiiinnnntttt nnnnffffiiiieeeellllddddssss;;;;
cccchhhhaaaarrrr ****sssseeeeppppaaaarrrraaaattttoooorrrrssss;;;;
DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
_S_p_l_i_t splits the _s_t_r_i_n_g into _f_i_e_l_d_s according to the _s_e_p_a_r_a_-
_t_o_r_s, much in the manner of _a_w_k(1)'s field facilities.
_S_t_r_i_n_g has NUL s written into it to do the splitting, and
pointers to the resulting strings are placed into the _f_i_e_l_d_s
array, up to the number specified by _n_f_i_e_l_d_s. If the number
of fields found exceeds _n_f_i_e_l_d_s, the writing of NUL s stops,
so that the last entry in _f_i_e_l_d_s points to the remainder of
the string.
The returned value is the number of fields present in
_s_t_r_i_n_g, which may exceed _n_f_i_e_l_d_s. If the returned value is
less than _n_f_i_e_l_d_s, the contents of the remaining entries in
_f_i_e_l_d_s (up to the limit set by _n_f_i_e_l_d_s) are undefined.
(Note, in particular, that _s_p_l_i_t does not terminate the list
of fields with a NULL pointer.)
If _s_e_p_a_r_a_t_o_r_s is a string of length 1, that character is the
separator: each occurrence of it separates the current
field from a new field, which may be of length 0 if another
separator follows immediately.
If _s_e_p_a_r_a_t_o_r_s is a string of length >1, all the characters
in it are separators: any sequence of characters composed
entirely of separators separates the current field from a
new field, which is of length 0 only if it is at the begin-
ning or end of the _s_t_r_i_n_g. Characters may be duplicated in
_s_e_p_a_r_a_t_o_r_s; in particular, a _s_e_p_a_r_a_t_o_r_s string consisting of
the same character twice gives fields separated by sequences
of that character.
As a special case, if _s_e_p_a_r_a_t_o_r_s is a string of length 0,
sequences of white-space characters (here defined as blanks
and tabs) are the separators, and sequences of separators at
the beginning or end of the _s_t_r_i_n_g are ignored, so there can
be no fields of length 0.
In all cases, an empty _s_t_r_i_n_g (or, in the case of a _s_e_p_a_r_a_-
_t_o_r_s of length 0, a _s_t_r_i_n_g consisting only of white space)
has 0 fields.
Sun Microsystems Last change: 8 Dec 1990 1
SPLIT(3) C LIBRARY FUNCTIONS SPLIT(3)
SSSSEEEEEEEE AAAALLLLSSSSOOOO
awk(1), regexp(3), strtok(3)
HHHHIIIISSSSTTTTOOOORRRRYYYY
Written at University of Toronto by Henry Spencer, with con-
tributions from Geoff Collyer and Mark Moraes.
BBBBUUUUGGGGSSSS
Too many different decisions are bundled into the single
_s_e_p_a_r_a_t_o_r_s argument. Arguably it should be a regular
expression instead.
Specifying several characters as _s_e_p_a_r_a_t_o_r_s is rather inef-
ficient; if speed is a priority in such a case, it is better
to custom-build code that knows about the particular separa-
tors desired.
Sun Microsystems Last change: 8 Dec 1990 2