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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// STRIP Ascii characters from a string
///
/// Remove from a character string all characters which fall
/// between specified starting and ending characters, inclusive.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// INSTR I Input string.
/// ASCIIB I First ASCII character in range to be stripped.
/// ASCIIE I Last ASCII character in range to be stripped.
/// OUTSTR O Output (stripped) string.
/// ```
///
/// # Detailed Input
///
/// ```text
/// INSTR is a character string from which all characters
/// between ASCIIB and ASCIIE, inclusive, are to be
/// removed.
///
/// ASCIIB is the first ASCII character in the range of
/// characters to be removed from the input string.
/// ASCIIB is itself removed from the string, if
/// it occurs.
///
/// ASCIIE is the last ASCII character in the range of
/// characters to be removed from the input string.
/// ASCIIE is itself removed from the string, if
/// it occurs.
/// ```
///
/// # Detailed Output
///
/// ```text
/// OUTSTR is the input string after all the character
/// between ASCIIB and ASCIIE, inclusive, have
/// been removed.
///
/// If OUTSTR is not large enough to hold the output
/// string, it is truncated on the right.
///
/// OUTSTR may overwrite INSTR.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
/// ```
///
/// # Particulars
///
/// ```text
/// ASTRIP checks each character
/// in INSTR to determine if it falls between the characters ASCIIB
/// and ASCIIE. If so this character is removed from the string
/// (and the string is shortened). Remaining characters are copied
/// to the output string.
/// ```
///
/// # Examples
///
/// ```text
/// The following examples illustrate the use of ASTRIP.
///
/// ASCIIB = 'b'
/// ASCIIE = 'k'
/// INSTR = 'Now is the time for all good men to come quick.'
/// OUTSTR = 'Now s t tm or all oo mn to om qu.'
///
/// ASCIIB = 'a'
/// ASCIIE = 'z'
/// INSTR = 'SELECT column TIME FROM table TEST'
/// OUTSTR = 'SELECT TIME FROM TEST'
///
/// ASCIIB = 'a'
/// ASCIIE = 'z'
/// INSTR = 'this is going to be an empty string'
/// OUTSTR = ' '
///
/// ASCIIB = '!'
/// ASCIIE = '!'
/// INSTR = 'Only 32 more shopping days until Christmas!'
/// OUTSTR = 'Only 32 more shopping days until Christmas'
///
/// ASTRIP may also be used to strip ASCII control characters
/// (line feeds, tab stops, and so on), as shown in the example
/// below.
///
/// ASCIIB = CHAR ( 0 )
/// ASCIIE = CHAR ( 31 )
/// CALL ASTRIP ( STRING, ASCIIB, ASCIIE, STRING )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) If ASCIIB and ASCIIE are not properly ordered (that is,
/// if ICHAR(ASCIIB) is not less than or equal to ICHAR(ASCIIE))
/// then ASTRIP will not function as described. (In fact, it will
/// copy the input string to the output string without change.)
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 12-AUG-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - 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 (WLT) (IMU)
/// ```
pub fn astrip(instr: &str, asciib: char, asciie: char, outstr: &mut str) {
ASTRIP(
instr.as_bytes(),
&[u8::try_from(asciib).unwrap()],
&[u8::try_from(asciie).unwrap()],
fstr::StrBytes::new(outstr).as_mut(),
);
}
//$Procedure ASTRIP ( STRIP Ascii characters from a string )
pub fn ASTRIP(INSTR: &[u8], ASCIIB: &[u8], ASCIIE: &[u8], OUTSTR: &mut [u8]) {
let ASCIIB = &ASCIIB[..1];
let ASCIIE = &ASCIIE[..1];
let mut OUTLEN: i32 = 0;
let mut LAST: i32 = 0;
let mut LWRBND: i32 = 0;
let mut UPRBND: i32 = 0;
let mut J: i32 = 0;
let mut K: i32 = 0;
//
// SPICELIB functions
//
//
// Local Variables
//
//
// Find the length of the output string. We don't want to
// exceed it.
//
OUTLEN = intrinsics::LEN(OUTSTR);
//
// Find the last non-blank character of the input string.
//
LAST = LASTNB(INSTR);
//
// Get the numeric representation of ASCIIB and ASCIIE.
//
LWRBND = intrinsics::ICHAR(ASCIIB);
UPRBND = intrinsics::ICHAR(ASCIIE);
//
// Step through INSTR (I) a character at a time, transferring
// characters to OUTSTR (J) whenever they fall outside the range
// [ASCIIB, ASCIIE].
//
// If the end of OUTSTR is reached, stop transferring characters
// and return.
//
J = 0;
for I in 1..=LAST {
K = intrinsics::ICHAR(fstr::substr(INSTR, I..=I));
if ((K < LWRBND) || (K > UPRBND)) {
//
// The character is kept. Note that if the user inputs
// ASCIIB and ASCIIE in the wrong order this test will
// always succeed so that the output string will be
// the same as the input string.
//
J = (J + 1);
fstr::assign(fstr::substr_mut(OUTSTR, J..=J), fstr::substr(INSTR, I..=I));
if (J == OUTLEN) {
return;
}
}
}
//
// Pad the output string with blanks.
//
if (J < OUTLEN) {
fstr::assign(fstr::substr_mut(OUTSTR, (J + 1)..), b" ");
}
}