- Fix SDAIString (read and write) for P21
- Add support for \S\' in P21 string
This commit is contained in:
parent
defe0dd2b7
commit
6e9b5a7845
4 changed files with 71 additions and 104 deletions
|
|
@ -559,39 +559,7 @@ NumberValidLevel( const char * attrValue, ErrorDescriptor * err,
|
|||
|
||||
void
|
||||
PushPastString( istream & in, std::string & s, ErrorDescriptor * err ) {
|
||||
char messageBuf[BUFSIZ];
|
||||
messageBuf[0] = '\0';
|
||||
|
||||
char c;
|
||||
in >> ws; // skip whitespace
|
||||
in >> c;
|
||||
int i_quote = 0;
|
||||
if ( c == STRING_DELIM ) {
|
||||
s += c;
|
||||
while ( i_quote != -1 && in.get(c) ) {
|
||||
s += c;
|
||||
// to handle a string like 'hi'''
|
||||
if ( c == STRING_DELIM) {
|
||||
i_quote++;
|
||||
} else {
|
||||
// # of quotes is odd
|
||||
if ( i_quote % 2 != 0 ) {
|
||||
i_quote = -1;
|
||||
// put back last char, take it off from s and update c
|
||||
in.putback(c);
|
||||
s = s.substr(0, s.size() - 1);
|
||||
c = *s.rbegin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( c != STRING_DELIM ) {
|
||||
err->GreaterSeverity( SEVERITY_INPUT_ERROR );
|
||||
sprintf( messageBuf, "Invalid string value.\n" );
|
||||
err->AppendToDetailMsg( messageBuf );
|
||||
s.append( "\'" );
|
||||
}
|
||||
}
|
||||
s = ToExpressStr(in, err);
|
||||
}
|
||||
|
||||
// assign 's' so that it contains an exchange file format aggregate read from
|
||||
|
|
|
|||
|
|
@ -23,40 +23,12 @@ SCLP23( String )::operator= ( const char * s ) {
|
|||
|
||||
void
|
||||
SCLP23( String )::STEPwrite( ostream & out ) const {
|
||||
const char * str = 0;
|
||||
if( empty() ) {
|
||||
out << "\'\'";
|
||||
} else {
|
||||
out << "\'";
|
||||
str = c_str();
|
||||
while( *str ) {
|
||||
if( *str == STRING_DELIM ) {
|
||||
out << STRING_DELIM;
|
||||
}
|
||||
out << *str;
|
||||
str++;
|
||||
}
|
||||
out << "\'";
|
||||
}
|
||||
out << c_str();
|
||||
}
|
||||
|
||||
void
|
||||
SCLP23( String )::STEPwrite( std::string & s ) const {
|
||||
const char * str = 0;
|
||||
if( empty() ) {
|
||||
s = "\'\'";
|
||||
} else {
|
||||
s = "\'";
|
||||
str = c_str();
|
||||
while( *str ) {
|
||||
if( *str == STRING_DELIM ) {
|
||||
s += STRING_DELIM;
|
||||
}
|
||||
s += *str;
|
||||
str++;
|
||||
}
|
||||
s += STRING_DELIM;
|
||||
}
|
||||
s += c_str();
|
||||
}
|
||||
|
||||
Severity
|
||||
|
|
@ -73,12 +45,7 @@ SCLP23( String )::StrToVal( const char * s ) {
|
|||
// starting with a single quote
|
||||
Severity
|
||||
SCLP23( String )::STEPread( istream & in, ErrorDescriptor * err ) {
|
||||
int foundEndQuote = 0; // need so this string is not ok: 'hi''
|
||||
clear(); // clear the old string
|
||||
char c;
|
||||
in >> ws; // skip white space
|
||||
in >> c;
|
||||
|
||||
// remember the current format state to restore the previous settings
|
||||
#if defined(__GNUC__) && (__GNUC__ > 2)
|
||||
ios_base::fmtflags flags = in.flags();
|
||||
|
|
@ -87,44 +54,26 @@ SCLP23( String )::STEPread( istream & in, ErrorDescriptor * err ) {
|
|||
#endif
|
||||
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';
|
||||
continue;
|
||||
} 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';
|
||||
continue;
|
||||
}
|
||||
// else { ; } // do nothing it is an embedded quote
|
||||
}
|
||||
operator+= ( c );
|
||||
}
|
||||
// extract the string from the inputstream
|
||||
string s = ToExpressStr(in, err);
|
||||
operator+= (s);
|
||||
|
||||
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;
|
||||
}
|
||||
// retrieve current severity
|
||||
Severity sev = err -> severity();
|
||||
|
||||
// Not missing closing quote on string value
|
||||
if (sev != SEVERITY_INPUT_ERROR && s.compare("") != 0) {
|
||||
sev = SEVERITY_NULL;
|
||||
}
|
||||
// otherwise there was not a quote
|
||||
in.putback( c );
|
||||
in.flags( flags ); // set the format state back to previous settings
|
||||
|
||||
clear();
|
||||
|
||||
return err -> GreaterSeverity( SEVERITY_INCOMPLETE );
|
||||
// There was no quote
|
||||
if ( !(sev == SEVERITY_INPUT_ERROR || sev == SEVERITY_NULL) ) {
|
||||
in.flags( flags ); // set the format state back to previous settings
|
||||
clear();
|
||||
err -> GreaterSeverity( SEVERITY_INCOMPLETE );
|
||||
sev = SEVERITY_INCOMPLETE;
|
||||
}
|
||||
return sev;
|
||||
}
|
||||
|
||||
Severity
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@
|
|||
*/
|
||||
|
||||
#include <Str.h>
|
||||
|
||||
#ifndef STRING_DELIM
|
||||
#define STRING_DELIM '\''
|
||||
#endif
|
||||
/******************************************************************
|
||||
** Procedure: string functions
|
||||
** Description: These functions take a character or a string and return
|
||||
|
|
@ -130,6 +132,52 @@ char * PrettyNewName( const char * oldname ) {
|
|||
return name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the string conform to P21 from the istream
|
||||
*/
|
||||
std::string ToExpressStr( istream &in, ErrorDescriptor *err ) {
|
||||
char c;
|
||||
in >> ws; // skip white space
|
||||
in >> c;
|
||||
int i_quote = 0;
|
||||
size_t found;
|
||||
string s = "";
|
||||
if ( c == STRING_DELIM ) {
|
||||
s += c;
|
||||
while ( i_quote != -1 && in.get(c) ) {
|
||||
s += c;
|
||||
// to handle a string like 'hi'''
|
||||
if ( c == STRING_DELIM) {
|
||||
// to handle \S\'
|
||||
found = s.find_last_of("\\S\\");
|
||||
if ( !(found != string::npos && (s.size() == found + 2)) ) {
|
||||
i_quote++;
|
||||
}
|
||||
} else {
|
||||
// # of quotes is odd
|
||||
if ( i_quote % 2 != 0 ) {
|
||||
i_quote = -1;
|
||||
// put back last char, take it off from s and update c
|
||||
in.putback(c);
|
||||
s = s.substr(0, s.size() - 1);
|
||||
c = *s.rbegin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( c != STRING_DELIM ) {
|
||||
// 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);
|
||||
}
|
||||
} else {
|
||||
in.putback(c);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// This function is used to check an input stream following a read. It writes
|
||||
// error messages in the 'ErrorDescriptor &err' argument as appropriate.
|
||||
// 'const char *tokenList' argument contains a string made up of delimiters
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ const char * PrettyTmpName (const char * oldname);
|
|||
char * PrettyNewName (const char * oldname);
|
||||
char * EntityClassName ( char * oldname);
|
||||
|
||||
std::string ToExpressStr (istream &in, ErrorDescriptor *err);
|
||||
|
||||
extern Severity CheckRemainingInput
|
||||
(istream &in, ErrorDescriptor *err,
|
||||
const char *typeName, // used in error message
|
||||
|
|
|
|||
Loading…
Reference in a new issue