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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Compress a character string
///
/// Compress a character string by removing occurrences of
/// more than N consecutive occurrences of a specified
/// character.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// DELIM I Delimiter to be compressed.
/// N I Maximum consecutive occurrences of DELIM.
/// INPUT I Input string.
/// OUTPUT O Compressed string.
/// ```
///
/// # Detailed Input
///
/// ```text
/// DELIM is the delimiter to be compressed out of the string.
/// This may be any ASCII character.
///
/// N is the maximum number of consecutive occurrences
/// of DELIM that will be allowed to remain in the
/// output string.
///
/// INPUT is the input string.
/// ```
///
/// # Detailed Output
///
/// ```text
/// OUTPUT is the output string. This is the input string
/// with all occurrences of more than N consecutive
/// delimiters removed.
///
/// If OUTPUT is not large enough to hold the
/// compressed string, it is truncated on the right.
///
/// OUTPUT may overwrite INPUT.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
///
/// 1) If the output string length is too short to contain the result
/// of compressing the input string, the result is truncated on
/// the right.
/// ```
///
/// # Particulars
///
/// ```text
/// Occurrences of more than N consecutive delimiters are removed
/// from the input string as it is copied to the output string.
/// If the output string is not large enough to hold the compressed
/// string, it is truncated on the right.
/// ```
///
/// # Examples
///
/// ```text
/// Let DELIM = '.', and N = 2. Then
///
/// 'ABC...DE.F...', becomes 'ABC..DE.F..'
/// ' ...........' ' ..'
/// '.. ..AB....CD' '.. ..AB..CD'
///
/// Let DELIM = ' ', and N = 0. Then
///
/// ' DISK:[USER. SUB ]' becomes 'DISK:[USER.SUB]'
/// ```
///
/// # 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, 09-JUL-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// Added $Exceptions entry #1.
///
/// - 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 cmprss(delim: char, n: i32, input: &str, output: &mut str) {
CMPRSS(
&[u8::try_from(delim).unwrap()],
n,
input.as_bytes(),
fstr::StrBytes::new(output).as_mut(),
);
}
//$Procedure CMPRSS ( Compress a character string )
pub fn CMPRSS(DELIM: &[u8], N: i32, INPUT: &[u8], OUTPUT: &mut [u8]) {
let DELIM = &DELIM[..1];
let mut J: i32 = 0;
let mut COUNT: i32 = 0;
let mut INLEN: i32 = 0;
let mut OUTLEN: i32 = 0;
//
//
// Local Variables
//
//
// Find out how much space there is in the INPUT and OUTPUT strings
// and initialize the delimiter counter and output place holder.
//
INLEN = intrinsics::LEN(INPUT);
OUTLEN = intrinsics::LEN(OUTPUT);
COUNT = 0;
J = 0;
for I in 1..=INLEN {
//
// Check each character to see if it is a delimiter or not.
//
if fstr::eq(fstr::substr(INPUT, I..=I), DELIM) {
COUNT = (COUNT + 1);
//
// Copy delimiters until enough consecutive delimiters
// have been accumulated. When enough consecutive delimiters
// have accumulated, we no longer copy them.
//
if (COUNT <= N) {
J = (J + 1);
fstr::assign(fstr::substr_mut(OUTPUT, J..=J), fstr::substr(INPUT, I..=I));
}
} else {
//
// We don't have a delimiter here so we just copy the
// character and set the delimiter counter to zero.
//
COUNT = 0;
J = (J + 1);
fstr::assign(fstr::substr_mut(OUTPUT, J..=J), fstr::substr(INPUT, I..=I));
}
if (J == OUTLEN) {
return;
}
}
//
// Pad any left over space in the output string with blanks.
//
if (J < OUTLEN) {
fstr::assign(fstr::substr_mut(OUTPUT, (J + 1)..), b" ");
}
}