diff options
Diffstat (limited to 'plugins/NewStory/src/utils.cpp')
-rw-r--r-- | plugins/NewStory/src/utils.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index d1bf1e82a7..438246cf43 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -17,3 +17,62 @@ bool CheckFilter(wchar_t *buf, wchar_t *filter) return true; return false; } + +///////////////////////////////////////////////////////////////////////////////////////// + +struct +{ + wchar_t *pStart, *pEnd; + size_t cbStart, cbEnd; +} +static bbcodes[] = +{ + { L"[b]", nullptr }, + { L"[/b]", nullptr }, + { L"[i]", nullptr }, + { L"[/i]", nullptr }, + { L"[u]", nullptr }, + { L"[/u]", nullptr }, + { L"[s]", nullptr }, + { L"[/s]", nullptr }, + + { L"[color=", L"]" }, + { L"[/color]", nullptr }, + + { L"[$hicon=", L"$]" }, + + { L"[url]", L"[/url]" }, + { L"[url=", L"]", }, + { L"[img]", L"[/img]" }, + { L"[img=", L"]" }, +}; + +void RemoveBbcodes(wchar_t *pwszText) +{ + if (!pwszText) + return; + + if (bbcodes[0].cbStart == 0) + for (auto &it : bbcodes) { + it.cbStart = wcslen(it.pStart); + if (it.pEnd) + it.cbEnd = wcslen(it.pEnd); + } + + for (auto *p = wcschr(pwszText, '['); p != 0; p = wcschr(p, '[')) { + for (auto &it : bbcodes) { + if (wcsncmp(p, it.pStart, it.cbStart)) + continue; + + strdelw(p, it.cbStart); + + if (it.pEnd) + if (auto *pp = wcsstr(p, it.pEnd)) { + strdelw(p, size_t(pp - p)); + strdelw(p, it.cbEnd); + } + + break; + } + } +} |