64
66
<link title="Sys" rel="Chapter" href="Sys.html">
65
67
<link title="Thread" rel="Chapter" href="Thread.html">
66
68
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
69
<link title="Tk" rel="Chapter" href="Tk.html">
67
70
<link title="Unix" rel="Chapter" href="Unix.html">
68
71
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
69
72
<link title="Weak" rel="Chapter" href="Weak.html"><title>Scanf.Scanning</title>
74
77
<center><h1>Module <a href="type_Scanf.Scanning.html">Scanf.Scanning</a></h1></center>
76
<pre><span class="keyword">module</span> Scanning: <code class="code"><span class="keyword">sig</span></code> <a href="Scanf.Scanning.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>Scanning buffers.<br>
79
<pre><span class="keyword">module</span> Scanning: <code class="code"><span class="keyword">sig</span></code> <a href="Scanf.Scanning.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><a name="6_Scanningbuffers"></a>
80
<h6>Scanning buffers</h6><br>
78
82
<pre><span class="keyword">type</span> <a name="TYPEscanbuf"></a><code class="type"></code>scanbuf </pre>
80
The type of scanning buffers. A scanning buffer is the argument passed
81
to the scanning functions used by the <code class="code">scanf</code> family of functions.
82
The scanning buffer holds the current state of the scan, plus
83
a function to get the next char from the input, and a token buffer
84
to store the string matched so far.<br>
84
The type of scanning buffers. A scanning buffer is the source from which a
85
formatted input function gets characters. The scanning buffer holds the
86
current state of the scan, plus a function to get the next char from the
87
input, and a token buffer to store the string matched so far.
90
Note: a scan may often require to examine one character in advance;
91
when this ``lookahead'' character does not belong to the token read,
92
it is stored back in the scanning buffer and becomes the next
87
96
<pre><span class="keyword">val</span> <a name="VALstdib"></a>stdib : <code class="type"><a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a></code></pre><div class="info">
88
97
The scanning buffer reading from <code class="code">stdin</code>.
89
<code class="code">stdib</code> is equivalent to <code class="code"><span class="constructor">Scanning</span>.from_channel stdin</code>.<br>
98
<code class="code">stdib</code> is equivalent to <code class="code"><span class="constructor">Scanning</span>.from_channel stdin</code>.
101
Note: when input is read interactively from <code class="code">stdin</code>, the newline character
102
that triggers the evaluation is incorporated in the input; thus, scanning
103
specifications must properly skip this character (simply add a <code class="code"><span class="string">'\n'</span></code>
104
as the last character of the format string).<br>
91
106
<pre><span class="keyword">val</span> <a name="VALfrom_string"></a>from_string : <code class="type">string -> <a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a></code></pre><div class="info">
92
<code class="code"><span class="constructor">Scanning</span>.from_string s</code> returns a scanning buffer which reads
93
from the given string.
107
<code class="code"><span class="constructor">Scanning</span>.from_string s</code> returns a scanning buffer which reads from the
94
109
Reading starts from the first character in the string.
95
110
The end-of-input condition is set when the end of the string is reached.<br>
97
112
<pre><span class="keyword">val</span> <a name="VALfrom_file"></a>from_file : <code class="type">string -> <a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a></code></pre><div class="info">
98
113
Bufferized file reading in text mode. The efficient and usual
99
114
way to scan text mode files (in effect, <code class="code">from_file</code> returns a
100
buffer that reads characters in large chunks, rather than one
115
scanning buffer that reads characters in large chunks, rather than one
101
116
character at a time as buffers returned by <code class="code">from_channel</code> do).
102
117
<code class="code"><span class="constructor">Scanning</span>.from_file fname</code> returns a scanning buffer which reads
103
118
from the given file <code class="code">fname</code> in text mode.<br>
106
121
Bufferized file reading in binary mode.<br>
108
123
<pre><span class="keyword">val</span> <a name="VALfrom_function"></a>from_function : <code class="type">(unit -> char) -> <a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a></code></pre><div class="info">
109
<code class="code"><span class="constructor">Scanning</span>.from_function f</code> returns a scanning buffer with
110
the given function as its reading method.
124
<code class="code"><span class="constructor">Scanning</span>.from_function f</code> returns a scanning buffer with the given
125
function as its reading method.
111
128
When scanning needs one more character, the given function is called.
112
When the function has no more character to provide, it must signal
113
an end-of-input condition by raising the exception <code class="code"><span class="constructor">End_of_file</span></code>.<br>
131
When the function has no more character to provide, it must signal an
132
end-of-input condition by raising the exception <code class="code"><span class="constructor">End_of_file</span></code>.<br>
115
134
<pre><span class="keyword">val</span> <a name="VALfrom_channel"></a>from_channel : <code class="type"><a href="Pervasives.html#TYPEin_channel">in_channel</a> -> <a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a></code></pre><div class="info">
116
135
<code class="code"><span class="constructor">Scanning</span>.from_channel ic</code> returns a scanning buffer which reads
118
137
current reading position.<br>
120
139
<pre><span class="keyword">val</span> <a name="VALend_of_input"></a>end_of_input : <code class="type"><a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a> -> bool</code></pre><div class="info">
121
<code class="code"><span class="constructor">Scanning</span>.end_of_input ib</code> tests the end-of-input condition
122
of the given buffer.<br>
140
<code class="code"><span class="constructor">Scanning</span>.end_of_input ib</code> tests the end-of-input condition of the given
124
143
<pre><span class="keyword">val</span> <a name="VALbeginning_of_input"></a>beginning_of_input : <code class="type"><a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a> -> bool</code></pre><div class="info">
125
<code class="code"><span class="constructor">Scanning</span>.beginning_of_input ib</code> tests the beginning of input
126
condition of the given buffer.<br>
144
<code class="code"><span class="constructor">Scanning</span>.beginning_of_input ib</code> tests the beginning of input condition of
145
the given scanning buffer.<br>
128
147
<pre><span class="keyword">val</span> <a name="VALname_of_input"></a>name_of_input : <code class="type"><a href="Scanf.Scanning.html#TYPEscanbuf">scanbuf</a> -> string</code></pre><div class="info">
129
<code class="code"><span class="constructor">Scanning</span>.file_name_of_input ib</code> returns the name of the character
130
source for the input buffer <code class="code">ib</code>.<br>
148
<code class="code"><span class="constructor">Scanning</span>.file_name_of_input ib</code> returns the name of the character source
149
for the scanning buffer <code class="code">ib</code>.<br>
b'\\ No newline at end of file'