#include "DBEntity.h" #include "extensions.h" DBEntity::DBEntity(TIPsDatabase *_db, const char *_name, const bool _commonword, const unsigned int _id): DBObject(_db, _id), m_commonword(_commonword), m_name(strdupCheck(_name)), m_nameLength(strlen(m_name)) {parseName();} size_t DBEntity::parseName() { //parse the name into a vector of name parts //note that name is not saved and its parts are duplicated char was, c; const char *last = m_name; if (m_name && (was = *m_name)) { //populate the names vector, in-place working for (char *i = (char*)m_name; c = *i; i++) { if (c == ' ' && was != ' ') { *i = 0; m_names.push_back(strdupCheck(last)); last = i+1; *i = ' '; } was = c; } m_names.push_back(strdupCheck(last)); } return m_names.size(); } DBEntity::DBEntity(TIPsDatabase *_db, const InternetResource *_ir, const char *_name): DBObject(_db, _ir), m_commonword(false), m_name(strdupCheck(_name)), m_nameLength(strlen(m_name)) {parseName();} DBEntity::~DBEntity() { if (m_name) free((void*)m_name); for (vector::iterator i = m_names.begin(); i != m_names.end(); i++) free((void*)*i); }