Skip to content

Commit afb46dc

Browse files
authored
Handle a sequence of uppercase characters, followed by at least one lowercase character in function toUpperCase (#2542)
1 parent f2134af commit afb46dc

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

XMLHelper.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ inline TypeInfo readTypeInfo( tinyxml2::XMLElement const * element )
412412
}
413413
if ( typeInfo.prefix.starts_with( "const" ) )
414414
{
415-
typeInfo.prefix = trim( typeInfo.prefix.substr( 5 ) );
415+
typeInfo.prefix = trim( typeInfo.prefix.substr( 5 ) );
416416
typeInfo.postfix = ( typeInfo.postfix.empty() ? "const" : ( "const " + typeInfo.postfix ) );
417417
}
418418
return typeInfo;
@@ -558,18 +558,18 @@ inline std::string toString( tinyxml2::XMLError error )
558558

559559
std::string toUpperCase( std::string const & name )
560560
{
561+
assert( !name.empty() );
561562
std::string convertedName;
562-
bool previousIsLowerCase = false;
563-
bool previousIsDigit = false;
564-
for ( auto c : name )
563+
convertedName.push_back( static_cast<char>( toupper( name.front() ) ) );
564+
size_t n = name.length();
565+
for ( size_t i = 1; i < n; ++i )
565566
{
566-
if ( ( isupper( c ) && ( previousIsLowerCase || previousIsDigit ) ) || ( isdigit( c ) && previousIsLowerCase ) )
567+
if ( ( isupper( name[i] ) && ( islower( name[i - 1] ) || isdigit( name[i - 1] ) || ( ( i < n - 1 ) && islower( name[i + 1] ) ) ) ) ||
568+
( isdigit( name[i] ) && islower( name[i - 1] ) ) )
567569
{
568570
convertedName.push_back( '_' );
569571
}
570-
convertedName.push_back( static_cast<char>( toupper( c ) ) );
571-
previousIsLowerCase = !!islower( c );
572-
previousIsDigit = !!isdigit( c );
572+
convertedName.push_back( static_cast<char>( toupper( name[i] ) ) );
573573
}
574574
return convertedName;
575575
}

0 commit comments

Comments
 (0)