[brlcad-commits] SF.net SVN: brlcad:[50584] brlcad/trunk/src/other/step/src
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <n_...@us...> - 2012-05-17 16:58:15
|
Revision: 50584 http://brlcad.svn.sourceforge.net/brlcad/?rev=50584&view=rev Author: n_reed Date: 2012-05-17 16:58:03 +0000 (Thu, 17 May 2012) Log Message: ----------- Apply changes based on SCL git 6e9b5a7. Creates GetLiteralStr function to implement and extend functionality common to SDAI_String::STEPread and PushPastString. Modified Paths: -------------- brlcad/trunk/src/other/step/src/cldai/sdaiString.cc brlcad/trunk/src/other/step/src/clstepcore/read_func.cc brlcad/trunk/src/other/step/src/clstepcore/sdaiApplication_instance.cc brlcad/trunk/src/other/step/src/clutils/Str.cc brlcad/trunk/src/other/step/src/clutils/Str.h Modified: brlcad/trunk/src/other/step/src/cldai/sdaiString.cc =================================================================== --- brlcad/trunk/src/other/step/src/cldai/sdaiString.cc 2012-05-17 16:12:13 UTC (rev 50583) +++ brlcad/trunk/src/other/step/src/cldai/sdaiString.cc 2012-05-17 16:58:03 UTC (rev 50584) @@ -18,39 +18,11 @@ } void SDAI_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 SDAI_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 SDAI_String::StrToVal( const char * s ) { @@ -67,54 +39,28 @@ * starting with a single quote */ Severity SDAI_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 ios_base::fmtflags 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'; - 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 + std::string s = GetLiteralStr( in, err ); + append( 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; - } - } - // otherwise there was not a quote - in.putback( c ); - in.flags( flags ); // set the format state back to previous settings + // retrieve current severity + Severity sev = err -> severity(); - clear(); - - return err -> GreaterSeverity( SEVERITY_INCOMPLETE ); + if ( s.empty() ) { + // no string was read + in.flags( flags ); // set the format state back to previous settings + err -> GreaterSeverity( SEVERITY_INCOMPLETE ); + sev = SEVERITY_INCOMPLETE; + } else if ( sev != SEVERITY_INPUT_ERROR ) { + // read valid string + sev = SEVERITY_NULL; + } + return sev; } Severity SDAI_String::STEPread( const char * s, ErrorDescriptor * err ) { Modified: brlcad/trunk/src/other/step/src/clstepcore/read_func.cc =================================================================== --- brlcad/trunk/src/other/step/src/clstepcore/read_func.cc 2012-05-17 16:12:13 UTC (rev 50583) +++ brlcad/trunk/src/other/step/src/clstepcore/read_func.cc 2012-05-17 16:58:03 UTC (rev 50584) @@ -4,6 +4,7 @@ #include "sdai.h" #include "read_func.h" #include "STEPattribute.h" +#include "Str.h" const int RealNumPrecision = REAL_NUM_PRECISION; @@ -458,41 +459,7 @@ /// assign 's' so that it contains an exchange file format string read from 'in'. void PushPastString( istream & in, std::string & s, ErrorDescriptor * err ) { - in >> ws; // skip whitespace - - if ( in.peek() == STRING_DELIM ) { - int lastAppended = in.get(); - s += lastAppended; - - int numDelims = 0; - while ( in.good() ) { - if ( in.peek() == STRING_DELIM ) { - numDelims++; - } else if ( numDelims % 2 != 0 ) { - // Found non-delim char following odd number of inner delims. - // Most recently appended delim was unescaped and terminates string, - // so we break rather than append the next non-delim char. - break; - } - lastAppended = in.get(); - s += lastAppended; - } - - if ( lastAppended != STRING_DELIM || - ( lastAppended == STRING_DELIM && numDelims % 2 == 0 ) ) - { - // Last appended was non-delimiter, or was the opening delimiter - // or an escaped delimiter. Add closing delim and log error. - char messageBuf[BUFSIZ]; - messageBuf[0] = '\0'; - - err->GreaterSeverity( SEVERITY_INPUT_ERROR ); - sprintf( messageBuf, "Unterminated string value.\n" ); - err->AppendToDetailMsg( messageBuf ); - - s += STRING_DELIM; - } - } + s += GetLiteralStr( in, err ); } /** Modified: brlcad/trunk/src/other/step/src/clstepcore/sdaiApplication_instance.cc =================================================================== --- brlcad/trunk/src/other/step/src/clstepcore/sdaiApplication_instance.cc 2012-05-17 16:12:13 UTC (rev 50583) +++ brlcad/trunk/src/other/step/src/clstepcore/sdaiApplication_instance.cc 2012-05-17 16:58:03 UTC (rev 50584) @@ -574,23 +574,6 @@ _error.AppendToUserMsg( "Since using pre-technical corrigendum... missing asterisk for redefined attr. " ); } - /* - if( ! ( (c == ',') || (c == ')') ) ) - { // input is not a delimiter - an error - PrependEntityErrMsg(); - - _error.AppendToDetailMsg( - "Delimiter expected after redefined asterisk attribute encoding (since using pre-technical corregendum.\n"); - CheckRemainingInput(in, &_error, "ENTITY", ",)"); - if(!in.good()) - return _error.severity(); - if(_error.severity() <= SEVERITY_INPUT_ERROR) - { - // STEPread_error(c,i,in); - return _error.severity(); - } - } - */ } else { // using technical corrigendum // should be nothing to do except loop again unless... // if at end need to have read the closing paren. Modified: brlcad/trunk/src/other/step/src/clutils/Str.cc =================================================================== --- brlcad/trunk/src/other/step/src/clutils/Str.cc 2012-05-17 16:12:13 UTC (rev 50583) +++ brlcad/trunk/src/other/step/src/clutils/Str.cc 2012-05-17 16:58:03 UTC (rev 50584) @@ -9,8 +9,9 @@ * and is not subject to copyright. */ -#include <Str.h> +#include "Str.h" #include <sstream> +#include <string> /****************************************************************** ** Procedure: string functions @@ -111,6 +112,65 @@ return c1 - c2; } +/** + * Test if a string ends with the given suffix. + */ +bool StrEndsWith( const std::string &s, const char * suf ) { + if ( suf == NULL ) { + return false; + } + std::string suffix = suf; + size_t sLen = s.length(); + size_t suffixLen = suffix.length(); + if ( sLen < suffixLen ) { + return false; + } + if ( s.substr( sLen - suffixLen ).compare( suffix ) == 0 ) { + return true; + } + return false; +} + +/** + * Extract the next delimited string from the istream. + */ +std::string GetLiteralStr( istream & in, ErrorDescriptor * err ) { + std::string s; + in >> std::ws; // skip whitespace + + if ( in.good() && in.peek() == STRING_DELIM ) { + s += in.get(); + bool allDelimsEscaped = true; + while ( in.good() ) { + if ( in.peek() == STRING_DELIM ) { + // A delimiter closes the string unless it's followed by another + // delimiter, in which case it's escaped. \S\ starts an ISO + // 8859 character escape sequence, so we ignore delimiters + // prefixed with \S\. + if ( !StrEndsWith( s, "\\S\\" ) ) { + allDelimsEscaped = !allDelimsEscaped; + } + } else if ( !allDelimsEscaped ) { + // Found normal char after unescaped delim, so last delim + // that was appended terminated the string. + break; + } + if ( !in.eof() ) { + s += in.get(); + } + } + if ( allDelimsEscaped ) { + // Any delimiters found after the opening delimiter were escaped, + // so the string is unclosed. + // 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 s; +} + /**************************************************************//** ** \fn PrettyTmpName (char * oldname) ** \returns a new capitalized name in a static buffer Modified: brlcad/trunk/src/other/step/src/clutils/Str.h =================================================================== --- brlcad/trunk/src/other/step/src/clutils/Str.h 2012-05-17 16:12:13 UTC (rev 50583) +++ brlcad/trunk/src/other/step/src/clutils/Str.h 2012-05-17 16:58:03 UTC (rev 50584) @@ -34,6 +34,9 @@ const char * StrToLower( const char * word, std::string & s ); const char * StrToUpper( const char * word, std::string & s ); const char * StrToConstant( const char * word, std::string & s ); +int StrCmpIns( const char * str1, const char * str2 ); +bool StrEndsWith( const std::string &s, const char * suffix ); +std::string GetLiteralStr( istream & in, ErrorDescriptor * err ); const char * PrettyTmpName( const char * oldname ); char * PrettyNewName( const char * oldname ); int StrCmpIns( const char *, const char * ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |