summaryrefslogtreecommitdiff
path: root/src/mmo/human_time_diff.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-10-25 15:24:26 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-10-26 14:21:48 -0700
commit86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80 (patch)
tree2710c62fe71d5e0d2e228fba9c951a040c4dcddf /src/mmo/human_time_diff.hpp
parent6800761863dd45b6055768febc6ace6a20120dc7 (diff)
downloadtmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.tar.gz
tmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.tar.bz2
tmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.tar.xz
tmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.zip
Fix header ranking
Diffstat (limited to 'src/mmo/human_time_diff.hpp')
-rw-r--r--src/mmo/human_time_diff.hpp45
1 files changed, 1 insertions, 44 deletions
diff --git a/src/mmo/human_time_diff.hpp b/src/mmo/human_time_diff.hpp
index b5c19fb..40352d0 100644
--- a/src/mmo/human_time_diff.hpp
+++ b/src/mmo/human_time_diff.hpp
@@ -24,8 +24,6 @@
#include "../strings/xstring.hpp"
-#include "extract.hpp"
-
namespace tmwa
{
@@ -44,46 +42,5 @@ struct HumanTimeDiff
return !bool(*this);
}
};
-
-inline
-bool extract(XString str, HumanTimeDiff *iv)
-{
- // str is a sequence of [-+]?[0-9]+([ay]|m|[jd]|h|mn|s)
- // there are NO spaces here
- // parse by counting the number starts
- auto is_num = [](char c)
- { return c == '-' || c == '+' || ('0' <= c && c <= '9'); };
- if (!str || !is_num(str.front()))
- return false;
- *iv = HumanTimeDiff{};
- while (str)
- {
- auto it = std::find_if_not(str.begin(), str.end(), is_num);
- auto it2 = std::find_if(it, str.end(), is_num);
- XString number = str.xislice_h(it);
- XString suffix = str.xislice(it, it2);
- str = str.xislice_t(it2);
-
- short *ptr = nullptr;
- if (suffix == "y"_s || suffix == "a"_s)
- ptr = &iv->year;
- else if (suffix == "m"_s)
- ptr = &iv->month;
- else if (suffix == "j"_s || suffix == "d"_s)
- ptr = &iv->day;
- else if (suffix == "h"_s)
- ptr = &iv->hour;
- else if (suffix == "mn"_s)
- ptr = &iv->minute;
- else if (suffix == "s"_s)
- ptr = &iv->second;
- else
- return false;
- if (number.startswith('+') && !number.startswith("+-"_s))
- number = number.xslice_t(1);
- if (*ptr || !extract(number, ptr))
- return false;
- }
- return true;
-}
+bool extract(XString str, HumanTimeDiff *iv);
} // namespace tmwa