diff options
author | George Hazan <ghazan@miranda.im> | 2019-03-02 12:32:44 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-03-02 12:32:55 +0300 |
commit | 931a7dc1ac0dbc7e6c1083583ced915e572f5b47 (patch) | |
tree | 9fe9a6448d44030e26aa7107ce16044ed413e0d0 /protocols/CurrencyRates/src/DBUtils.cpp | |
parent | dd7d9954042254e66e3bbbec7195c6be8b1a0663 (diff) |
all protocols (even virtual ones) moved to the Protocols folder
Diffstat (limited to 'protocols/CurrencyRates/src/DBUtils.cpp')
-rw-r--r-- | protocols/CurrencyRates/src/DBUtils.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/protocols/CurrencyRates/src/DBUtils.cpp b/protocols/CurrencyRates/src/DBUtils.cpp new file mode 100644 index 0000000000..20189c0f3f --- /dev/null +++ b/protocols/CurrencyRates/src/DBUtils.cpp @@ -0,0 +1,43 @@ +#include "StdAfx.h" + +std::wstring GetNodeText(const TiXmlElement *pNode) +{ + auto *pszText = pNode->GetText(); + if (pszText) + return Utf2T(pszText).get(); + + return std::wstring(); +} + +std::wstring CurrencyRates_DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *pszDefValue) +{ + if (pszDefValue == nullptr) + pszDefValue = L""; + + return std::wstring(ptrW(db_get_wsa(hContact, szModule, szSetting, pszDefValue))); +} + +bool CurrencyRates_DBWriteDouble(MCONTACT hContact, const char *szModule, const char *szSetting, double dValue) +{ + return 0 == db_set_blob(hContact, szModule, szSetting, &dValue, sizeof(dValue)); +} + +bool CurrencyRates_DBReadDouble(MCONTACT hContact, const char *szModule, const char *szSetting, double& rdValue) +{ + DBVARIANT dbv = {}; + dbv.type = DBVT_BLOB; + + bool bResult = ((0 == db_get(hContact, szModule, szSetting, &dbv)) && (DBVT_BLOB == dbv.type)); + if (bResult) + rdValue = *reinterpret_cast<double*>(dbv.pbVal); + + db_free(&dbv); + return bResult; +} + +void FixInvalidChars(tstring &s) +{ + for (auto &c : s) + if (wcschr(L"\\/:*?\"<>|", c)) + c = '_'; +} |