summaryrefslogtreecommitdiff
path: root/src/mir_app
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-09-05 15:35:12 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-09-05 15:35:12 +0300
commit28c2eb96831f1e6088e4b498f8125b050585dd3b (patch)
tree2bff3cbedb270fdba4288c0eacf2b5381a77b4c9 /src/mir_app
parenta074799eaf3218c979fa07d8a76525aa0ec7b9fd (diff)
SRMM: quoting unification
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
-rw-r--r--src/mir_app/src/srmm_util.cpp48
3 files changed, 50 insertions, 0 deletions
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index eef3369c58..d4bd43e373 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -902,3 +902,4 @@ Clist_GroupSaveExpanded @1003 NONAME
?bEnableCustomLogs@Chat@@3V?$CMOption@_N@@A @1019 NONAME
?Srmm_IsCustomLogUsed@@YG_NXZ @1020 NONAME
?IconFlashTime@Clist@@3V?$CMOption@I@@A @1021 NONAME
+?Srmm_Quote@@YG?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@PB_WH@Z @1022 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index cee812529b..9a2dfd3ef0 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -902,3 +902,4 @@ Clist_GroupSaveExpanded @1003 NONAME
?bEnableCustomLogs@Chat@@3V?$CMOption@_N@@A @1019 NONAME
?Srmm_IsCustomLogUsed@@YA_NXZ @1020 NONAME
?IconFlashTime@Clist@@3V?$CMOption@I@@A @1021 NONAME
+?Srmm_Quote@@YA?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@PEB_WH@Z @1022 NONAME
diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp
index a13af78623..dd69502e34 100644
--- a/src/mir_app/src/srmm_util.cpp
+++ b/src/mir_app/src/srmm_util.cpp
@@ -260,3 +260,51 @@ MIR_APP_DLL(void) Srmm_SetStatusText(MCONTACT hContact, const wchar_t *wszText,
SSTParam param = { hwnd, wszText, hIcon };
CallFunctionSync(sttSetStatusText, &param);
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Quote
+
+MIR_APP_DLL(CMStringW) Srmm_Quote(const wchar_t *pwzsText, int iWrapWidth)
+{
+ CMStringW ret;
+
+ if (auto *p = pwzsText) {
+ bool justDoneLineBreak = true;
+ for (int lineChar = 0; *p;) {
+ if (justDoneLineBreak && *p != '\r' && *p != '\n') {
+ ret.AppendChar('>');
+ ret.AppendChar(' ');
+ lineChar = 2;
+ }
+
+ if (lineChar == iWrapWidth && *p != '\r' && *p != '\n') {
+ int decreasedBy = 0;
+ for (int outChar = ret.GetLength() - 1; lineChar > 10; lineChar--, p--, outChar--, decreasedBy++)
+ if (ret[outChar] == ' ' || ret[outChar] == '\t' || ret[outChar] == '-')
+ break;
+
+ if (lineChar <= 10) {
+ lineChar += decreasedBy;
+ p += decreasedBy;
+ }
+ else p++;
+ ret.Append(L"\r\n");
+ justDoneLineBreak = true;
+ continue;
+ }
+ ret.AppendChar(*p);
+ lineChar++;
+ if (*p == '\n' || *p == '\r') {
+ if (*p == '\r' && p[1] != '\n')
+ ret.AppendChar('\n');
+ justDoneLineBreak = 1;
+ lineChar = 0;
+ }
+ else justDoneLineBreak = false;
+ p++;
+ }
+ }
+
+ ret.Append(L"\r\n");
+ return ret;
+}