From 1c35b863b47b558a1b2e7f2f4673643b4f0128d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 21 Aug 2022 01:05:29 +0200 Subject: Fetch wiki URL. --- c/data.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'c') 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; template -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& fvElv, FileView& 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& fvElv, FileView& 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")); } } -- cgit v1.2.3