Better documentation.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7048 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Pierre Weis 2005-09-13 11:26:06 +00:00
parent fbf58963a8
commit 026ff6d482
1 changed files with 17 additions and 20 deletions

View File

@ -140,32 +140,27 @@ val bscanf :
the format specified by the second letter. the format specified by the second letter.
- [\[ range \]]: reads characters that matches one of the characters - [\[ range \]]: reads characters that matches one of the characters
mentioned in the range of characters [range] (or not mentioned in mentioned in the range of characters [range] (or not mentioned in
it, if the range starts with [^]). Returns a [string] that can be it, if the range starts with [^]). Reads a [string] that can be
empty, if no character in the input matches the range. Hence, empty, if no character in the input matches the range. The set of
[\[0-9\]] returns a string representing a decimal number or an empty characters from [c1] to [c2] (inclusively) is denoted by [c1-c2].
string if no decimal digit is found. Hence, [%\[0-9\]] returns a string representing a decimal number
or an empty string if no decimal digit is found; similarly,
[%\[\\048-\\057\\065-\\070\]] returns a string of hexadecimal digits.
If a closing bracket appears in a range, it must occur as the If a closing bracket appears in a range, it must occur as the
first character of the range (or just after the [^] in case of first character of the range (or just after the [^] in case of
range negation); hence [\[\]\]] matches a [\]] character and range negation); hence [\[\]\]] matches a [\]] character and
[\[^\]\]] matches any character that is not [\]]. [\[^\]\]] matches any character that is not [\]].
- [\{ fmt %\}]: reads a format string argument that matches - [\{ fmt %\}]: reads a format string that must have the same
the internal format string specification [fmt]. type as the format string [fmt].
The [fmt] character string defines the conversion The argument is read according to the lexical conventions for
specification sequence that in turn states the format type [t] of the format strings described here.
argument returned.
The argument is read according to the lexical conventions of Caml
for format strings, and must have a type compatible with [t],
otherwise the exception [Scan_failure] is raised.
For instance, "%\{%i%\}" reads any format string that can read a value of For instance, "%\{%i%\}" reads any format string that can read a value of
type [int]; hence [Scanf.sscanf "fmt:\\\"number is %u\\\"" "fmt:%\{%i%\}"] type [int]; hence [Scanf.sscanf "fmt:\\\"number is %u\\\"" "fmt:%\{%i%\}"]
succeeds and returns the format string ["number is %u"]. succeeds and returns the format string ["number is %u"].
- [\( fmt %\)]: scanning format insertion. - [\( fmt %\)]: scanning format substitution.
This conversion reads a format string specified by [fmt] with This conversion specifies a format string that should be read in the
the same conventions as the [\{ fmt %\}] conversion above. input to replace [fmt]. The format string read must have the same
After successful reading of a format string compatible with type as [fmt].
[fmt], the scanning process goes on, first scanning according to
the very format string read, then resuming as usual to the
following conversions.
- [l]: applies [f] to the number of lines read so far. - [l]: applies [f] to the number of lines read so far.
- [n]: applies [f] to the number of characters read so far. - [n]: applies [f] to the number of characters read so far.
- [N] or [L]: applies [f] to the number of tokens read so far. - [N] or [L]: applies [f] to the number of tokens read so far.
@ -179,7 +174,9 @@ val bscanf :
The field widths are composed of an optional integer literal The field widths are composed of an optional integer literal
indicating the maximal width of the token to read. indicating the maximal width of the token to read.
For instance, [%6d] reads an integer, having at most 6 decimal digits; For instance, [%6d] reads an integer, having at most 6 decimal digits;
and [%4f] reads a float with at most 4 characters. [%4f] reads a float with at most 4 characters; and [%8\[\\000-\\255\]]
returns the next 8 characters (or all the characters still available,
if less than 8 characters are available in the input).
Scanning indications appear just after the string conversions [s] Scanning indications appear just after the string conversions [s]
and [\[ range \]] to delimit the end of the token. A scanning and [\[ range \]] to delimit the end of the token. A scanning