summaryrefslogtreecommitdiff
path: root/plugins/Quotes/src/QuotesProviderYahoo.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-02-25 13:36:37 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-02-25 13:36:37 +0000
commit42095fb5cb7228f9dfb94965988029fd7f47b793 (patch)
tree6185ec5d7450fb474ed80b0ce95d0d1c0e0b26a8 /plugins/Quotes/src/QuotesProviderYahoo.cpp
parent8e891173c74ceaa0964f32be247f380fd5f8bcd1 (diff)
Quotes: major code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@16335 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Quotes/src/QuotesProviderYahoo.cpp')
-rw-r--r--plugins/Quotes/src/QuotesProviderYahoo.cpp137
1 files changed, 51 insertions, 86 deletions
diff --git a/plugins/Quotes/src/QuotesProviderYahoo.cpp b/plugins/Quotes/src/QuotesProviderYahoo.cpp
index ab09978d39..9b9ad36c4f 100644
--- a/plugins/Quotes/src/QuotesProviderYahoo.cpp
+++ b/plugins/Quotes/src/QuotesProviderYahoo.cpp
@@ -1,69 +1,50 @@
#include "stdafx.h"
-namespace
+void remove_quotes(tstring& s)
{
- void remove_quotes(tstring& s)
- {
- if (*s.begin() == _T('"'))
- {
- s.erase(s.begin());
- }
- if (*s.rbegin() == _T('"'))
- {
- tstring::iterator i(s.begin());
- std::advance(i, s.size() - 1);
- s.erase(i);
- }
- }
+ if (*s.begin() == _T('"'))
+ s.erase(s.begin());
- void remove_end_of_line(tstring& s)
- {
- if (*s.rbegin() == _T('\n'))
- {
- tstring::iterator i(s.begin());
- std::advance(i, s.size() - 1);
- s.erase(i);
- }
- if (*s.rbegin() == _T('\r'))
- {
- tstring::iterator i(s.begin());
- std::advance(i, s.size() - 1);
- s.erase(i);
- }
+ if (*s.rbegin() == _T('"')) {
+ tstring::iterator i(s.begin());
+ std::advance(i, s.size() - 1);
+ s.erase(i);
}
+}
- bool t2d(const tstring& s, double& d)
- {
- tistringstream stream(s);
- stream >> d;
- return ((false == stream.fail()) && (false == stream.bad()));
- // try
- // {
- // d = boost::lexical_cast<double>(s);
- // return true;
- // }
- // catch(boost::bad_lexical_cast& e)
- // {
- // }
- // return false;
+void remove_end_of_line(tstring& s)
+{
+ if (*s.rbegin() == _T('\n')) {
+ tstring::iterator i(s.begin());
+ std::advance(i, s.size() - 1);
+ s.erase(i);
+ }
+ if (*s.rbegin() == _T('\r')) {
+ tstring::iterator i(s.begin());
+ std::advance(i, s.size() - 1);
+ s.erase(i);
}
+}
- typedef std::vector<tstring> TStrings;
+bool t2d(const tstring& s, double& d)
+{
+ tistringstream stream(s);
+ stream >> d;
+ return ((false == stream.fail()) && (false == stream.bad()));
+}
- bool get_double_from_parsed_line(MCONTACT hContact, const TStrings& rasParsedLine, size_t nIndex, const char* pszDbName)
- {
- if (rasParsedLine.size() > nIndex)
- {
- double d = 0.0;
- if (true == t2d(rasParsedLine[nIndex], d))
- {
- return Quotes_DBWriteDouble(hContact, QUOTES_MODULE_NAME, pszDbName, d);
- }
- }
+typedef std::vector<tstring> TStrings;
- db_set_ts(hContact, QUOTES_MODULE_NAME, pszDbName, _T(""));
- return false;
+bool get_double_from_parsed_line(MCONTACT hContact, const TStrings& rasParsedLine, size_t nIndex, const char* pszDbName)
+{
+ if (rasParsedLine.size() > nIndex) {
+ double d = 0.0;
+ if (true == t2d(rasParsedLine[nIndex], d))
+ return Quotes_DBWriteDouble(hContact, QUOTES_MODULE_NAME, pszDbName, d);
}
+
+ db_set_ts(hContact, QUOTES_MODULE_NAME, pszDbName, _T(""));
+ return false;
}
void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts)
@@ -75,59 +56,47 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts)
TQuoteID2ContractHandles aQuoteID2Handles;
tostringstream oURL;
oURL << sURL << _T("dioksin.txt?s=");
- for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i)
- {
+ for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i) {
MCONTACT hContact = *i;
if (bUseExtendedStatus)
- {
SetContactStatus(hContact, ID_STATUS_OCCUPIED);
- }
tstring sQuoteID = Quotes_DBGetStringT(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_ID);
aQuoteID2Handles[sQuoteID] = hContact;
if (i != anContacts.begin())
- {
oURL << _T("+");
- }
+
oURL << sQuoteID;
}
- if (true == IsOnline())
- {
+ if (true == IsOnline()) {
oURL << _T("&f=snl1ohgpc1");
CHTTPSession http;
- if ((true == http.OpenURL(oURL.str())) && (true == IsOnline()))
- {
+ if ((true == http.OpenURL(oURL.str())) && (true == IsOnline())) {
tstring sFile;
- if ((true == http.ReadResponce(sFile)) && (true == IsOnline()))
- {
+ if ((true == http.ReadResponce(sFile)) && (true == IsOnline())) {
tistringstream out_str(sFile.c_str());
- while (false == out_str.eof())
- {
+ while (false == out_str.eof()) {
tstring sLine;
std::getline(out_str, sLine);
- if (false == sLine.empty())
- {
+ if (false == sLine.empty()) {
remove_end_of_line(sLine);
TStrings asStrings;
- for (tstring::size_type nPos = sLine.find(_T(',')); nPos != tstring::npos; nPos = sLine.find(_T(',')))
- {
+ for (tstring::size_type nPos = sLine.find(_T(',')); nPos != tstring::npos; nPos = sLine.find(_T(','))) {
tstring::iterator i(sLine.begin());
std::advance(i, nPos);
tstring s(sLine.begin(), i);
remove_quotes(s);
asStrings.push_back(s);
- if (i != sLine.end())
- {
+ if (i != sLine.end()) {
std::advance(i, 1);
}
sLine.erase(sLine.begin(), i);
}
- if (false == sLine.empty())
- {
+ if (false == sLine.empty()) {
remove_quotes(sLine);
if (false == sLine.empty())
@@ -135,8 +104,7 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts)
}
size_t cItems = asStrings.size();
- if (cItems >= 3)
- {
+ if (cItems >= 3) {
enum
{
indexSymbol = 0,
@@ -149,12 +117,10 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts)
indexChange
};
auto it3 = aQuoteID2Handles.find(asStrings[indexSymbol]);
- if (it3 != aQuoteID2Handles.end())
- {
+ if (it3 != aQuoteID2Handles.end()) {
MCONTACT hContact = it3->second;
double dRate = 0.0;
- if (true == t2d(asStrings[indexLastTrade], dRate))
- {
+ if (true == t2d(asStrings[indexLastTrade], dRate)) {
db_set_ts(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_DESCRIPTION, asStrings[indexName].c_str());
get_double_from_parsed_line(hContact, asStrings, indexOpen, DB_STR_YAHOO_OPEN_VALUE);
@@ -172,10 +138,9 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts)
}
}
- if (true == IsOnline())
- {
+ if (true == IsOnline()) {
std::for_each(aQuoteID2Handles.begin(), aQuoteID2Handles.end(),
- [](const TQuoteID2ContractHandles::value_type& pair){SetContactStatus(pair.second, ID_STATUS_NA); });
+ [](const TQuoteID2ContractHandles::value_type& pair) { SetContactStatus(pair.second, ID_STATUS_NA); });
}
}
}