Skip to content

Commit

Permalink
Several changes:
Browse files Browse the repository at this point in the history
 - We can get an exception since Boost 1.67
 - Translation fix for JWt
  • Loading branch information
RockinRoel committed Dec 14, 2018
1 parent aa7b878 commit d57f719
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
24 changes: 18 additions & 6 deletions src/Wt/WDate.C
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ WDate WDate::addDays(int ndays) const
{
if (isValid()) {
date d(year(), month(), day());
d += date_duration(ndays);
if (d.year() > 9999 || d.year() < 1400)
try {
d += date_duration(ndays);
if (d.year() > 9999 || d.year() < 1400)
return WDate();
} catch (const std::out_of_range &e) {
return WDate();
}
return WDate(d.year(), d.month(), d.day());
} else
return WDate();
Expand All @@ -68,9 +72,13 @@ WDate WDate::addMonths(int nmonths) const
{
if (isValid()) {
date d(year(), month(), day());
d += months(nmonths);
if (d.year() > 9999 || d.year() < 1400)
try {
d += months(nmonths);
if (d.year() > 9999 || d.year() < 1400)
return WDate();
} catch (const std::out_of_range &e) {
return WDate();
}
return WDate(d.year(), d.month(), d.day());
} else
return WDate();
Expand All @@ -80,9 +88,13 @@ WDate WDate::addYears(int nyears) const
{
if (isValid()) {
date d(year(), month(), day());
d += years(nyears);
if (d.year() > 9999 || d.year() < 1400)
try {
d += years(nyears);
if (d.year() > 9999 || d.year() < 1400)
return WDate();
} catch (const std::out_of_range &e) {
return WDate();
}
return WDate(d.year(), d.month(), d.day());
} else
return WDate();
Expand Down
16 changes: 12 additions & 4 deletions src/web/ColorUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ inline bool ishex(char c) {
(c >= 'A' && c <= 'F');
}

inline bool tailIsHex(const std::string &str) {
for (std::size_t i = 1; i < str.size(); ++i) {
if (!ishex(str[i]))
return false;
}
return true;
}

}

namespace Wt {
Expand Down Expand Up @@ -66,20 +74,20 @@ WColor parseCssColor(const std::string &name)
int alpha = 255;

if (boost::starts_with(n, "#")) {
if (n.size() - 1 == 3 && std::count_if(n.begin() + 1, n.end(), ishex) == 3) { // #rgb
if (n.size() - 1 == 3 && tailIsHex(n)) { // #rgb
red = replicateHex(n.substr(1, 1));
green = replicateHex(n.substr(2,1));
blue = replicateHex(n.substr(3,1));
} else if (n.size() - 1 == 4 && std::count_if(n.begin() + 1, n.end(), ishex) == 4) { // #rgba
} else if (n.size() - 1 == 4 && tailIsHex(n)) { // #rgba
red = replicateHex(n.substr(1, 1));
green = replicateHex(n.substr(2,1));
blue = replicateHex(n.substr(3,1));
alpha = replicateHex(n.substr(4,1));
} else if (n.size() - 1 == 6 && std::count_if(n.begin() + 1, n.end(), ishex) == 6) { // #rrggbb
} else if (n.size() - 1 == 6 && tailIsHex(n)) { // #rrggbb
red = Utils::hexToInt(n.substr(1,2).c_str());
green = Utils::hexToInt(n.substr(3,2).c_str());
blue = Utils::hexToInt(n.substr(5,2).c_str());
} else if (n.size() - 1 == 8 && std::count_if(n.begin() + 1, n.end(), ishex) == 8) { // #rrggbbaa
} else if (n.size() - 1 == 8 && tailIsHex(n)) { // #rrggbbaa
red = Utils::hexToInt(n.substr(1,2).c_str());
green = Utils::hexToInt(n.substr(3,2).c_str());
blue = Utils::hexToInt(n.substr(5,2).c_str());
Expand Down

0 comments on commit d57f719

Please sign in to comment.