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 >
Wrap
Text File
|
1994-08-06
|
3KB
|
131 lines
/*
* NIST STEP Core Class Library
* clstepcore/STEPstring.cc
* February, 1994
* KC Morris
* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
/* $Id: STEPstring.cc,v 2.0.1.1 1994/04/05 16:39:51 sauderd Exp $ */
#include <STEPstring.h>
#include <strstream.h>
void
SdaiString::STEPwrite (ostream& out) const
{
const char *str = 0;
if (is_null ())
out << "$";
else
{
out << "\'";
str = chars ();
while (*str)
{
if(*str == STRING_DELIM)
out << STRING_DELIM;
out << *str;
str++;
}
out << "\'";
}
}
void
SdaiString::STEPwrite (SCLstring &s) const
{
const char *str = 0;
if (is_null ())
{
// s.set_null(); // this would free up space? nope
s = "$";
}
else
{
s = "\'";
str = chars ();
while (*str)
{
if(*str == STRING_DELIM)
s.Append(STRING_DELIM);
s.Append(*str);
str++;
}
s.Append(STRING_DELIM);
}
}
Severity
SdaiString::StrToVal (const char * s)
{
operator= (s);
if (! strcmp (chars (), s)) return SEVERITY_NULL ;
else return SEVERITY_INPUT_ERROR;
}
// STEPread reads a string in exchange file format
// starting with a single quote
Severity
SdaiString::STEPread (istream& in, ErrorDescriptor *err)
{
int foundEndQuote = 0; // need so this string is not ok: 'hi''
set_null (); // clear the old string
char c;
in >> ws; // skip white space
in >> c;
// remember the current format state to restore the previous settings
long int flags = in.flags();
in.unsetf(ios::skipws);
if (c == STRING_DELIM)
{
while( (c != '\0') && in.good() && in.get(c) )
{
if (c == STRING_DELIM) {
in.get (c);
if( ! in.good() )
{ // it is the final quote and no extra char was read
foundEndQuote = 1;
c = '\0';
}
else if( !(c == STRING_DELIM) )
{ // it is the final quote and extra char was read
in.putback (c); // put back non-quote extra char
foundEndQuote = 1;
c = '\0';
}
else { ; } // do nothing it is an embedded quote
}
Append (c);
}
Append ('\0');
if(foundEndQuote)
return SEVERITY_NULL;
else
{ // non-recoverable error
err->AppendToDetailMsg("Missing closing quote on string value.\n");
err->AppendToUserMsg("Missing closing quote on string value.\n");
err->GreaterSeverity(SEVERITY_INPUT_ERROR);
return SEVERITY_INPUT_ERROR;
}
}
// otherwise there was not a quote
in.putback (c);
in.flags(flags); // set the format state back to previous settings
return err -> GreaterSeverity (SEVERITY_INCOMPLETE);
}
Severity
SdaiString::STEPread (const char *s, ErrorDescriptor *err)
{
istrstream in((char *)s);
return STEPread (in, err);
}