Imported Upstream version 2.81
[platform/upstream/libbullet.git] / UnitTests / cppunit / src / cppunit / TypeInfoHelper.cpp
1 #include <cppunit/Portability.h>
2 #include <cppunit/extensions/TypeInfoHelper.h>
3
4 #if CPPUNIT_HAVE_RTTI
5
6 #include <string>
7
8 #if CPPUNIT_HAVE_GCC_ABI_DEMANGLE
9 #include <malloc.h>
10 #include <cxxabi.h>
11 #endif
12
13
14 CPPUNIT_NS_BEGIN
15
16
17 std::string 
18 TypeInfoHelper::getClassName( const std::type_info &info )
19 {
20 #if defined(CPPUNIT_HAVE_GCC_ABI_DEMANGLE)  &&  CPPUNIT_HAVE_GCC_ABI_DEMANGLE
21
22   int status = 0;
23   char* c_name = 0;
24
25   c_name = abi::__cxa_demangle( info.name(), 0, 0, &status );
26   
27   std::string name( c_name );
28   free( c_name );  
29
30 #else   // CPPUNIT_HAVE_GCC_ABI_DEMANGLE
31
32   static std::string classPrefix( "class " );
33   std::string name( info.name() );
34
35   // Work around gcc 3.0 bug: strip number before type name.
36   unsigned int firstNotDigitIndex = 0;
37   while ( firstNotDigitIndex < name.length()  &&
38           name[firstNotDigitIndex] >= '0'  &&
39           name[firstNotDigitIndex] <= '9' )
40     ++firstNotDigitIndex;
41   name = name.substr( firstNotDigitIndex );
42
43   if ( name.substr( 0, classPrefix.length() ) == classPrefix )
44     return name.substr( classPrefix.length() );
45
46 #endif  // CPPUNIT_HAVE_GCC_ABI_DEMANGLE
47
48   return name;
49 }
50
51
52 CPPUNIT_NS_END
53
54 #endif // CPPUNIT_HAVE_RTTI