Changeset 10486 for trunk


Ignore:
Timestamp:
04/28/11 17:35:33 (13 years ago)
Author:
tbretz
Message:
Remove redundant trailing \0s from strings.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/EventImp.cc

    r10423 r10486  
    186186
    187187    return find(fAllowedStates.begin(), fAllowedStates.end(), state)!=fAllowedStates.end();
     188}
     189
     190// --------------------------------------------------------------------------
     191//
     192//! @returns the event data converted to a std::string. Trailing redundant
     193//!          \0's are removed.
     194//!
     195string EventImp::GetString() const
     196{
     197    size_t s = GetSize()-1;
     198    while (s>0 && GetText()[s]==0)
     199        s--;
     200
     201    return std::string(GetText(), s+1);
    188202}
    189203
  • trunk/FACT++/src/EventImp.h

    r10423 r10486  
    3535    EventImp &operator()(const std::string str) { SetDescription(str); return *this; }
    3636    EventImp &operator()(const char *str) { SetDescription(str); return *this; }
     37    EventImp &operator()(int state) { fAllowedStates.push_back(state); return *this; }
    3738
    3839    // Print contents
     
    6566    double            GetDouble() const { return *reinterpret_cast<const double*>(GetData()); }
    6667    const char       *GetText() const   { return  reinterpret_cast<const char*>(GetData()); }
    67     std::string       GetString() const { return std::string(GetText(), GetSize()); }
    6868    std::vector<char> GetVector() const { return std::vector<char>(GetText(), GetText()+GetSize()); }
    69 
     69    std::string       GetString() const;
    7070};
    7171
Note: See TracChangeset for help on using the changeset viewer.