Thread: [Cppunit-devel] questionable code @ TypeInfoHelper.cpp
Brought to you by:
blep
|
From: FUKUDA F. <ff...@nt...> - 2002-04-18 07:06:37
|
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 == ...
-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...
|
|
From: Duane M. <dua...@ma...> - 2002-04-18 15:12:26
|
--- At Thu, 18 Apr 2002 16:05:54 +0900, FUKUDA Fumiki wrote:
>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).
This is incorrect. string.compare() will not throw an exception under
these conditions. The minimum of classPrefix.length() and
info.name().length() will be compared. The code is fine.
...Duane
--
"If tyranny and oppression come to this land, it will be in the
guise of fighting a foreign enemy." - James Madison
|
|
From: Baptiste L. <gai...@fr...> - 2002-04-19 10:51:47
|
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() ?
----- 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 == ...
>
> -----:-----:-----:-----:-----:-----:-----:-----:-----:-----
> FUKUDA (episteme) Fumiki -- magical, but never a magic...
>
> _______________________________________________
> Cppunit-devel mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppunit-devel
>
|
|
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
|