home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / SCL.EXE / STEPSTRI.CPP < prev    next >
Text File  |  1994-08-06  |  3KB  |  131 lines

  1.  
  2. /*
  3. * NIST STEP Core Class Library
  4. * clstepcore/STEPstring.cc
  5. * February, 1994
  6. * KC Morris
  7.  
  8. * Development of this software was funded by the United States Government,
  9. * and is not subject to copyright.
  10. */
  11.  
  12. /* $Id: STEPstring.cc,v 2.0.1.1 1994/04/05 16:39:51 sauderd Exp $ */
  13.  
  14. #include <STEPstring.h>
  15. #include <strstream.h>
  16.  
  17. void 
  18. SdaiString::STEPwrite (ostream& out) const
  19. {
  20.     const char *str = 0;
  21.     if (is_null ())
  22.     out << "$";
  23.     else
  24.     {
  25.     out << "\'";
  26.     str = chars ();
  27.     while (*str)
  28.     {
  29.         if(*str == STRING_DELIM)
  30.         out << STRING_DELIM;
  31.         out << *str;
  32.         str++;
  33.     }
  34.     out << "\'";
  35.     }
  36. }
  37.  
  38. void 
  39. SdaiString::STEPwrite (SCLstring &s) const
  40. {
  41.     const char *str = 0;
  42.     if (is_null ())
  43.     {
  44. //    s.set_null(); // this would free up space? nope
  45.     s = "$";
  46.     }
  47.     else
  48.     {
  49.     s = "\'";
  50.     str = chars ();
  51.     while (*str)
  52.     {
  53.         if(*str == STRING_DELIM)
  54.         s.Append(STRING_DELIM);
  55.         s.Append(*str);
  56.         str++;
  57.     }
  58.     s.Append(STRING_DELIM);
  59.     }
  60. }
  61.  
  62. Severity
  63. SdaiString::StrToVal (const char * s)
  64. {
  65.   operator= (s);
  66.   if (! strcmp (chars (),  s))  return SEVERITY_NULL ; 
  67.   else return SEVERITY_INPUT_ERROR; 
  68. }
  69.  
  70. //  STEPread reads a string in exchange file format
  71. //  starting with a single quote
  72. Severity 
  73. SdaiString::STEPread (istream& in, ErrorDescriptor *err)
  74. {
  75.     int foundEndQuote = 0; // need so this string is not ok: 'hi''
  76.     set_null ();  // clear the old string
  77.     char c;
  78.     in >> ws; // skip white space
  79.     in >> c;
  80.  
  81.     // remember the current format state to restore the previous settings
  82.     long int flags = in.flags();
  83.     in.unsetf(ios::skipws);
  84.  
  85.     if (c == STRING_DELIM)
  86.     {
  87.     while( (c != '\0') && in.good() && in.get(c) )
  88.     {
  89.         if (c == STRING_DELIM)   {
  90.         in.get (c);
  91.         if( ! in.good() )
  92.         {    // it is the final quote and no extra char was read
  93.             foundEndQuote = 1;
  94.             c = '\0';
  95.         }
  96.         else if( !(c == STRING_DELIM) )
  97.         {    // it is the final quote and extra char was read
  98.             in.putback (c); // put back non-quote extra char
  99.             foundEndQuote = 1;
  100.             c = '\0';
  101.         }
  102.         else { ; } // do nothing it is an embedded quote
  103.         } 
  104.         Append (c);
  105.     }
  106.     Append ('\0');
  107.  
  108.     if(foundEndQuote)
  109.         return SEVERITY_NULL;
  110.     else
  111.     {    // non-recoverable error
  112.         err->AppendToDetailMsg("Missing closing quote on string value.\n");
  113.         err->AppendToUserMsg("Missing closing quote on string value.\n");
  114.         err->GreaterSeverity(SEVERITY_INPUT_ERROR);
  115.         return SEVERITY_INPUT_ERROR;
  116.     }
  117.     }
  118.     //  otherwise there was not a quote
  119.     in.putback (c);
  120.     in.flags(flags); // set the format state back to previous settings
  121.  
  122.     return err -> GreaterSeverity (SEVERITY_INCOMPLETE);  
  123. }
  124.  
  125. Severity 
  126. SdaiString::STEPread (const char *s, ErrorDescriptor *err)
  127. {
  128.     istrstream in((char *)s);
  129.     return STEPread (in, err);
  130. }
  131.