1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Word Count
///
/// Return the number of words in a string.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// STRING I Input character string.
///
/// The function returns the number of words in the input string
/// STRING.
/// ```
///
/// # Detailed Input
///
/// ```text
/// STRING is the input string to be parsed. It contains some number
/// of words, where a word is any string of consecutive
/// non-blank characters delimited by a blank or by either
/// end of the string.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the number of words in the input character
/// string STRING.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
/// ```
///
/// # Particulars
///
/// ```text
/// WDCNT, like NTHWD and NEXTWD, is useful primarily for parsing
/// input commands consisting of one or more words, where a word is
/// defined to be any sequence of consecutive non-blank characters
/// delimited by either a blank or by either end of the string.
/// ```
///
/// # Examples
///
/// ```text
/// The following examples illustrate the use of WDCNT.
///
/// WDCNT ( 'Now is the time' ) = 4
/// WDCNT ( ' for all ' ) = 2
/// WDCNT ( 'good,men.to_come' ) = 1
/// WDCNT ( ' ' ) = 0
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.2.0, 08-APR-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.1.0, 10-JAN-2005 (EDW)
///
/// Added logic to prevent the evaluation of STRING(LOC:LOC)
/// if LOC exceeds the length of string. Functionally, the
/// evaluation had no effect on WDCNT's output, but the NAG
/// F95 compiler flagged the evaluation as an array
/// overrun error. This occurred because given:
///
/// A .AND. B
///
/// NAG evaluates A then B then performs the logical
/// comparison.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (IMU)
/// ```
pub fn wdcnt(string: &str) -> i32 {
let ret = WDCNT(string.as_bytes());
ret
}
//$Procedure WDCNT ( Word Count )
pub fn WDCNT(STRING: &[u8]) -> i32 {
let mut WDCNT: i32 = 0;
let mut N: i32 = 0;
let mut LOC: i32 = 0;
let mut LENGTH: i32 = 0;
let mut CONT: bool = false;
//
// Local variables
//
//
// This is just NTHWD, except that it keeps looking until
// it finds the last word.
//
//
// Trivial case first.
//
if fstr::eq(STRING, b" ") {
WDCNT = 0;
return WDCNT;
} else {
LENGTH = intrinsics::LEN(STRING);
}
//
// Skip leading blanks.
//
LOC = 1;
while fstr::eq(fstr::substr(STRING, LOC..=LOC), b" ") {
LOC = (LOC + 1);
}
//
// Keep stepping through STRING, counting words as we go.
// (The current word is ended whenever a blank is encountered.)
// Quit when the end of the string is reached.
//
// N is the number of words found so far.
// LOC is the current location in STRING.
//
N = 1;
while (LOC < LENGTH) {
LOC = (LOC + 1);
//
// Blank signals end of the current word.
//
if fstr::eq(fstr::substr(STRING, LOC..=LOC), b" ") {
//
// Skip ahead to the next word. Ensure no
// evaluation of STRING(LOC:LOC) when
// LOC = LENGTH+1.
//
CONT = (LOC <= LENGTH);
if CONT {
CONT = (CONT && fstr::eq(fstr::substr(STRING, LOC..=LOC), b" "));
}
while CONT {
LOC = (LOC + 1);
CONT = (LOC <= LENGTH);
if CONT {
CONT = (CONT && fstr::eq(fstr::substr(STRING, LOC..=LOC), b" "));
}
}
//
// If not at the end of the string, we have another word.
//
if (LOC <= LENGTH) {
N = (N + 1);
}
}
}
//
// Return the number of words found.
//
WDCNT = N;
WDCNT
}