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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Remove a substring
///
/// Remove the substring (LEFT:RIGHT) from a character string.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// IN I Input string.
/// LEFT I Position of first character to be removed.
/// RIGHT I Position of last character to be removed.
/// OUT O Output string.
/// ```
///
/// # Detailed Input
///
/// ```text
/// IN is an input character string, from which a substring
/// is to be removed.
///
/// LEFT,
/// RIGHT are the ends of the substring to be removed.
/// ```
///
/// # Detailed Output
///
/// ```text
/// OUT is the output string. This is equivalent to the
/// string that would be created by the concatenation
///
/// OUT = IN(1 : LEFT-1) // IN(RIGHT+1 : )
///
/// If the string is too long to fit into OUT, it is
/// truncated on the right.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If LEFT > RIGHT, RIGHT < 1, LEFT < 1, RIGHT > LEN(IN), or
/// LEFT > LEN(IN), the error SPICE(INVALIDINDEX) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// Move the characters, beginning with RIGHT, one at a time to the
/// positions immediately following LEFT. This has the same effect
/// as the concatenation
///
/// OUT = IN(1 : LEFT-1) // IN(RIGHT+1 : )
///
/// Because this operation is not standard for strings of length (*),
/// this routine does not use concatenation.
/// ```
///
/// # Examples
///
/// ```text
/// The following examples illustrate the use of REMSUB.
///
/// IN LEFT RIGHT OUT
/// ----------------- ---- ----- ------------------------
/// 'ABCDEFGHIJ' 3 5 'ABFGHIJ'
/// 'The best rabbit' 5 8 'The rabbit'
/// 'The other woman' 1 4 'other woman'
/// 'An Apple a day' 2 2 'A apple a day'
/// 'An Apple a day' 5 2 An error is signaled.
/// 'An Apple a day' 0 0 An error is signaled.
/// 'An Apple a day' -3 3 An error is signaled.
///
/// Whenever an error has been signaled, the contents of OUT are
/// unpredictable.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 20-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) (HAN)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 2.0.0, 05-JAN-1989 (HAN)
///
/// Error handling was added to detect invalid character
/// positions. If LEFT > RIGHT, RIGHT < 1, LEFT < 1,
/// RIGHT > LEN(IN), or LEFT > LEN(IN), an error is signaled.
/// ```
pub fn remsub(
ctx: &mut SpiceContext,
in_: &str,
left: i32,
right: i32,
out: &mut str,
) -> crate::Result<()> {
REMSUB(
in_.as_bytes(),
left,
right,
fstr::StrBytes::new(out).as_mut(),
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure REMSUB ( Remove a substring )
pub fn REMSUB(
IN: &[u8],
LEFT: i32,
RIGHT: i32,
OUT: &mut [u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut INLEN: i32 = 0;
let mut OUTLEN: i32 = 0;
let mut L: i32 = 0;
let mut R: i32 = 0;
let mut I: i32 = 0;
let mut J: i32 = 0;
//
// SPICELIB functions
//
//
// Other functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"REMSUB", ctx)?;
}
//
// If a character position is out of range, signal an error.
//
if (((((LEFT > RIGHT) || (RIGHT < 1)) || (LEFT < 1)) || (RIGHT > intrinsics::LEN(IN)))
|| (LEFT > intrinsics::LEN(IN)))
{
SETMSG(b"Left location was *. Right location was *.", ctx);
ERRINT(b"*", LEFT, ctx);
ERRINT(b"*", RIGHT, ctx);
SIGERR(b"SPICE(INVALIDINDEX)", ctx)?;
CHKOUT(b"REMSUB", ctx)?;
return Ok(());
} else {
L = LEFT;
R = RIGHT;
}
//
// How much of the input string will we use? And how big is the
// output string?
//
INLEN = LASTNB(IN);
OUTLEN = intrinsics::LEN(OUT);
//
// Copy the first part of the input string. (One character at a
// time, in case this is being done in place.)
//
{
let m1__: i32 = 1;
let m2__: i32 = intrinsics::MIN0(&[(L - 1), OUTLEN]);
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
fstr::assign(fstr::substr_mut(OUT, I..=I), fstr::substr(IN, I..=I));
I += m3__;
}
}
//
// Now move the rest of the string over.
//
I = L;
J = (R + 1);
while ((I <= OUTLEN) && (J <= INLEN)) {
fstr::assign(fstr::substr_mut(OUT, I..=I), fstr::substr(IN, J..=J));
I = (I + 1);
J = (J + 1);
}
//
// Pad with blanks, if necessary.
//
if (I <= OUTLEN) {
fstr::assign(fstr::substr_mut(OUT, I..), b" ");
}
CHKOUT(b"REMSUB", ctx)?;
Ok(())
}