X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FKM_util.cpp;h=d263d6e47bcfd416b30ddf71a164a594a78890cf;hb=79912d9558b67fb75dfad8bca29d2db1fa58a769;hp=8f8107f6875371c54a4d239c4970409a5ba5c2a0;hpb=ab3e3df49a9d4a44a3bf11211e31bdeac3ef7bcf;p=asdcplib.git diff --git a/src/KM_util.cpp b/src/KM_util.cpp index 8f8107f..d263d6e 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2005-2012, John Hurst +Copyright (c) 2005-2015, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -129,10 +129,10 @@ Kumu::Result_t::Get(unsigned int i) } // -Kumu::Result_t::Result_t(int v, const char* s, const char* l) : value(v), symbol(s), label(l) +Kumu::Result_t::Result_t(int v, const std::string& s, const std::string& l) : value(v), symbol(s), label(l) { - assert(l); - assert(s); + assert(!l.empty()); + assert(!s.empty()); if ( v == 0 ) return; @@ -162,8 +162,65 @@ Kumu::Result_t::Result_t(int v, const char* s, const char* l) : value(v), symbol return; } + +Kumu::Result_t::Result_t(const Result_t& rhs) +{ + value = rhs.value; + symbol = rhs.symbol; + label = rhs.label; + message = rhs.message; +} + Kumu::Result_t::~Result_t() {} +// +const Kumu::Result_t& +Kumu::Result_t::operator=(const Result_t& rhs) +{ + value = rhs.value; + symbol = rhs.symbol; + label = rhs.label; + message = rhs.message; + return *this; +} + +// +const Kumu::Result_t +Kumu::Result_t::operator()(const std::string& message) const +{ + Result_t result = *this; + result.message = message; + return result; +} + +static int const MESSAGE_BUF_MAX = 2048; + +// +const Kumu::Result_t +Kumu::Result_t::operator()(const int& line, const char* filename) const +{ + assert(filename); + char buf[MESSAGE_BUF_MAX]; + snprintf(buf, MESSAGE_BUF_MAX-1, "%s, line %d", filename, line); + + Result_t result = *this; + result.message = buf; + return result; +} + +// +const Kumu::Result_t +Kumu::Result_t::operator()(const std::string& message, const int& line, const char* filename) const +{ + assert(filename); + char buf[MESSAGE_BUF_MAX]; + snprintf(buf, MESSAGE_BUF_MAX-1, "%s, line %d", filename, line); + + Result_t result = *this; + result.message = message + buf; + return result; +} + //------------------------------------------------------------------------------------------ // DTrace internals @@ -796,8 +853,8 @@ Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const tmp_t.AddMinutes(m_TZOffsetMinutes); tmp_t.GetComponents(year, month, day, hour, minute, second); - ofst_hours = abs(m_TZOffsetMinutes) / 60; - ofst_minutes = abs(m_TZOffsetMinutes) % 60; + ofst_hours = Kumu::xabs(m_TZOffsetMinutes) / 60; + ofst_minutes = Kumu::xabs(m_TZOffsetMinutes) % 60; if ( m_TZOffsetMinutes < 0 ) direction = '-'; @@ -805,7 +862,7 @@ Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const // 2004-05-01T13:20:00+00:00 snprintf(str_buf, buf_len, - "%04hu-%02hu-%02huT%02hu:%02hu:%02hu%c%02hu:%02hu", + "%04hu-%02hhu-%02hhuT%02hhu:%02hhu:%02hhu%c%02u:%02u", year, month, day, hour, minute, second, direction, ofst_hours, ofst_minutes); @@ -1178,22 +1235,14 @@ Kumu::km_token_split(const std::string& str, const std::string& separator) while ( r != 0 ) { assert(r >= pstr); - if ( r > pstr ) - { - std::string tmp_str; - tmp_str.assign(pstr, r - pstr); - components.push_back(tmp_str); - } - + std::string tmp_str; + tmp_str.assign(pstr, r - pstr); + components.push_back(tmp_str); pstr = r + separator.size(); r = strstr(pstr, separator.c_str()); } - if ( strlen(pstr) > 0 ) - { - components.push_back(std::string(pstr)); - } - + components.push_back(std::string(pstr)); return components; }