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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Right justify a character string
///
/// Right justify a character string.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// INPUT I Input character string.
/// OUTPUT O Output character string, right justified.
/// ```
///
/// # Detailed Input
///
/// ```text
/// INPUT is the input character string.
/// ```
///
/// # Detailed Output
///
/// ```text
/// OUTPUT is the output character string, right justified.
/// If INPUT is too large to fit into OUTPUT, it is
/// truncated on the left.
///
/// OUTPUT may overwrite INPUT.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
/// ```
///
/// # Particulars
///
/// ```text
/// Any trailing blanks in the input string are removed, and
/// the remaining string is copied to the output string.
/// ```
///
/// # Examples
///
/// ```text
/// The following examples should illustrate the use of RJUST.
///
/// 'ABCDE ' becomes ' ABCDE'
/// 'AN EXAMPLE ' ' AN EXAMPLE'
/// ' AN EXAMPLE ' ' AN EXAMPLE'
/// ' ' ' '
/// ```
///
/// # 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 (IMU)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 1.1.0, 11-DEC-1989 (IMU)
///
/// Did not work on Sun when INPUT and OUTPUT were
/// the same string, and where the initial and final
/// locations of the non-blank part of the string
/// overlapped.
///
/// The solution is to move the characters one by one,
/// starting from the right side of the input string.
/// That way, nothing gets clobbered.
/// ```
pub fn rjust(input: &str, output: &mut str) {
RJUST(input.as_bytes(), fstr::StrBytes::new(output).as_mut());
}
//$Procedure RJUST ( Right justify a character string )
pub fn RJUST(INPUT: &[u8], OUTPUT: &mut [u8]) {
let mut FIRST: i32 = 0;
let mut LAST: i32 = 0;
let mut LOC: i32 = 0;
let mut START: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Blank string? It's all the same.
//
if fstr::eq(INPUT, b" ") {
fstr::assign(OUTPUT, INPUT);
//
// Get the first non-blank character. Start OUTPUT at that point.
//
} else {
FIRST = FRSTNB(INPUT);
LAST = LASTNB(INPUT);
START = (intrinsics::LEN(OUTPUT) - (LAST - FIRST));
//
// If the input string is too long (START < 1), move FIRST
// up a little to truncate on the left.
//
if (START < 1) {
FIRST = (FIRST + (1 - START));
START = 1;
}
//
// Move the characters in reverse order, to keep from stomping
// anything if the operation is being done in place.
//
LOC = intrinsics::LEN(OUTPUT);
for I in intrinsics::range(LAST, FIRST, -1) {
fstr::assign(
fstr::substr_mut(OUTPUT, LOC..=LOC),
fstr::substr(INPUT, I..=I),
);
LOC = (LOC - 1);
}
//
// Clear the first part of OUTPUT, if necessary.
//
if (START > 1) {
fstr::assign(fstr::substr_mut(OUTPUT, 1..=(START - 1)), b" ");
}
}
}