/*
-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
#include <KM_error.h>
#include <KM_tai.h>
#include <string.h>
-#include <string>
#include <list>
namespace Kumu
virtual ~ArchivableString() {}
bool HasValue() const { return ! this->empty(); }
- ui32_t ArchiveLength() const { return static_cast<ui32_t>((sizeof(ui32_t) + this->size())|0xffffffff); }
+ ui32_t ArchiveLength() const { return sizeof(ui32_t) + static_cast<ui32_t>(this->size()); }
bool Archive(MemIOWriter* Writer) const {
if ( Writer == 0 ) return false;
// Return the number of seconds since the Unix epoch UTC (1970-01-01T00:00:00+00:00)
ui64_t GetCTime() const;
+ // Set internal time to the number of seconds since the Unix epoch UTC
+ void SetCTime(const ui64_t& ctime);
+
// Read and write the timestamp (always UTC) value as a byte string having
// the following format:
// | 16 bits int, big-endian | 8 bits | 8 bits | 8 bits | 8 bits | 8 bits |
inline virtual bool HasValue() const { return m_Length > 0; }
- inline virtual ui32_t ArchiveLength() const { return m_Length; }
+ inline virtual ui32_t ArchiveLength() const { return sizeof(ui32_t) + m_Length; }
inline virtual bool Archive(MemIOWriter* Writer) const {
assert(Writer);
};
inline void hexdump(const ByteString& buf, FILE* stream = 0) {
- hexdump(buf.RoData(), buf.Length());
+ hexdump(buf.RoData(), buf.Length(), stream);
}
+ // Locates the first occurrence of the null-terminated string s2 in the string s1, where not more
+ // than n characters are searched. Characters that appear after a `\0' character are not searched.
+ // Reproduced here from BSD for portability.
+ const char *km_strnstr(const char *s1, const char *s2, size_t n);
+
+ // Split the input string into tokens using the given separator. If the separator is not found the
+ // entire string will be returned as a single-item list. Empty items will be recorded for
+ // adjacent instances of the separator. E.g., "/foo//bar/" will return ["", "foo", "", "bar", ""].
+ std::list<std::string> km_token_split(const std::string& str, const std::string& separator);
+
+ // Join the tokens in the given list using delimiter. If prefix is defined then each token
+ // will be concatenated with the prefix before being added to the composite string.
+ template <class T>
+ std::string
+ km_join(const T& list, const std::string& delimiter, const std::string& prefix = "")
+ {
+ std::string result;
+
+ for ( typename T::const_iterator i = list.begin(); i != list.end(); ++i )
+ {
+ if ( i != list.begin() )
+ {
+ result += delimiter;
+ }
+
+ result += prefix + *i;
+ }
+
+ return result;
+ }
} // namespace Kumu