From cf92418ee4543234e59ee31705925be465cc1b1f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 11 Jul 2018 14:03:18 +0300 Subject: another obsolete helper died --- plugins/ListeningTo/src/listeningto.cpp | 102 +++++++++++--------------------- plugins/ListeningTo/src/stdafx.h | 5 +- plugins/ListeningTo/src/variables.cpp | 6 +- plugins/ListeningTo/src/version.h | 2 +- 4 files changed, 40 insertions(+), 75 deletions(-) (limited to 'plugins/ListeningTo') diff --git a/plugins/ListeningTo/src/listeningto.cpp b/plugins/ListeningTo/src/listeningto.cpp index 4244c91c22..79da8a41a7 100644 --- a/plugins/ListeningTo/src/listeningto.cpp +++ b/plugins/ListeningTo/src/listeningto.cpp @@ -405,71 +405,36 @@ ProtocolInfo* GetProtoInfo(char *proto) return nullptr; } -static void ReplaceVars(Buffer *buffer, MCONTACT hContact, wchar_t **variables, int numVariables) -{ - if (buffer->len < 3) - return; - - if (numVariables < 0) - return; - - for (size_t i = buffer->len - 1; i > 0; i--) { - if (buffer->str[i] == '%') { - // Find previous - size_t j; - for (j = i - 1; j > 0 && ((buffer->str[j] >= 'a' && buffer->str[j] <= 'z') - || (buffer->str[j] >= 'A' && buffer->str[j] <= 'Z') - || buffer->str[j] == '-' - || buffer->str[j] == '_'); j--); - - if (buffer->str[j] == '%') { - size_t foundLen = i - j + 1; - if (foundLen == 9 && wcsncmp(&buffer->str[j], L"%contact%", 9) == 0) { - buffer->replace(j, i + 1, Clist_GetContactDisplayName(hContact)); - } - else if (foundLen == 6 && wcsncmp(&buffer->str[j], L"%date%", 6) == 0) { - wchar_t tmp[128]; - TimeZone_ToStringT(time(0), L"d s", tmp, _countof(tmp)); - buffer->replace(j, i + 1, tmp); - } - else { - for (int k = 0; k < numVariables; k += 2) { - size_t len = mir_wstrlen(variables[k]); - if (foundLen == len + 2 && wcsncmp(&buffer->str[j] + 1, variables[k], len) == 0) { - buffer->replace(j, i + 1, variables[k + 1]); - break; - } - } - } - } - - i = j; - if (i == 0) - break; - } - else if (buffer->str[i] == '\\' && i + 1 <= buffer->len - 1 && buffer->str[i + 1] == 'n') { - buffer->str[i] = '\r'; - buffer->str[i + 1] = '\n'; - } +static void ReplaceVars(CMStringW &buffer, MCONTACT hContact, wchar_t **variables, int numVariables) +{ + buffer.Replace(L"\\n", L""); + buffer.Replace(L"%contact%", Clist_GetContactDisplayName(hContact)); + + wchar_t tmp[128]; + TimeZone_ToStringT(time(0), L"d s", tmp, _countof(tmp)); + buffer.Replace(L"%date%", tmp); + + for (int k = 0; k < numVariables; k += 2) { + CMStringW find('%'); + find.Append(variables[k]); + find.AppendChar('%'); + buffer.Replace(find, variables[k+1]); } } -void ReplaceTemplate(Buffer *out, MCONTACT hContact, wchar_t *templ, wchar_t **vars, int numVars) +void ReplaceTemplate(CMStringW &out, MCONTACT hContact, wchar_t *templ, wchar_t **vars, int numVars) { - if (ServiceExists(MS_VARS_FORMATSTRING)) { wchar_t *tmp = variables_parse_ex(templ, nullptr, hContact, vars, numVars); if (tmp != nullptr) { - out->append(tmp); + out.Append(tmp); mir_free(tmp); - out->pack(); return; } } - out->append(templ); + out.Append(templ); ReplaceVars(out, hContact, vars, numVars); - out->pack(); } void SetListeningInfo(char *proto, LISTENINGTOINFO *lti = nullptr) @@ -511,14 +476,14 @@ void SetListeningInfo(char *proto, LISTENINGTOINFO *lti = nullptr) L"listening", opts.nothing }; - Buffer name; - ReplaceTemplate(&name, NULL, opts.xstatus_name, fr, _countof(fr)); - Buffer msg; - ReplaceTemplate(&msg, NULL, opts.xstatus_message, fr, _countof(fr)); + CMStringW name; + ReplaceTemplate(name, NULL, opts.xstatus_name, fr, _countof(fr)); + CMStringW msg; + ReplaceTemplate(msg, NULL, opts.xstatus_message, fr, _countof(fr)); ics.flags = CSSF_UNICODE | CSSF_MASK_STATUS | CSSF_MASK_NAME | CSSF_MASK_MESSAGE; - ics.ptszName = name.str; - ics.ptszMessage = msg.str; + ics.ptszName = name.GetBuffer(); + ics.ptszMessage = msg.GetBuffer(); CallProtoService(proto, PS_SETCUSTOMSTATUSEX, 0, (LPARAM)&ics); } @@ -592,17 +557,16 @@ void SetListeningInfo(char *proto, LISTENINGTOINFO *lti = nullptr) L"type", UNKNOWN(lti->ptszType) }; - Buffer name; - ReplaceTemplate(&name, NULL, opts.xstatus_name, fr, _countof(fr)); - Buffer msg; - ReplaceTemplate(&msg, NULL, opts.xstatus_message, fr, _countof(fr)); + CMStringW name; + ReplaceTemplate(name, NULL, opts.xstatus_name, fr, _countof(fr)); + CMStringW msg; + ReplaceTemplate(msg, NULL, opts.xstatus_message, fr, _countof(fr)); status = XSTATUS_MUSIC; ics.flags = CSSF_UNICODE | CSSF_MASK_STATUS | CSSF_MASK_NAME | CSSF_MASK_MESSAGE; ics.status = &status; - ics.ptszName = name.str; - ics.ptszMessage = msg.str; - + ics.ptszName = name.GetBuffer(); + ics.ptszMessage = msg.GetBuffer(); CallProtoService(proto, PS_SETCUSTOMSTATUSEX, 0, (LPARAM)&ics); mir_free(fr[1]); @@ -685,7 +649,7 @@ INT_PTR GetTextFormat(WPARAM, LPARAM) return (INT_PTR)mir_wstrdup(opts.templ); } -wchar_t *GetParsedFormat(LISTENINGTOINFO *lti) +wchar_t* GetParsedFormat(LISTENINGTOINFO *lti) { if (lti == nullptr) return nullptr; @@ -702,9 +666,9 @@ wchar_t *GetParsedFormat(LISTENINGTOINFO *lti) L"type", UNKNOWN(lti->ptszType) }; - Buffer ret; - ReplaceTemplate(&ret, NULL, opts.templ, fr, _countof(fr)); - return ret.detach(); + CMStringW ret; + ReplaceTemplate(ret, NULL, opts.templ, fr, _countof(fr)); + return ret.Detach(); } INT_PTR GetParsedFormat(WPARAM, LPARAM lParam) diff --git a/plugins/ListeningTo/src/stdafx.h b/plugins/ListeningTo/src/stdafx.h index a85b455ff7..2236e6a83d 100644 --- a/plugins/ListeningTo/src/stdafx.h +++ b/plugins/ListeningTo/src/stdafx.h @@ -39,6 +39,8 @@ Boston, MA 02111-1307, USA. #include #include #include +#include +#include #include #include @@ -56,7 +58,6 @@ struct CMPlugin : public PLUGIN }; #include "../../utils/mir_options.h" -#include "../../utils/mir_buffer.h" #include "music.h" #include "resource.h" @@ -120,7 +121,7 @@ static bool IsEmpty(const WCHAR *str) void InitServices(); -void ReplaceTemplate(Buffer *out, MCONTACT hContact, wchar_t *templ, wchar_t **vars, int numVars); +void ReplaceTemplate(CMStringW &out, MCONTACT hContact, wchar_t *templ, wchar_t **vars, int numVars); wchar_t* VariablesParseInfo(ARGUMENTSINFO *ai); wchar_t* VariablesParseType(ARGUMENTSINFO *ai); diff --git a/plugins/ListeningTo/src/variables.cpp b/plugins/ListeningTo/src/variables.cpp index 73cb62f6d4..cbb34984bf 100644 --- a/plugins/ListeningTo/src/variables.cpp +++ b/plugins/ListeningTo/src/variables.cpp @@ -42,9 +42,9 @@ wchar_t* VariablesParseInfo(ARGUMENTSINFO *ai) L"type", UNKNOWN(lti->ptszType) }; - Buffer ret; - ReplaceTemplate(&ret, NULL, opts.templ, fr, _countof(fr)); - return ret.detach(); + CMStringW ret; + ReplaceTemplate(ret, NULL, opts.templ, fr, _countof(fr)); + return ret.Detach(); } #define VARIABLES_PARSE_BODY(__field__) \ diff --git a/plugins/ListeningTo/src/version.h b/plugins/ListeningTo/src/version.h index d65fb44463..215045a22f 100644 --- a/plugins/ListeningTo/src/version.h +++ b/plugins/ListeningTo/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 4 #define __RELEASE_NUM 0 -#define __BUILD_NUM 0 +#define __BUILD_NUM 1 #include -- cgit v1.2.3