Format: Add support for unsigned char
This commit is contained in:
@@ -81,6 +81,11 @@ void Formatter<const char*>::format(Builder& builder, const char* value) const
|
||||
value != nullptr ? std::string_view { value, strlen(value) } : "nullptr");
|
||||
}
|
||||
|
||||
void Formatter<const unsigned char*>::format(Builder& builder, const unsigned char* value) const
|
||||
{
|
||||
return Formatter<const char*>::format(builder, reinterpret_cast<const char*>(value));
|
||||
}
|
||||
|
||||
// Pointer
|
||||
|
||||
void Formatter<std::nullptr_t>::format(Builder& builder, std::nullptr_t) const
|
||||
|
||||
@@ -199,6 +199,19 @@ template<size_t N>
|
||||
struct Formatter<char[N]> : Formatter<const char*> {
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<const unsigned char*> : Formatter<const char*> {
|
||||
void format(Builder& builder, const unsigned char* value) const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<unsigned char*> : Formatter<const unsigned char*> {
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct Formatter<unsigned char[N]> : Formatter<const unsigned char*> {
|
||||
};
|
||||
|
||||
// Pointer
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -109,6 +109,14 @@ TEST_CASE(FormatString)
|
||||
result = format("{}", cString);
|
||||
EXPECT_EQ(result, "C string");
|
||||
|
||||
const unsigned char unsignedCharArray[] = "µnsïgned çhãr";
|
||||
result = format("{}", unsignedCharArray);
|
||||
EXPECT_EQ(result, "µnsïgned çhãr");
|
||||
|
||||
const unsigned char* unsignedCharPointer = &unsignedCharArray[0];
|
||||
result = format("{}", unsignedCharPointer);
|
||||
EXPECT_EQ(result, "µnsïgned çhãr");
|
||||
|
||||
std::string string = "string";
|
||||
result = format("{}", string);
|
||||
EXPECT_EQ(result, "string");
|
||||
|
||||
Reference in New Issue
Block a user