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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// First non-printable character
///
/// Return the index of the first non-printable character in a
/// character string. ASCII characters 32-126 are considered
/// printable by this routine. (Blanks are considered printable.)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// STRING I Input character string.
///
/// The function returns the index of first non-printable character in
/// STRING.
/// ```
///
/// # Detailed Input
///
/// ```text
/// STRING is the input character string.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the index of the first non-printable
/// character in the input string. Characters having integer codes
/// outside the range 32-126 are considered to be non-printable
/// characters. Blanks are considered to be printable characters. If
/// the input string contains no non-printable characters, FRSTNP is
/// zero.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine may be used to assist in validating strings that
/// are intended to be free of non-printable characters.
///
/// This routine treats blanks as printable characters. This choice
/// prevents embedded blanks from causing false positive results in
/// tests of strings for invalid characters. Note that the routine
/// FRSTPC and LASTPC treat blanks as non-printable.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) Find the first non-printable character in a given string,
/// considering blanks as printable characters.
///
///
/// Example code begins here.
///
///
/// PROGRAM FRSTNP_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// INTEGER FRSTNP
///
/// C
/// C Local variables
/// C
/// CHARACTER*10 S
///
/// C
/// C Add some random characters to the string, some of them
/// C non-printable.
/// C
/// S( 1: 1) = 'A'
/// S( 2: 2) = ' '
/// S( 3: 3) = CHAR ( 3 )
/// S( 4: 4) = 'A'
/// S( 5: 5) = 'B'
/// S( 6: 6) = 'C'
/// S( 7: 7) = CHAR ( 7 )
/// S( 8: 8) = CHAR ( 8 )
/// S( 9: 9) = CHAR ( 9 )
/// S(10:10) = ' '
///
/// WRITE (*,'(A,I2)') 'First non-printable character '
/// .// 'found at index', FRSTNP(S)
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// First non-printable character found at index 3
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 07-APR-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Created
/// complete code example from existing fragment.
///
/// - SPICELIB Version 1.0.0, 16-JUN-1995 (NJB) (IMU)
/// ```
pub fn frstnp(string: &str) -> i32 {
let ret = FRSTNP(string.as_bytes());
ret
}
//$Procedure FRSTNP ( First non-printable character )
pub fn FRSTNP(STRING: &[u8]) -> i32 {
let mut FRSTNP: i32 = 0;
//
// Local variables
//
//
// Look for the first character outside the range [32,126], and
// return its index.
//
for I in 1..=intrinsics::LEN(STRING) {
if ((intrinsics::ICHAR(fstr::substr(STRING, I..=I)) < 32)
|| (intrinsics::ICHAR(fstr::substr(STRING, I..=I)) > 126))
{
FRSTNP = I;
return FRSTNP;
}
}
//
// Still here? All characters are printable. Return zero.
//
FRSTNP = 0;
FRSTNP
}