Skip to content

Commit

Permalink
Refreshed tinyformat.h against upstream, retained local mods
Browse files Browse the repository at this point in the history
  • Loading branch information
coatless committed Apr 14, 2017
1 parent d8c1dc3 commit ec16932
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
2017-04-14 James J Balamuta <balamut2@illinois.edu>

* inst/include/Rcpp/utils/tinyformat.h: Refreshed tinyformat.h against
May 13, 2016 upstream, retained local mods.

* inst/include/Rcpp/Environment.h: Modified formatting of new exception
messages to be more concise.
* inst/include/Rcpp/exceptions.h: idem
Expand Down
33 changes: 13 additions & 20 deletions inst/include/Rcpp/utils/tinyformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,6 @@ namespace Rcpp {
# endif
#endif

#ifdef TINYFORMAT_USE_VARIADIC_TEMPLATES
# include <array>
# if defined(_MSC_VER) && _MSC_VER <= 1800 // VS2013
# define TINYFORMAT_BRACED_INIT_WORKAROUND(x) (x)
# else
# define TINYFORMAT_BRACED_INIT_WORKAROUND(x) {x}
# endif
#endif

#if defined(__GLIBCXX__) && __GLIBCXX__ < 20080201
// std::showpos is broken on old libstdc++ as provided with OSX. See
// http://gcc.gnu.org/ml/libstdc++/2007-11/msg00075.html
Expand Down Expand Up @@ -282,7 +273,7 @@ inline void formatTruncated(std::ostream& out, const T& value, int ntrunc)
std::ostringstream tmp;
tmp << value;
std::string result = tmp.str();
out.write(result.c_str(), std::min(ntrunc, static_cast<int>(result.size())));
out.write(result.c_str(), (std::min)(ntrunc, static_cast<int>(result.size())));
}
#define TINYFORMAT_DEFINE_FORMAT_TRUNCATED_CSTR(type) \
inline void formatTruncated(std::ostream& out, type* value, int ntrunc) \
Expand Down Expand Up @@ -332,8 +323,8 @@ inline void formatValue(std::ostream& out, const char* /*fmtBegin*/,
// void* respectively and format that instead of the value itself. For the
// %p conversion it's important to avoid dereferencing the pointer, which
// could otherwise lead to a crash when printing a dangling (const char*).
bool canConvertToChar = detail::is_convertible<T,char>::value;
bool canConvertToVoidPtr = detail::is_convertible<T, const void*>::value;
const bool canConvertToChar = detail::is_convertible<T,char>::value;
const bool canConvertToVoidPtr = detail::is_convertible<T, const void*>::value;
if(canConvertToChar && *(fmtEnd-1) == 'c')
detail::formatValueAsType<T, char>::invoke(out, value);
else if(canConvertToVoidPtr && *(fmtEnd-1) == 'p')
Expand Down Expand Up @@ -566,15 +557,17 @@ inline const char* printFormatStringLiteral(std::ostream& out, const char* fmt)
switch(*c)
{
case '\0':
out.write(fmt, static_cast<std::streamsize>(c - fmt));
out.write(fmt, c - fmt);
return c;
case '%':
out.write(fmt, static_cast<std::streamsize>(c - fmt));
out.write(fmt, c - fmt);
if(*(c+1) != '%')
return c;
// for "%%", tack trailing % onto next literal section.
fmt = ++c;
break;
default:
break;
}
}
}
Expand Down Expand Up @@ -644,6 +637,8 @@ inline const char* streamStateFromFormat(std::ostream& out, bool& spacePadPositi
spacePadPositive = false;
widthExtra = 1;
continue;
default:
break;
}
break;
}
Expand Down Expand Up @@ -757,6 +752,8 @@ inline const char* streamStateFromFormat(std::ostream& out, bool& spacePadPositi
TINYFORMAT_ERROR("tinyformat: Conversion spec incorrectly "
"terminated by end of string");
return c;
default:
break;
}
if(intConversion && precisionSet && !widthSet)
{
Expand Down Expand Up @@ -869,7 +866,7 @@ class FormatListN : public FormatList
template<typename... Args>
FormatListN(const Args&... args)
: FormatList(&m_formatterStore[0], N),
m_formatterStore TINYFORMAT_BRACED_INIT_WORKAROUND({ FormatArg(args)... })
m_formatterStore { FormatArg(args)... }
{ static_assert(sizeof...(args) == N, "Number of args must be N"); }
#else // C++98 version
void init(int) {}
Expand All @@ -878,7 +875,7 @@ class FormatListN : public FormatList
template<TINYFORMAT_ARGTYPES(n)> \
FormatListN(TINYFORMAT_VARARGS(n)) \
: FormatList(&m_formatterStore[0], n) \
{/*assert*n == N);*/init(0, TINYFORMAT_PASSARGS(n)); } \
{/*assert(n == N);*/init(0, TINYFORMAT_PASSARGS(n)); } \
\
template<TINYFORMAT_ARGTYPES(n)> \
void init(int i, TINYFORMAT_VARARGS(n)) \
Expand All @@ -892,11 +889,7 @@ class FormatListN : public FormatList
#endif

private:
#ifdef TINYFORMAT_USE_VARIADIC_TEMPLATES
std::array<FormatArg, N> m_formatterStore;
#else // C++98 version
FormatArg m_formatterStore[N];
#endif
};

// Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard
Expand Down

0 comments on commit ec16932

Please sign in to comment.