summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-02-27 22:22:00 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-02-27 22:22:00 +0300
commitb671f9f84a415206fde423b7dbbe0c15a9ec9b47 (patch)
treec043e1c0fd49be705ab68002f8633e59726ae940
parentea5a8c7d51ff9ee1f2abcae19a1a4c29d98a6114 (diff)
SmileyAdd: attempt to fix code insertion
-rw-r--r--include/m_regexp.h8
-rw-r--r--plugins/SmileyAdd/src/smileys.cpp41
2 files changed, 29 insertions, 20 deletions
diff --git a/include/m_regexp.h b/include/m_regexp.h
index a497176f59..6eff132083 100644
--- a/include/m_regexp.h
+++ b/include/m_regexp.h
@@ -73,14 +73,12 @@ public:
__forceinline bool isValid() const { return m_bIsValid; }
__forceinline int numMatches() const { return m_nMatches; }
- int getPos() const
- {
- return (m_nMatches >= 0) ? m_offsets[0] : 0;
- }
+ __forceinline int getPos() const { return m_offsets[0]; }
+ __forceinline int getLength() const { return m_offsets[1] - m_offsets[0]; }
CMStringW getMatch()
{
- return CMStringW(m_prevText + m_offsets[0], m_offsets[1] - m_offsets[0]);
+ return CMStringW(m_prevText + getPos(), getLength());
}
CMStringW getGroup(int i)
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp
index 8d6e69845f..16de9ebdf9 100644
--- a/plugins/SmileyAdd/src/smileys.cpp
+++ b/plugins/SmileyAdd/src/smileys.cpp
@@ -294,12 +294,36 @@ void SmileyPackType::AddTriggersToSmileyLookup(void)
}
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static MRegexp16 isCode(L"\\&\\#(\\d*)\\;");
+
+static void replaceCodes(CMStringW &str)
+{
+ if (isCode.match(str) < 0)
+ return;
+
+ str.Delete(isCode.getPos(), isCode.getLength());
+
+ uint32_t iCode = _wtoi(isCode.getGroup(1));
+ wchar_t tmp[3] = { 0, 0, 0 };
+ if (iCode < 0x10000)
+ tmp[0] = LOWORD(iCode), tmp[1] = HIWORD(iCode);
+ else {
+ iCode -= 0x10000;
+ tmp[0] = 0xD800 + (iCode >> 10);
+ tmp[1] = 0xDC00 + (iCode & 0x3FF);
+ }
+ str.Insert(isCode.getPos(), tmp);
+}
+
void SmileyPackType::ReplaceAllSpecials(const CMStringW &Input, CMStringW &Output)
{
Output = Input;
Output.Replace(L"%%_%%", L" ");
Output.Replace(L"%%__%%", L" ");
Output.Replace(L"%%''%%", L"\"");
+ replaceCodes(Output);
}
void SmileyPackType::Clear(void)
@@ -842,8 +866,6 @@ void SmileyCategoryListType::AddAllProtocolsAsCategory(void)
static const CMStringW testString(L"Test String");
-static MRegexp16 isCode(L"\\&\\#(\\d*)\\;");
-
SmileyLookup::SmileyLookup(const CMStringW &str, const bool regexs, const int ind, const CMStringW &smpt)
{
m_ind = ind;
@@ -857,19 +879,8 @@ SmileyLookup::SmileyLookup(const CMStringW &str, const bool regexs, const int in
}
}
else {
- if (isCode.match(str) >= 0) {
- uint32_t iCode = _wtoi(isCode.getGroup(1));
- wchar_t tmp[3] = { 0, 0, 0 };
- if (iCode < 0x10000)
- tmp[0] = LOWORD(iCode), tmp[1] = HIWORD(iCode);
- else {
- iCode -= 0x10000;
- tmp[0] = 0xD800 + (iCode >> 10);
- tmp[1] = 0xDC00 + (iCode & 0x3FF);
- }
- m_text = tmp;
- }
- else m_text = str;
+ m_text = str;
+ replaceCodes(m_text);
m_valid = !str.IsEmpty();
}
}