-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstr_funcs.cpp
More file actions
74 lines (70 loc) · 1.68 KB
/
str_funcs.cpp
File metadata and controls
74 lines (70 loc) · 1.68 KB
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
/* ============================================================================
"str_funcs.cpp" defines various string manipulation functions:
fits_str_cull - Removes leading and trailing quotes from a FITS
header card string.
============================================================================ */
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
/* ----------------------------------------------------------------------------
'fits_str_cull' Removes leading and trailing quotes from a FITS header
card string. It also removes leading and trailing white space from the string.
Arguments:
str - The string to process. It IS modified by this function.
Returned:
The processed string.
Written by Michael R. Greason, ADNET, 08 January 2007.
---------------------------------------------------------------------------- */
char *fits_str_cull (char *str)
{
char *p, *d;
int flg, n;
/*
Trivial case---NULL or empty string.
*/
if ((str == NULL) || ((n = strlen(str)) <= 0)) return str;
/*
Search for a leading quote.
*/
flg = 0;
p = str;
while (*p != '\0')
{
if ((*p == '\"') || (*p == '\''))
{
flg = 1;
*p = ' ';
break;
}
++p;
}
/*
Remove trailing white space. At the same time and if a
leading quote was found, remove a trailing quote.
*/
p = str + n - 1;
while (--n >= 0)
{
if (isspace(*p) != 0)
{
*(p--) = '\0';
continue;
}
if ((flg != 0) && ((*p == '\"') || (*p == '\'')))
{
*(p--) = '\0';
continue;
}
break;
}
/*
Remove leading white space.
*/
n = 0;
d = p = str;
while ((*p != '\0') && (isspace(*p) != 0)) ++p;
if (*p == '\0') return str;
while (*p != '\0') *d++ = *p++;
*d = '\0';
return str;
}