Merge pull request #1456 from atn34/trace-format-fixes

Trace format fixes
This commit is contained in:
A.J. Beamon 2019-04-15 10:19:22 -07:00 committed by GitHub
commit 77843e8494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -1218,3 +1218,8 @@ void TraceEventFields::validateFormat() const {
} }
} }
} }
std::string traceableStringToString(const char* value, size_t S) {
ASSERT_WE_THINK(value[S - 1] == '\0');
return std::string(value, S - 1); // Exclude trailing \0 byte
}

View File

@ -262,6 +262,8 @@ struct TraceableString<const char*> {
} }
}; };
std::string traceableStringToString(const char* value, size_t S);
template<size_t S> template<size_t S>
struct TraceableString<char[S]> { struct TraceableString<char[S]> {
static const char* begin(const char* value) { static const char* begin(const char* value) {
@ -269,12 +271,10 @@ struct TraceableString<char[S]> {
} }
static bool atEnd(const char* value, const char* iter) { static bool atEnd(const char* value, const char* iter) {
return iter - value == S; return iter - value == S - 1; // Exclude trailing \0 byte
} }
static std::string toString(const char* value) { static std::string toString(const char* value) { return traceableStringToString(value, S); }
return std::string(value, S);
}
}; };
template<> template<>
@ -294,7 +294,7 @@ struct TraceableString<char*> {
template<class T> template<class T>
struct TraceableStringImpl : std::true_type { struct TraceableStringImpl : std::true_type {
static constexpr bool isPrintable(char c) { return c > 32 && c < 127; } static constexpr bool isPrintable(char c) { return 32 <= c && c <= 126; }
template<class Str> template<class Str>
static std::string toString(Str&& value) { static std::string toString(Str&& value) {