File indexing completed on 2025-04-04 01:26:37
0001 #include "FWCore/Utilities/interface/OftenEmptyCString.h"
0002 #include <cstring>
0003 #include <utility>
0004
0005 namespace edm {
0006 OftenEmptyCString::OftenEmptyCString(const char* iValue) {
0007 if (iValue == nullptr or iValue[0] == '\0') {
0008 m_value = emptyString();
0009 } else {
0010 auto l = strlen(iValue);
0011 auto temp = new char[l + 1];
0012 strncpy(temp, iValue, l + 1);
0013 m_value = temp;
0014 }
0015 }
0016 void OftenEmptyCString::deleteIfNotEmpty() {
0017 if (m_value != emptyString()) {
0018 delete[] m_value;
0019 }
0020 }
0021 OftenEmptyCString::~OftenEmptyCString() { deleteIfNotEmpty(); }
0022
0023 OftenEmptyCString::OftenEmptyCString(OftenEmptyCString const& iOther) : OftenEmptyCString(iOther.m_value) {}
0024 OftenEmptyCString::OftenEmptyCString(OftenEmptyCString&& iOther) noexcept : m_value(iOther.m_value) {
0025 iOther.m_value = nullptr;
0026 }
0027 OftenEmptyCString& OftenEmptyCString::operator=(OftenEmptyCString const& iOther) {
0028 if (iOther.m_value != m_value) {
0029 OftenEmptyCString temp{iOther};
0030 *this = std::move(temp);
0031 }
0032 return *this;
0033 }
0034 OftenEmptyCString& OftenEmptyCString::operator=(OftenEmptyCString&& iOther) noexcept {
0035 if (iOther.m_value != m_value) {
0036 deleteIfNotEmpty();
0037 m_value = iOther.m_value;
0038 iOther.m_value = nullptr;
0039 }
0040 return *this;
0041 }
0042
0043 const char* OftenEmptyCString::emptyString() {
0044 constexpr static const char* s_empty = "";
0045 return s_empty;
0046 }
0047
0048 }