str_funcs.cpp

Go to the documentation of this file.
00001 /* ============================================================================
00002 "str_funcs.cpp" defines various string manipulation functions:
00003         fits_str_cull - Removes leading and trailing quotes from a FITS
00004                         header card string.
00005 ============================================================================ */
00006 #include <ctype.h>
00007 #include <string.h>
00008 #include <stdlib.h>
00009 /* ----------------------------------------------------------------------------
00010 'fits_str_cull' Removes leading and trailing quotes from a FITS header
00011 card string.  It also removes leading and trailing white space from the string.
00012 
00013 Arguments:
00014         str - The string to process.  It IS modified by this function.
00015 
00016 Returned:
00017         The processed string.
00018 
00019 Written by Michael R. Greason, ADNET, 08 January 2007.
00020 ---------------------------------------------------------------------------- */
00021 char *fits_str_cull (char *str)
00022 {
00023         char *p, *d;
00024         int  flg, n;
00025 /*
00026                         Trivial case---NULL or empty string.
00027 */
00028         if ((str == NULL) || ((n = strlen(str)) <= 0)) return str;
00029 /*
00030                         Search for a leading quote.
00031 */
00032         flg = 0;
00033         p = str;
00034         while (*p != '\0')
00035         {
00036                 if ((*p == '\"') || (*p == '\''))
00037                 {
00038                         flg = 1;
00039                         *p  = ' ';
00040                         break;
00041                 }
00042                 ++p;
00043         }
00044 /*
00045                         Remove trailing white space.  At the same time and if a
00046                         leading quote was found, remove a trailing quote.
00047 */
00048         p = str + n - 1;
00049         while (--n >= 0)
00050         {
00051                 if (isspace(*p) != 0)
00052                 {
00053                         *(p--) = '\0';
00054                         continue;
00055                 }
00056                 if ((flg != 0) && ((*p == '\"') || (*p == '\'')))
00057                 {
00058                         *(p--) = '\0';
00059                         continue;
00060                 }
00061                 break;
00062         }
00063 /*
00064                         Remove leading white space.
00065 */
00066         n = 0;
00067         d = p = str;
00068         while ((*p != '\0') && (isspace(*p) != 0)) ++p;
00069         if (*p == '\0') return str;
00070         while (*p != '\0') *d++ = *p++;
00071         *d = '\0';
00072 
00073         return str;
00074 }

Generated on Fri Feb 6 15:32:42 2009 for Skyviewer by  doxygen 1.4.7