void
WriteStringT( hid_t iParent,
              const std::string &iAttrName,
              const StringT &iString )
{
    // Verify that no NULL characters have been hidden in the string.
    CharT NullChar = ( CharT )0;
    ABCA_ASSERT( iString.find( NullChar ) == StringT::npos,
                 "Illegal NULL character found in string in WriteStringT" );

    // Create the dataspace.
    size_t len = iString.length();
    Dimensions dims( len + 1 );
    HDimensions hdims( dims );
    size_t npoints = hdims.numPoints();
    ABCA_ASSERT( npoints > 0,
                 "Cannot create degenerate dataspace" );

    hid_t dspaceId = H5Screate_simple( hdims.rank(), hdims.rootPtr(), NULL );
    DspaceCloser dspaceCloser( dspaceId );

    // Get the data.
    const CharT *data;
    if ( len == 0 )
    {
        data = &NullChar;
    }
    else
    {
        data = iString.c_str();
    }

    // Write into it.
    WriteDataToAttr( iParent, dspaceId, iAttrName,
                     GetFileDtype<CharT>(), GetNativeDtype<CharT>(),
                     ( const void * )data );
}
예제 #2
0
void CheckFind()
{
    StringT E = "";
    StringT X = "x";
    StringT Y = "y";
    StringT S = "xxx";

    EXPECT_EQ(E.find(E),                                0u);
    EXPECT_EQ(S.find(E),                                0u);
    EXPECT_EQ(E.find(E, 2),                             StringT::npos);
    EXPECT_EQ(S.find(E, 2),                             2u);
    EXPECT_EQ(E.find(E, 8),                             StringT::npos);
    EXPECT_EQ(S.find(E, 8),                             StringT::npos);
    EXPECT_EQ(E.find(E, StringT::npos),                 StringT::npos);
    EXPECT_EQ(S.find(E, StringT::npos),                 StringT::npos);

    EXPECT_EQ(E.find_first_of(E),                       StringT::npos);
    EXPECT_EQ(S.find_first_of(E),                       StringT::npos);
    EXPECT_EQ(E.find_first_of(E, 2),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(E, 2),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(E, 8),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(E, 8),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(E, StringT::npos),        StringT::npos);
    EXPECT_EQ(S.find_first_of(E, StringT::npos),        StringT::npos);
    EXPECT_EQ(E.find_first_of(X),                       StringT::npos);
    EXPECT_EQ(S.find_first_of(X),                       0u);
    EXPECT_EQ(E.find_first_of(X, 2),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(X, 2),                    2u);
    EXPECT_EQ(E.find_first_of(X, 8),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(X, 8),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(X, StringT::npos),        StringT::npos);
    EXPECT_EQ(S.find_first_of(X, StringT::npos),        StringT::npos);
    EXPECT_EQ(E.find_first_of(Y, 2),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(Y, 2),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(Y, 8),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(Y, 8),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(Y, StringT::npos),        StringT::npos);
    EXPECT_EQ(S.find_first_of(Y, StringT::npos),        StringT::npos);

    EXPECT_EQ(E.find_first_not_of(E),                   StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E),                   0u);
    EXPECT_EQ(E.find_first_not_of(E, 2),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E, 2),                2u);
    EXPECT_EQ(E.find_first_not_of(E, 8),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E, 8),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(E, StringT::npos),    StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E, StringT::npos),    StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X),                   StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X),                   StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X, 2),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X, 2),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X, 8),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X, 8),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X, StringT::npos),    StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X, StringT::npos),    StringT::npos);
    EXPECT_EQ(E.find_first_not_of(Y, 2),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(Y, 2),                2u);
    EXPECT_EQ(E.find_first_not_of(Y, 8),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(Y, 8),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(Y, StringT::npos),    StringT::npos);
    EXPECT_EQ(S.find_first_not_of(Y, StringT::npos),    StringT::npos);

    EXPECT_EQ(E.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(S.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(E.find_last_of(E, 2),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(E, 2),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(E, 8),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(E, 8),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(E, 0),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(E, 0),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(S.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(E.find_last_of(X, 2),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(X, 2),                     2u);
    EXPECT_EQ(E.find_last_of(X, 8),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(X, 8),                     2u);
    EXPECT_EQ(E.find_last_of(X, 0),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(X, 0),                     0u);
    EXPECT_EQ(E.find_last_of(Y, 2),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(Y, 2),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(Y, 8),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(Y, 8),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(Y, 0),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(Y, 0),                     StringT::npos);

    EXPECT_EQ(E.find_last_not_of(E),                    StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E),                    2u);
    EXPECT_EQ(E.find_last_not_of(E, 2),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E, 2),                 2u);
    EXPECT_EQ(E.find_last_not_of(E, 8),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E, 8),                 2u);
    EXPECT_EQ(E.find_last_not_of(E, 0),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E, 0),                 0u);
    EXPECT_EQ(E.find_last_not_of(E),                    StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E),                    2u);
    EXPECT_EQ(E.find_last_not_of(X, 2),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(X, 2),                 StringT::npos);
    EXPECT_EQ(E.find_last_not_of(X, 8),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(X, 8),                 StringT::npos);
    EXPECT_EQ(E.find_last_not_of(X, 0),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(X, 0),                 StringT::npos);
    EXPECT_EQ(E.find_last_not_of(Y, 2),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(Y, 2),                 2u);
    EXPECT_EQ(E.find_last_not_of(Y, 8),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(Y, 8),                 2u);
    EXPECT_EQ(E.find_last_not_of(Y, 0),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(Y, 0),                 0u);
}