Skip to content

Commit

Permalink
FIXUP: Introduce new custom function to format TRIL code
Browse files Browse the repository at this point in the history
  • Loading branch information
janvrany committed Dec 15, 2023
1 parent 55b7637 commit 187c1bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions fvtest/tril/test/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ TEST(FormatTest, FormatInt) {
//ASSERT_STREQ(buffer, ">>-4<<");
}

TEST(FormatTest, FormatIntWithPrefix) {
char buffer[1024] = { '\0' };

Tril::format(buffer, sizeof(buffer), ">>%hhd<<", (int8_t)42);
ASSERT_STREQ(buffer, ">>42<<");

Tril::format(buffer, sizeof(buffer), ">>%hd<<", (int16_t)-42);
ASSERT_STREQ(buffer, ">>-42<<");

Tril::format(buffer, sizeof(buffer), ">>%ld<<", (int32_t)42);
ASSERT_STREQ(buffer, ">>42<<");

Tril::format(buffer, sizeof(buffer), ">>%lld<<", (int64_t)-42);
ASSERT_STREQ(buffer, ">>-42<<");

}

TEST(FormatTest, FormatIntBad) {
char buffer[1024] = { '\0' };

Expand Down
9 changes: 8 additions & 1 deletion fvtest/tril/tril/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ inline void _format(char* dst, size_t size, const char *fmt, V value, Rest... re
else
{
/*
* Ignore l, ll, h, hh and j prefixes
* Ignore l, ll, h, hh, j, I, I32 and I64 prefixes
*/
if (*fmt == 'l')
{
Expand All @@ -408,6 +408,13 @@ inline void _format(char* dst, size_t size, const char *fmt, V value, Rest... re
}
else if (*fmt == 'j')
fmt++;
else if (*fmt == 'I')
{
fmt++;
if ( (*(fmt+0) == '3' && *(fmt+1) == '2')
|| (*(fmt+0) == '6' && *(fmt+1) == '4') )
fmt+=2;
}

size_t consumed = 0;
switch (*fmt) {
Expand Down

0 comments on commit 187c1bd

Please sign in to comment.