aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/data.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/c/data.cpp b/c/data.cpp
index 1e59b8b..c2a8909 100644
--- a/c/data.cpp
+++ b/c/data.cpp
@@ -69,12 +69,8 @@ static inline void XmlFree(void* p) { xmlFree(p); }
using XmlCharPtr = XmlPtr<XmlFree, xmlChar*>;
template <size_t N>
-bool WriteNodeContent(wchar_t (&dst)[N], const xmlNodePtr node)
+bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8)
{
- XmlCharPtr utf8 = xmlNodeGetContent(node);
- if (!utf8)
- return false;
-
/* Truncate if source is larger than destination. */
utf8[N] = 0;
int lenUtf8 = xmlStrlen(utf8);
@@ -132,6 +128,9 @@ void FetchData(FileView<ElvDataA>& fvElv, FileView<DlvDataA>& fvDlv)
if (xmlChildElementCount(node) != 8)
throw std::runtime_error("unexpected remote data format");
+ ElvDataA& e = fvElv.At(i);
+ DlvDataA& d = fvDlv.At(i);
+
/* Get cells. */
const xmlNodePtr nodeEp = xmlFirstElementChild(node);
const xmlNodePtr nodeTitle = xmlNextElementSibling(xmlNextElementSibling(nodeEp));
@@ -140,14 +139,16 @@ void FetchData(FileView<ElvDataA>& fvElv, FileView<DlvDataA>& fvDlv)
xmlNextElementSibling(xmlNextElementSibling(nodeDate)));
const xmlNodePtr nodeHint = xmlNextElementSibling(nodeSource);
- ElvDataA& e = fvElv.At(i);
- DlvDataA& d = fvDlv.At(i);
-
- WriteNodeContent(e.siEp, nodeEp);
+ WcharsFromXmlchars(e.siEp, xmlNodeGetContent(nodeEp));
e.siEp[wcscspn(e.siEp, L"W")] = 0; /* Remove WPS suffix. */
- WriteNodeContent(e.title, nodeTitle);
- WriteNodeContent(d.date, nodeDate);
- WriteNodeContent(d.source, nodeSource);
- WriteNodeContent(d.hint, nodeHint);
+ WcharsFromXmlchars(e.title, xmlNodeGetContent(nodeTitle));
+ WcharsFromXmlchars(d.date, xmlNodeGetContent(nodeDate));
+ WcharsFromXmlchars(d.source, xmlNodeGetContent(nodeSource));
+ WcharsFromXmlchars(d.hint, xmlNodeGetContent(nodeHint));
+
+ /* Get wiki URL. */
+ const xmlNodePtr nodeLink = xmlFirstElementChild(nodeTitle);
+ if (nodeLink)
+ WcharsFromXmlchars(d.wiki, xmlGetProp(nodeLink, (const xmlChar*)"href"));
}
}