Re: [Cppunit-devel] questionable code @ TypeInfoHelper.cpp
Brought to you by:
blep
|
From: Duane M. <dua...@ma...> - 2002-04-19 15:25:01
|
--- At Fri, 19 Apr 2002 12:57:53 +0200, Baptiste Lepilleur wrote:
>I did this instead (remove the ugly #ifdef):
>
>std::string
>TypeInfoHelper::getClassName( const std::type_info &info )
>{
> static std::string classPrefix( "class " );
> std::string name( info.name() );
>
> if ( name.substr( 0, classPrefix.length() ) == classPrefix )
> return name.substr( classPrefix.length() );
> return name;
>}
>
>Let me know if it's works.
>Baptiste.
>
>PS: is there any reason for comparing the size() with the length() ?
std::string::length() and std::string::size() are synonyms. length() is
commonly used for string (ie strlen) however, size() was used for
containers (vectors, etc). So they included both. This allows std::string
to be compatible with the "container interface".
>----- Original Message -----
>From: "FUKUDA Fumiki" <ff...@nt...>
>To: <cpp...@li...>
>Sent: Thursday, April 18, 2002 9:05 AM
>Subject: [Cppunit-devel] questionable code @ TypeInfoHelper.cpp
>
>
>> Hi all,
>>
>> ----- excerpt from src/cppunit/TypeInfoHelper.cpp -----
>> std::string
>> TypeInfoHelper::getClassName( const std::type_info &info )
>> {
>> static std::string classPrefix( "class " );
>> std::string name( info.name() );
>>
>> bool has_class_prefix = 0 ==
>> #if CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST
>> name.compare( classPrefix, 0, classPrefix.length() );
>> #else
>> name.compare( 0, classPrefix.length(), classPrefix );
>> #endif
>> return has_class_prefix ? name.substr( classPrefix.length() ) : name;
>> }
>> ------------------
>>
>> if info.name().length() < classPrefix.length(), an exception should be
>thrown.
>> I think this method should return 'name' at this condition (as follows).
>>
>> ...
>> static std::string classPrefix( "class " );
>> std::string name( info.name() );
>>
>> if ( name.length() < classPrefix.size() ) return name; // ADD THIS!
>>
>> bool has_class_prefix = 0 == ...
...Duane
--
"If tyranny and oppression come to this land, it will be in the
guise of fighting a foreign enemy." - James Madison
|