diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-21 01:05:29 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-21 01:05:29 +0200 |
commit | 1c35b863b47b558a1b2e7f2f4673643b4f0128d4 (patch) | |
tree | e54ac89d919c444975c65204df827a24ad948494 | |
parent | 593757d3d178e7f94376241a70ac29fe2bf94469 (diff) | |
download | EpisodeBrowser-1c35b863b47b558a1b2e7f2f4673643b4f0128d4.tar.gz |
Fetch wiki URL.
-rw-r--r-- | c/data.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -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")); } } |