restrict conversions being done in strbuffer
This commit is contained in:
@@ -73,8 +73,19 @@ template <typename A, typename B> std::string StringPairToString(const std::pair
|
||||
return pair.first;
|
||||
}
|
||||
|
||||
template <typename T> struct StringConverter {
|
||||
const char *operator()(const char *s) { return s; }
|
||||
};
|
||||
template <> struct StringConverter< basic_buffer<wchar_t> > {
|
||||
std::wstring operator()(const char *s) { return ToWString(s); }
|
||||
};
|
||||
template <> struct StringConverter<Scrollpad> {
|
||||
std::basic_string<my_char_t> operator()(const char *s) { return TO_WSTRING(s); }
|
||||
};
|
||||
|
||||
template <typename C> void String2Buffer(const std::basic_string<C> &s, basic_buffer<C> &buf)
|
||||
{
|
||||
StringConverter< basic_buffer<C> > cnv;
|
||||
for (typename std::basic_string<C>::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||
{
|
||||
if (*it == '$')
|
||||
@@ -107,7 +118,7 @@ template <typename C> void String2Buffer(const std::basic_string<C> &s, basic_bu
|
||||
case '/':
|
||||
if (++it == s.end())
|
||||
{
|
||||
buf << "$/";
|
||||
buf << cnv("$/");
|
||||
break;
|
||||
}
|
||||
switch (*it)
|
||||
@@ -149,6 +160,8 @@ template <typename C> void String2Buffer(const std::basic_string<C> &s, basic_bu
|
||||
|
||||
template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
|
||||
{
|
||||
StringConverter<T> cnv;
|
||||
|
||||
const unsigned MINUTE = 60;
|
||||
const unsigned HOUR = 60*MINUTE;
|
||||
const unsigned DAY = 24*HOUR;
|
||||
@@ -157,37 +170,37 @@ template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
|
||||
unsigned years = length/YEAR;
|
||||
if (years)
|
||||
{
|
||||
buf << years << (short_names ? "y" : (years == 1 ? " year" : " years"));
|
||||
buf << years << cnv(short_names ? "y" : (years == 1 ? " year" : " years"));
|
||||
length -= years*YEAR;
|
||||
if (length)
|
||||
buf << ", ";
|
||||
buf << cnv(", ");
|
||||
}
|
||||
unsigned days = length/DAY;
|
||||
if (days)
|
||||
{
|
||||
buf << days << (short_names ? "d" : (days == 1 ? " day" : " days"));
|
||||
buf << days << cnv(short_names ? "d" : (days == 1 ? " day" : " days"));
|
||||
length -= days*DAY;
|
||||
if (length)
|
||||
buf << ", ";
|
||||
buf << cnv(", ");
|
||||
}
|
||||
unsigned hours = length/HOUR;
|
||||
if (hours)
|
||||
{
|
||||
buf << hours << (short_names ? "h" : (hours == 1 ? " hour" : " hours"));
|
||||
buf << hours << cnv(short_names ? "h" : (hours == 1 ? " hour" : " hours"));
|
||||
length -= hours*HOUR;
|
||||
if (length)
|
||||
buf << ", ";
|
||||
buf << cnv(", ");
|
||||
}
|
||||
unsigned minutes = length/MINUTE;
|
||||
if (minutes)
|
||||
{
|
||||
buf << minutes << (short_names ? "m" : (minutes == 1 ? " minute" : " minutes"));
|
||||
buf << minutes << cnv(short_names ? "m" : (minutes == 1 ? " minute" : " minutes"));
|
||||
length -= minutes*MINUTE;
|
||||
if (length)
|
||||
buf << ", ";
|
||||
buf << cnv(", ");
|
||||
}
|
||||
if (length)
|
||||
buf << length << (short_names ? "s" : (length == 1 ? " second" : " seconds"));
|
||||
buf << length << cnv(short_names ? "s" : (length == 1 ? " second" : " seconds"));
|
||||
}
|
||||
|
||||
template <typename T> void ShowTag(T &buf, const std::string &tag)
|
||||
|
||||
Reference in New Issue
Block a user