summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-05 12:52:30 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-05 12:52:30 +0000
commit3576b67db9fa0a3d8d5c1747cc3560504d31d125 (patch)
treef6a6cb9916cbf1aab83bac572fec8822f6ad065e /plugins/HistoryStats/src/utils.cpp
parent73e6231455372205e912963083624aaa371bab0b (diff)
- adaptation for standard Windows ways of handling Unicode;
- obsoleted code removed; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@8407 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/HistoryStats/src/utils.cpp')
-rw-r--r--plugins/HistoryStats/src/utils.cpp689
1 files changed, 277 insertions, 412 deletions
diff --git a/plugins/HistoryStats/src/utils.cpp b/plugins/HistoryStats/src/utils.cpp
index ba1cabc53f..c73b8d941d 100644
--- a/plugins/HistoryStats/src/utils.cpp
+++ b/plugins/HistoryStats/src/utils.cpp
@@ -12,45 +12,39 @@
namespace utils
{
- ext::string timestampToString(DWORD value, const mu_text* format)
+ ext::string timestampToString(DWORD value, const TCHAR* format)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
- return (ext::strfunc::ftime(temp, 100, format, gmtime(reinterpret_cast<time_t*>(&value))) > 0) ? temp : muT("");
+ return (ext::strfunc::ftime(temp, 100, format, gmtime(reinterpret_cast<time_t*>(&value))) > 0) ? temp : _T("");
}
- ext::string tmStructToString(const tm& value, const mu_text* format)
+ ext::string tmStructToString(const tm& value, const TCHAR* format)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
- return (ext::strfunc::ftime(temp, 100, format, &value) > 0) ? temp : muT("");
+ return (ext::strfunc::ftime(temp, 100, format, &value) > 0) ? temp : _T("");
}
ext::string durationToString(DWORD value)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
value += 59;
value /= 60;
if (value >= 1440)
- {
- ext::strfunc::sprintf(temp, muT("%dd %02d:%02d"), value / 1440, (value / 60) % 24, value % 60);
- }
+ ext::strfunc::sprintf(temp, _T("%dd %02d:%02d"), value / 1440, (value / 60) % 24, value % 60);
else
- {
- ext::strfunc::sprintf(temp, muT("%02d:%02d"), value / 60, value % 60);
- }
+ ext::strfunc::sprintf(temp, _T("%02d:%02d"), value / 60, value % 60);
return temp;
}
DWORD parseDate(const ext::string& date)
{
- if (date.length() != 10 || date[4] != muC('-') || date[7] != muC('-'))
- {
+ if (date.length() != 10 || date[4] != '-' || date[7] != '-')
return 0;
- }
struct tm dateTM;
@@ -63,9 +57,7 @@ namespace utils
time_t dateTT = mktime(&dateTM);
if (dateTT == -1)
- {
return 0;
- }
dateTM.tm_year = 1970 - 1900;
dateTM.tm_mon = 1 - 1;
@@ -76,55 +68,48 @@ namespace utils
time_t baseTT = mktime(&dateTM);
if (baseTT == -1)
- {
return 0;
- }
return dateTT - baseTT + 2 * 86400;
}
ext::string intToString(int value)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
- ext::strfunc::sprintf(temp, muT("%d"), value);
+ ext::strfunc::sprintf(temp, _T("%d"), value);
return temp;
}
ext::string intToPadded(int value, int len)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
- ext::strfunc::sprintf(temp, muT("%0*d"), len, value);
+ ext::strfunc::sprintf(temp, _T("%0*d"), len, value);
return temp;
}
ext::string intToGrouped(int value)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
const char* grouping = Locale::grouping();
- ext::strfunc::sprintf(temp, muT("%d"), value);
+ ext::strfunc::sprintf(temp, _T("%d"), value);
if (*grouping == CHAR_MAX || *grouping <= 0)
- {
return temp;
- }
ext::string str = temp;
ext::string::size_type pos = str.length();
- ext::string::size_type prefix = (temp[0] == muC('+') || temp[0] == muC('-')) ? 1 : 0;
+ ext::string::size_type prefix = (temp[0] == '+' || temp[0] == '-') ? 1 : 0;
- while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping)
- {
+ while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping) {
str.insert(pos -= *grouping, 1, Locale::thousandSep());
if (grouping[1] > 0)
- {
++grouping;
- }
}
return str;
@@ -132,42 +117,35 @@ namespace utils
ext::string floatToString(double value, int precision)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
- ext::strfunc::sprintf(temp, muT("%.*f"), precision, value);
+ ext::strfunc::sprintf(temp, _T("%.*f"), precision, value);
return temp;
}
ext::string floatToGrouped(double value, int precision)
{
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
const char* grouping = Locale::grouping();
- ext::strfunc::sprintf(temp, muT("%.*f"), precision, value);
+ ext::strfunc::sprintf(temp, _T("%.*f"), precision, value);
if (*grouping == CHAR_MAX || *grouping <= 0)
- {
return temp;
- }
ext::string str = temp;
ext::string::size_type pos = str.find(Locale::decimalPoint());
- ext::string::size_type prefix = (temp[0] == muC('+') || temp[0] == muC('-')) ? 1 : 0;
+ ext::string::size_type prefix = (temp[0] == '+' || temp[0] == '-') ? 1 : 0;
if (pos == ext::string::npos)
- {
pos = str.length();
- }
- while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping)
- {
+ while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping) {
str.insert(pos -= *grouping, 1, Locale::thousandSep());
if (grouping[1] > 0)
- {
++grouping;
- }
}
return str;
@@ -176,26 +154,24 @@ namespace utils
ext::string ratioToPercent(int numerator, int denominator)
{
float value = 0.0;
- mu_text temp[100] = { 0 };
+ TCHAR temp[100] = { 0 };
- if (denominator != 0)
- {
+ if (denominator != 0) {
value = 1.0f * numerator / denominator;
}
- ext::strfunc::sprintf(temp, muT("%.0f%%"), 100.0f * value);
+ ext::strfunc::sprintf(temp, _T("%.0f%%"), 100.0f * value);
return temp;
}
- void replaceAllInPlace(ext::string& text, const mu_text* find, const mu_text* replace)
+ void replaceAllInPlace(ext::string& text, const TCHAR* find, const TCHAR* replace)
{
ext::string::size_type pos = 0;
ext::string::size_type find_len = ext::strfunc::len(find);
ext::string::size_type replace_len = ext::strfunc::len(replace);
- while ((pos = text.find(find, pos, find_len)) != ext::string::npos)
- {
+ while ((pos = text.find(find, pos, find_len)) != ext::string::npos) {
text.erase(pos, find_len);
text.insert(pos, replace, replace_len);
pos += replace_len;
@@ -204,191 +180,155 @@ namespace utils
void htmlEscapeInPlace(ext::string& text)
{
- replaceAllInPlace(text, muT("&") , muT("&amp;") );
- replaceAllInPlace(text, muT("\""), muT("&quot;"));
- replaceAllInPlace(text, muT("<") , muT("&lt;") );
- replaceAllInPlace(text, muT(">") , muT("&gt;") );
+ replaceAllInPlace(text, _T("&"), _T("&amp;"));
+ replaceAllInPlace(text, _T("\""), _T("&quot;"));
+ replaceAllInPlace(text, _T("<"), _T("&lt;"));
+ replaceAllInPlace(text, _T(">"), _T("&gt;"));
}
- const mu_text* stripPrefix(const mu_text* szPrefix, const mu_text* szText)
+ const TCHAR* stripPrefix(const TCHAR* szPrefix, const TCHAR* szText)
{
int i = 0;
- while (szPrefix[i] != muC('\0') && szText[i] != muC('\0') && szPrefix[i] == szText[i])
- {
+ while (szPrefix[i] != '\0' && szText[i] != '\0' && szPrefix[i] == szText[i])
++i;
- }
- if (szPrefix[i] == muC('\0'))
- {
+ if (szPrefix[i] == '\0')
return szText + i;
- }
- else
- {
- return szText;
- }
+
+ return szText;
}
- ext::string replaceVariables(const ext::string& strFormat, DWORD timeValue, const mu_text* szNick /* = muT("") */)
+ ext::string replaceVariables(const ext::string& strFormat, DWORD timeValue, const TCHAR* szNick /* = _T("") */)
{
- static const mu_text* szMonthName[][2] = {
- { I18N(muT("month3:Jan")), I18N(muT("monthF:January")) },
- { I18N(muT("month3:Feb")), I18N(muT("monthF:February")) },
- { I18N(muT("month3:Mar")), I18N(muT("monthF:March")) },
- { I18N(muT("month3:Apr")), I18N(muT("monthF:April")) },
- { I18N(muT("month3:May")), I18N(muT("monthF:May")) },
- { I18N(muT("month3:Jun")), I18N(muT("monthF:June")) },
- { I18N(muT("month3:Jul")), I18N(muT("monthF:July")) },
- { I18N(muT("month3:Aug")), I18N(muT("monthF:August")) },
- { I18N(muT("month3:Sep")), I18N(muT("monthF:September")) },
- { I18N(muT("month3:Oct")), I18N(muT("monthF:October")) },
- { I18N(muT("month3:Nov")), I18N(muT("monthF:November")) },
- { I18N(muT("month3:Dec")), I18N(muT("monthF:December")) },
+ static const TCHAR* szMonthName[][2] = {
+ { LPGENT("month3:Jan"), LPGENT("monthF:January") },
+ { LPGENT("month3:Feb"), LPGENT("monthF:February") },
+ { LPGENT("month3:Mar"), LPGENT("monthF:March") },
+ { LPGENT("month3:Apr"), LPGENT("monthF:April") },
+ { LPGENT("month3:May"), LPGENT("monthF:May") },
+ { LPGENT("month3:Jun"), LPGENT("monthF:June") },
+ { LPGENT("month3:Jul"), LPGENT("monthF:July") },
+ { LPGENT("month3:Aug"), LPGENT("monthF:August") },
+ { LPGENT("month3:Sep"), LPGENT("monthF:September") },
+ { LPGENT("month3:Oct"), LPGENT("monthF:October") },
+ { LPGENT("month3:Nov"), LPGENT("monthF:November") },
+ { LPGENT("month3:Dec"), LPGENT("monthF:December") },
};
- static const mu_text* szWDayName[][3] = {
- { I18N(muT("wday2:Mo")), I18N(muT("wday3:Mon")), I18N(muT("wdayF:Monday")) },
- { I18N(muT("wday2:Tu")), I18N(muT("wday3:Tue")), I18N(muT("wdayF:Tuesday")) },
- { I18N(muT("wday2:We")), I18N(muT("wday3:Wed")), I18N(muT("wdayF:Wednesday")) },
- { I18N(muT("wday2:Th")), I18N(muT("wday3:Thu")), I18N(muT("wdayF:Thursday")) },
- { I18N(muT("wday2:Fr")), I18N(muT("wday3:Fri")), I18N(muT("wdayF:Friday")) },
- { I18N(muT("wday2:Sa")), I18N(muT("wday3:Sat")), I18N(muT("wdayF:Saturday")) },
- { I18N(muT("wday2:Su")), I18N(muT("wday3:Sun")), I18N(muT("wdayF:Sunday")) },
+ static const TCHAR* szWDayName[][3] = {
+ { LPGENT("wday2:Mo"), LPGENT("wday3:Mon"), LPGENT("wdayF:Monday") },
+ { LPGENT("wday2:Tu"), LPGENT("wday3:Tue"), LPGENT("wdayF:Tuesday") },
+ { LPGENT("wday2:We"), LPGENT("wday3:Wed"), LPGENT("wdayF:Wednesday") },
+ { LPGENT("wday2:Th"), LPGENT("wday3:Thu"), LPGENT("wdayF:Thursday") },
+ { LPGENT("wday2:Fr"), LPGENT("wday3:Fri"), LPGENT("wdayF:Friday") },
+ { LPGENT("wday2:Sa"), LPGENT("wday3:Sat"), LPGENT("wdayF:Saturday") },
+ { LPGENT("wday2:Su"), LPGENT("wday3:Sun"), LPGENT("wdayF:Sunday") },
};
struct tm timeTM = *gmtime(reinterpret_cast<time_t*>(&timeValue));
ext::string strOut = strFormat;
- ext::string::size_type posOpen = strOut.find(muC('%'));
+ ext::string::size_type posOpen = strOut.find('%');
- while (posOpen != ext::string::npos)
- {
- ext::string::size_type posClose = strOut.find(muC('%'), posOpen + 1);
+ while (posOpen != ext::string::npos) {
+ ext::string::size_type posClose = strOut.find('%', posOpen + 1);
- if (posOpen != ext::string::npos)
- {
+ if (posOpen != ext::string::npos) {
ext::string strVar = strOut.substr(posOpen + 1, posClose - posOpen - 1);
ext::string strSubst;
// match variable and generate substitution
- if (strVar == muT("h"))
- {
+ if (strVar == _T("h")) {
strSubst = intToString(timeTM.tm_hour % 12 + (timeTM.tm_hour % 12 == 0 ? 12 : 0));
}
- else if (strVar == muT("hh"))
- {
+ else if (strVar == _T("hh")) {
strSubst = intToPadded(timeTM.tm_hour % 12 + (timeTM.tm_hour % 12 == 0 ? 12 : 0), 2);
}
- else if (strVar == muT("H"))
- {
+ else if (strVar == _T("H")) {
strSubst = intToString(timeTM.tm_hour);
}
- else if (strVar == muT("HH"))
- {
+ else if (strVar == _T("HH")) {
strSubst = intToPadded(timeTM.tm_hour, 2);
}
- else if (strVar == muT("m"))
- {
+ else if (strVar == _T("m")) {
strSubst = intToString(timeTM.tm_min);
}
- else if (strVar == muT("mm"))
- {
+ else if (strVar == _T("mm")) {
strSubst = intToPadded(timeTM.tm_min, 2);
}
- else if (strVar == muT("s"))
- {
+ else if (strVar == _T("s")) {
strSubst = intToString(timeTM.tm_sec);
}
- else if (strVar == muT("ss"))
- {
+ else if (strVar == _T("ss")) {
strSubst = intToPadded(timeTM.tm_sec, 2);
}
- else if (strVar == muT("tt"))
- {
- strSubst = timeTM.tm_hour / 12 ? i18n(muT("pm")) : i18n(muT("am"));
+ else if (strVar == _T("tt")) {
+ strSubst = timeTM.tm_hour / 12 ? TranslateT("pm") : TranslateT("am");
}
- else if (strVar == muT("TT"))
- {
- strSubst = timeTM.tm_hour / 12 ? i18n(muT("PM")) : i18n(muT("AM"));
+ else if (strVar == _T("TT")) {
+ strSubst = timeTM.tm_hour / 12 ? TranslateT("PM") : TranslateT("AM");
}
- else if (strVar == muT("yy"))
- {
+ else if (strVar == _T("yy")) {
strSubst = intToPadded((timeTM.tm_year + 1900) % 100, 2);
}
- else if (strVar == muT("yyyy"))
- {
+ else if (strVar == _T("yyyy")) {
strSubst = intToPadded(timeTM.tm_year + 1900, 4);
}
- else if (strVar == muT("M"))
- {
+ else if (strVar == _T("M")) {
strSubst = intToString(timeTM.tm_mon + 1);
}
- else if (strVar == muT("MM"))
- {
+ else if (strVar == _T("MM")) {
strSubst = intToPadded(timeTM.tm_mon + 1, 2);
}
- else if (strVar == muT("MMM"))
- {
- strSubst = stripPrefix(muT("month3:"), i18n(szMonthName[timeTM.tm_mon % 12][0]));
+ else if (strVar == _T("MMM")) {
+ strSubst = stripPrefix(_T("month3:"), TranslateTS(szMonthName[timeTM.tm_mon % 12][0]));
}
- else if (strVar == muT("MMMM"))
- {
- strSubst = stripPrefix(muT("monthF:"), i18n(szMonthName[timeTM.tm_mon % 12][1]));
+ else if (strVar == _T("MMMM")) {
+ strSubst = stripPrefix(_T("monthF:"), TranslateTS(szMonthName[timeTM.tm_mon % 12][1]));
}
- else if (strVar == muT("d"))
- {
+ else if (strVar == _T("d")) {
strSubst = intToString(timeTM.tm_mday);
}
- else if (strVar == muT("dd"))
- {
+ else if (strVar == _T("dd")) {
strSubst = intToPadded(timeTM.tm_mday, 2);
}
- else if (strVar == muT("ww"))
- {
- strSubst = stripPrefix(muT("wday2:"), i18n(szWDayName[(timeTM.tm_wday + 6) % 7][0]));
+ else if (strVar == _T("ww")) {
+ strSubst = stripPrefix(_T("wday2:"), TranslateTS(szWDayName[(timeTM.tm_wday + 6) % 7][0]));
}
- else if (strVar == muT("www"))
- {
- strSubst = stripPrefix(muT("wday3:"), i18n(szWDayName[(timeTM.tm_wday + 6) % 7][1]));
+ else if (strVar == _T("www")) {
+ strSubst = stripPrefix(_T("wday3:"), TranslateTS(szWDayName[(timeTM.tm_wday + 6) % 7][1]));
}
- else if (strVar == muT("wwww"))
- {
- strSubst = stripPrefix(muT("wdayF:"), i18n(szWDayName[(timeTM.tm_wday + 6) % 7][2]));
+ else if (strVar == _T("wwww")) {
+ strSubst = stripPrefix(_T("wdayF:"), TranslateTS(szWDayName[(timeTM.tm_wday + 6) % 7][2]));
}
- else if (strVar == muT("miranda_path"))
- {
+ else if (strVar == _T("miranda_path")) {
strSubst = getMirandaPath();
}
- else if (strVar == muT("profile_path"))
- {
+ else if (strVar == _T("profile_path")) {
strSubst = getProfilePath();
}
- else if (strVar == muT("profile_name"))
- {
+ else if (strVar == _T("profile_name")) {
strSubst = getProfileName();
}
- else if (strVar == muT("nick"))
- {
+ else if (strVar == _T("nick")) {
strSubst = szNick;
}
- else if (strVar == muT(""))
- {
- strSubst = muT("%");
+ else if (strVar == _T("")) {
+ strSubst = _T("%");
}
// perform actual substitution
- if (!strSubst.empty())
- {
+ if (!strSubst.empty()) {
strOut.replace(posOpen, posClose - posOpen + 1, strSubst);
posClose += strSubst.length() - strVar.length() - 2;
}
}
- else
- {
+ else {
break;
}
- posOpen = strOut.find(muC('%'), posClose + 1);
+ posOpen = strOut.find('%', posClose + 1);
}
return strOut;
@@ -397,7 +337,7 @@ namespace utils
ext::string toLowerCase(const ext::string& text)
{
int len = text.length();
- mu_text* buf = new mu_text[len + 1];
+ TCHAR* buf = new TCHAR[len + 1];
LCID lcid = GetUserDefaultLCID();
@@ -408,14 +348,14 @@ namespace utils
ext::string ret_str(buf, len);
delete[] buf;
-
+
return ret_str;
}
ext::string toUpperCase(const ext::string& text)
{
int len = text.length();
- mu_text* buf = new mu_text[len + 1];
+ TCHAR* buf = new TCHAR[len + 1];
LCID lcid = GetUserDefaultLCID();
@@ -426,30 +366,29 @@ namespace utils
ext::string ret_str(buf, len);
delete[] buf;
-
+
return ret_str;
}
DWORD dottedToVersion(ext::string version)
{
- union {
+ union
+ {
__int32 combined;
__int8 parts[4];
} res = { 0 };
int part = 3;
- while (!version.empty() && part >= 0)
- {
- ext::string::size_type dotPos = version.find(muT("."));
+ while (!version.empty() && part >= 0) {
+ ext::string::size_type dotPos = version.find(_T("."));
- if (dotPos == ext::string::npos)
- {
+ if (dotPos == ext::string::npos) {
dotPos = version.length();
}
res.parts[part--] = _ttoi(version.substr(0, dotPos).c_str());
-
+
version.erase(0, dotPos + 1);
}
@@ -458,11 +397,11 @@ namespace utils
ext::string versionToDotted(DWORD version)
{
- mu_text temp[16] = { 0 };
+ TCHAR temp[16] = { 0 };
ext::strfunc::sprintf(
temp,
- muT("%d.%d.%d.%d"),
+ _T("%d.%d.%d.%d"),
(version >> 24) & 0xFF,
(version >> 16) & 0xFF,
(version >> 8) & 0xFF,
@@ -471,13 +410,13 @@ namespace utils
return temp;
}
- ext::a::string convertWToA(const mu_wide* str, size_t len)
+ ext::a::string convertWToA(const WCHAR* str, size_t len)
{
- mu_ansi* buf = new mu_ansi[len + 1];
+ char* buf = new char[len + 1];
len = WideCharToMultiByte(CP_ACP, 0, str, len, buf, len, NULL, NULL);
- buf[len] = muC('\0');
+ buf[len] = '\0';
ext::a::string ret_str(buf, len);
@@ -486,195 +425,171 @@ namespace utils
return ret_str;
}
- ext::w::string convertAToW(const mu_ansi* str, size_t len)
+ ext::w::string convertAToW(const char* str, size_t len)
{
- mu_wide* buf = new mu_wide[len + 1];
+ WCHAR* buf = new WCHAR[len + 1];
len = MultiByteToWideChar(CP_ACP, 0, str, len, buf, len);
- buf[len] = muC('\0');
+ buf[len] = '\0';
ext::w::string ret_str(buf, len);
delete[] buf;
-
+
return ret_str;
}
- ext::a::string convertTToUTF8(const mu_text* str, size_t str_len)
+ ext::a::string convertTToUTF8(const TCHAR* str, size_t str_len)
{
-#if defined(MU_WIDE)
- const mu_wide* conv_str = str;
-#else // MU_WIDE
+#if defined(_UNICODE)
+ const WCHAR* conv_str = str;
+#else // _UNICODE
const ext::w::string conv_strX = convertAToW(str, str_len);
- const mu_wide* conv_str = conv_strX.c_str();
-#endif // MU_WIDE
+ const WCHAR* conv_str = conv_strX.c_str();
+#endif // _UNICODE
int len = 0;
upto_each_(i, str_len)
{
- mu_wide c = conv_str[i];
+ WCHAR c = conv_str[i];
- if (c <= 0x007F)
- {
+ if (c <= 0x007F) {
len++;
}
- else if (c <= 0x07FF)
- {
+ else if (c <= 0x07FF) {
len += 2;
}
- else
- {
+ else {
len += 3;
}
}
- ext::a::string out_str(len, muC('_'));
-
+ ext::a::string out_str(len, '_');
+
int pos = 0;
upto_each_(i, str_len)
{
- mu_wide c = conv_str[i];
+ WCHAR c = conv_str[i];
- if (c <= 0x007F)
- {
- out_str[pos++] = (unsigned char) c;
+ if (c <= 0x007F) {
+ out_str[pos++] = (unsigned char)c;
}
- else if (c <= 0x07FF)
- {
- out_str[pos++] = (unsigned char) 0xC0 | (c >> 6);
- out_str[pos++] = (unsigned char) 0x80 | (c & 0x3F);
+ else if (c <= 0x07FF) {
+ out_str[pos++] = (unsigned char)0xC0 | (c >> 6);
+ out_str[pos++] = (unsigned char)0x80 | (c & 0x3F);
}
- else
- {
- out_str[pos++] = (unsigned char) 0xE0 | (c >> 12);
- out_str[pos++] = (unsigned char) 0x80 | ((c >> 6) & 0x3F);
- out_str[pos++] = (unsigned char) 0x80 | (c & 0x3F);
+ else {
+ out_str[pos++] = (unsigned char)0xE0 | (c >> 12);
+ out_str[pos++] = (unsigned char)0x80 | ((c >> 6) & 0x3F);
+ out_str[pos++] = (unsigned char)0x80 | (c & 0x3F);
}
}
return out_str;
}
- ext::string convertUTF8ToT(const mu_ansi* str, size_t str_len)
+ ext::string convertUTF8ToT(const char* str, size_t str_len)
{
size_t len = 0, in_pos = 0;
- while (in_pos < str_len)
- {
- mu_ansi c = str[in_pos];
+ while (in_pos < str_len) {
+ char c = str[in_pos];
- if ((c & 0x80) == 0x00)
- {
+ if ((c & 0x80) == 0x00) {
in_pos++;
}
- else if ((c & 0xE0) == 0xC0)
- {
+ else if ((c & 0xE0) == 0xC0) {
in_pos += 2;
}
- else if ((c & 0xF0) == 0xE0)
- {
+ else if ((c & 0xF0) == 0xE0) {
in_pos += 3;
}
- else
- {
+ else {
in_pos++;
}
len++;
}
- ext::w::string out_str(len, muC('_'));
+ ext::w::string out_str(len, '_');
size_t out_pos = 0;
in_pos = 0;
- while (in_pos < str_len)
- {
- unsigned char c = (unsigned char) str[in_pos];
+ while (in_pos < str_len) {
+ unsigned char c = (unsigned char)str[in_pos];
- if ((c & 0x80) == 0x00)
- {
- out_str[out_pos] = (mu_wide) c;
+ if ((c & 0x80) == 0x00) {
+ out_str[out_pos] = (WCHAR)c;
in_pos++;
}
- else if ((c & 0xE0) == 0xC0)
- {
- out_str[out_pos] = (mu_wide) (((c & 0x1F) << 6) | ((unsigned char) str[in_pos + 1] & 0x3F));
+ else if ((c & 0xE0) == 0xC0) {
+ out_str[out_pos] = (WCHAR)(((c & 0x1F) << 6) | ((unsigned char)str[in_pos + 1] & 0x3F));
in_pos += 2;
}
- else if ((c & 0xF0) == 0xE0)
- {
- out_str[out_pos] = (mu_wide) (((c & 0x0F) << 12) | (((unsigned char) str[in_pos + 1] & 0x3F) << 6) | ((unsigned char) str[in_pos + 2] & 0x3F));
+ else if ((c & 0xF0) == 0xE0) {
+ out_str[out_pos] = (WCHAR)(((c & 0x0F) << 12) | (((unsigned char)str[in_pos + 1] & 0x3F) << 6) | ((unsigned char)str[in_pos + 2] & 0x3F));
in_pos += 3;
}
- else
- {
+ else {
in_pos++;
}
out_pos++;
}
-#if defined(MU_WIDE)
+#if defined(_UNICODE)
return out_str;
-#else // MU_WIDE
+#else // _UNICODE
return convertWToA(out_str.c_str(), out_str.length());
-#endif // MU_WIDE
+#endif // _UNICODE
}
- size_t rawUTF8Encode(const mu_wide* pIn, size_t lenIn, mu_ansi* pOut)
+ size_t rawUTF8Encode(const WCHAR* pIn, size_t lenIn, char* pOut)
{
- mu_ansi* pOutBegin = pOut;
+ char* pOutBegin = pOut;
upto_each_(i, lenIn)
{
- mu_wide c = pIn[i];
+ WCHAR c = pIn[i];
- if (c <= 0x007F)
- {
- *pOut++ = (unsigned char) c;
+ if (c <= 0x007F) {
+ *pOut++ = (unsigned char)c;
}
- else if (c <= 0x07FF)
- {
- *pOut++ = (unsigned char) 0xC0 | (c >> 6);
- *pOut++ = (unsigned char) 0x80 | (c & 0x3F);
+ else if (c <= 0x07FF) {
+ *pOut++ = (unsigned char)0xC0 | (c >> 6);
+ *pOut++ = (unsigned char)0x80 | (c & 0x3F);
}
- else
- {
- *pOut++ = (unsigned char) 0xE0 | (c >> 12);
- *pOut++ = (unsigned char) 0x80 | ((c >> 6) & 0x3F);
- *pOut++ = (unsigned char) 0x80 | (c & 0x3F);
+ else {
+ *pOut++ = (unsigned char)0xE0 | (c >> 12);
+ *pOut++ = (unsigned char)0x80 | ((c >> 6) & 0x3F);
+ *pOut++ = (unsigned char)0x80 | (c & 0x3F);
}
}
return (pOut - pOutBegin);
}
- size_t getUTF8Len(const mu_ansi* str)
+ size_t getUTF8Len(const char* str)
{
size_t len = 0, in_pos = 0, str_len = ext::a::strfunc::len(str);
- while (in_pos < str_len)
- {
- mu_ansi c = str[in_pos];
+ while (in_pos < str_len) {
+ char c = str[in_pos];
- if ((c & 0x80) == 0x00)
- {
+ if ((c & 0x80) == 0x00) {
in_pos++;
}
- else if ((c & 0xE0) == 0xC0)
- {
+ else if ((c & 0xE0) == 0xC0) {
in_pos += 2;
}
- else if ((c & 0xF0) == 0xE0)
- {
+ else if ((c & 0xF0) == 0xE0) {
in_pos += 3;
}
- else
- {
+ else {
in_pos++;
}
@@ -689,14 +604,12 @@ namespace utils
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(fileName.c_str(), &wfd);
- if (hFind != INVALID_HANDLE_VALUE)
- {
+ if (hFind != INVALID_HANDLE_VALUE) {
FindClose(hFind);
return true;
}
- else
- {
+ else {
return false;
}
}
@@ -704,16 +617,14 @@ namespace utils
bool pathExists(const ext::string& path)
{
WIN32_FIND_DATA wfd;
- HANDLE hFind = FindFirstFile((path + muT(".")).c_str(), &wfd);
+ HANDLE hFind = FindFirstFile((path + _T(".")).c_str(), &wfd);
- if (hFind != INVALID_HANDLE_VALUE)
- {
+ if (hFind != INVALID_HANDLE_VALUE) {
FindClose(hFind);
return (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
- else
- {
+ else {
return false;
}
}
@@ -721,12 +632,8 @@ namespace utils
bool isRelative(const ext::string& fileName)
{
if (fileName.length() > 2)
- {
- if ((fileName[1] == muC(':') && fileName[2] == muC('\\')) || (fileName[0] == muC('\\') && fileName[1] == muC('\\')))
- {
+ if ((fileName[1] == ':' && fileName[2] == '\\') || (fileName[0] == '\\' && fileName[1] == '\\'))
return false;
- }
- }
return true;
}
@@ -734,55 +641,49 @@ namespace utils
bool isValidFilePart(ext::string filePart)
{
// check for disallowed chars
- if (filePart.find_first_of(muT("<>:\"/\\|?*")) != ext::string::npos)
- {
+ if (filePart.find_first_of(_T("<>:\"/\\|?*")) != ext::string::npos)
return false;
- }
// check for dots only
- if (filePart.find_first_not_of(muC('.')) == ext::string::npos)
- {
+ if (filePart.find_first_not_of('.') == ext::string::npos)
return false;
- }
// check for disallowed names
- static const mu_text* disallowedNames[] = {
- muT("clock$"),
- muT("aux"),
- muT("con"),
- muT("nul"),
- muT("prn"),
- muT("com1"),
- muT("com2"),
- muT("com3"),
- muT("com4"),
- muT("com5"),
- muT("com6"),
- muT("com7"),
- muT("com8"),
- muT("com9"),
- muT("lpt1"),
- muT("lpt2"),
- muT("lpt3"),
- muT("lpt4"),
- muT("lpt5"),
- muT("lpt6"),
- muT("lpt7"),
- muT("lpt8"),
- muT("lpt9")
+ static const TCHAR* disallowedNames[] = {
+ _T("clock$"),
+ _T("aux"),
+ _T("con"),
+ _T("nul"),
+ _T("prn"),
+ _T("com1"),
+ _T("com2"),
+ _T("com3"),
+ _T("com4"),
+ _T("com5"),
+ _T("com6"),
+ _T("com7"),
+ _T("com8"),
+ _T("com9"),
+ _T("lpt1"),
+ _T("lpt2"),
+ _T("lpt3"),
+ _T("lpt4"),
+ _T("lpt5"),
+ _T("lpt6"),
+ _T("lpt7"),
+ _T("lpt8"),
+ _T("lpt9")
};
- ext::string::size_type pos = filePart.find(muC('.'));
+ ext::string::size_type pos = filePart.find('.');
- if (pos != ext::string::npos)
- {
+ if (pos != ext::string::npos) {
filePart.erase(pos);
}
array_each_(i, disallowedNames)
{
- if (filePart == disallowedNames[i])
- {
+ if (filePart == disallowedNames[i]) {
return false;
}
}
@@ -793,14 +694,12 @@ namespace utils
bool isValidFile(const ext::string& fileName)
{
// find the last backslash to extract file name
- ext::string::size_type pos = fileName.rfind(muC('\\'));
+ ext::string::size_type pos = fileName.rfind('\\');
- if (pos == ext::string::npos)
- {
+ if (pos == ext::string::npos) {
pos = 0;
}
- else
- {
+ else {
// is a path, if ends with a backslash
if (pos == fileName.length() - 1)
return false;
@@ -814,28 +713,24 @@ namespace utils
ext::string extractPath(const ext::string& fileName)
{
- ext::string::size_type pos = fileName.rfind(muC('\\'));
+ ext::string::size_type pos = fileName.rfind('\\');
- if (pos == ext::string::npos)
- {
- return muT("");
+ if (pos == ext::string::npos) {
+ return _T("");
}
- else
- {
+ else {
return fileName.substr(0, pos + 1);
}
}
ext::string extractFile(const ext::string& fileName)
{
- ext::string::size_type pos = fileName.rfind(muC('\\'));
+ ext::string::size_type pos = fileName.rfind('\\');
- if (pos == ext::string::npos)
- {
+ if (pos == ext::string::npos) {
return fileName;
}
- else
- {
+ else {
return fileName.substr(pos + 1);
}
}
@@ -846,37 +741,32 @@ namespace utils
std::stack<ext::string> subDirs;
// create stack of missing subdirs and validate them
- while (curPath.length() > 3 && !pathExists(curPath))
- {
- ext::string::size_type pos = curPath.rfind(muC('\\'), curPath.length() - 2);
+ while (curPath.length() > 3 && !pathExists(curPath)) {
+ ext::string::size_type pos = curPath.rfind('\\', curPath.length() - 2);
- if (pos == ext::string::npos)
- {
+ if (pos == ext::string::npos) {
pos = -1;
}
subDirs.push(curPath.substr(pos + 1, curPath.length() - pos - 2));
curPath.erase(pos + 1);
- if (!isValidFilePart(subDirs.top()))
- {
+ if (!isValidFilePart(subDirs.top())) {
return false;
}
}
// try to create subdirs in reverse order
- while (!subDirs.empty())
- {
+ while (!subDirs.empty()) {
const ext::string& curDir = subDirs.top();
curPath += curDir;
- if (!CreateDirectory(curPath.c_str(), NULL))
- {
+ if (!CreateDirectory(curPath.c_str(), NULL)) {
return false;
}
- curPath += muT("\\");
+ curPath += _T("\\");
subDirs.pop();
}
@@ -886,9 +776,9 @@ namespace utils
ext::string colorToHTML(COLORREF crColor)
{
- static const mu_text hexDigits[] = muT("0123456789ABCDEF");
+ static const TCHAR hexDigits[] = _T("0123456789ABCDEF");
- ext::string htmlColor(7, muC('#'));
+ ext::string htmlColor(7, '#');
upto_each_(i, 3)
{
@@ -906,7 +796,7 @@ namespace utils
struct rgb { int r, g, b; };
rgb fromRGB = { GetRValue(fromColor), GetGValue(fromColor), GetBValue(fromColor) };
- rgb toRGB = { GetRValue(toColor), GetGValue(toColor), GetBValue(toColor) };
+ rgb toRGB = { GetRValue(toColor), GetGValue(toColor), GetBValue(toColor) };
upto_each_(i, 256)
{
@@ -919,28 +809,26 @@ namespace utils
void ensureRange(int& value, int min, int max, int fallback)
{
- if (value < min || value > max)
- {
+ if (value < min || value > max) {
value = fallback;
}
}
void ensureRange(unsigned int& value, unsigned int min, unsigned int max, unsigned int fallback)
{
- if (value < min || value > max)
- {
+ if (value < min || value > max) {
value = fallback;
}
}
ext::string getGUID()
{
- static const mu_text hexDigits[] = muT("0123456789ABCDEF");
+ static const TCHAR hexDigits[] = _T("0123456789ABCDEF");
GUID guid;
CoCreateGuid(&guid);
- ext::string strGUID(2 * sizeof(guid), muC('_'));
+ ext::string strGUID(2 * sizeof(guid), '_');
upto_each_(i, sizeof(guid))
{
@@ -955,15 +843,13 @@ namespace utils
void centerDialog(HWND hDlg, HWND hParent /* = NULL */)
{
- if (!hParent)
- {
+ if (!hParent) {
hParent = GetParent(hDlg);
}
RECT rDlg, rParent;
- if (GetWindowRect(hParent, &rParent) && GetWindowRect(hDlg, &rDlg))
- {
+ if (GetWindowRect(hParent, &rParent) && GetWindowRect(hDlg, &rDlg)) {
SetWindowPos(
hDlg,
0,
@@ -973,8 +859,7 @@ namespace utils
0,
SWP_NOSIZE | SWP_NOZORDER);
}
- else if (GetWindowRect(hDlg, &rDlg))
- {
+ else if (GetWindowRect(hDlg, &rDlg)) {
SetWindowPos(
hDlg,
0,
@@ -1007,11 +892,10 @@ namespace utils
{
static ext::string strMirandaPath;
- if (strMirandaPath.empty())
- {
- mu_text szPath[MAX_PATH] = { 0 };
+ if (strMirandaPath.empty()) {
+ TCHAR szPath[MAX_PATH] = { 0 };
- mu::utils::pathToAbsolute(muT("x"), szPath);
+ mu::utils::pathToAbsolute(_T("x"), szPath);
strMirandaPath = extractPath(szPath);
}
@@ -1022,16 +906,15 @@ namespace utils
{
static ext::string strProfilePath;
- if (strProfilePath.empty())
- {
- mu_text szPath[MAX_PATH] = { 0 };
+ if (strProfilePath.empty()) {
+ TCHAR szPath[MAX_PATH] = { 0 };
mu::db::getProfilePath(MAX_PATH, szPath);
strProfilePath = szPath;
- if (strProfilePath.empty() || strProfilePath[strProfilePath.length() - 1] != muC('\\'))
+ if (strProfilePath.empty() || strProfilePath[strProfilePath.length() - 1] != '\\')
{
- strProfilePath += muT("\\");
+ strProfilePath += _T("\\");
}
}
@@ -1042,17 +925,15 @@ namespace utils
{
static ext::string strProfileName;
- if (strProfileName.empty())
- {
- mu_text szName[MAX_PATH] = { 0 };
+ if (strProfileName.empty()) {
+ TCHAR szName[MAX_PATH] = { 0 };
mu::db::getProfileName(MAX_PATH, szName);
strProfileName = szName;
- ext::string::size_type posDot = strProfileName.rfind(muC('.'));
+ ext::string::size_type posDot = strProfileName.rfind('.');
- if (posDot != ext::string::npos && posDot != 0)
- {
+ if (posDot != ext::string::npos && posDot != 0) {
strProfileName.erase(posDot);
}
}
@@ -1066,8 +947,8 @@ namespace utils
*/
OS::OS()
- : m_bIsXPPlus(false),
- m_ImageListColor(ILC_COLORDDB) // MEMO: maybe change this to ILC_COLOR{8,16,24}
+: m_bIsXPPlus(false),
+m_ImageListColor(ILC_COLORDDB) // MEMO: maybe change this to ILC_COLOR{8,16,24}
{
m_SmIcon.cx = 16; // GetSystemMetrics(SM_CXSMICON);
m_SmIcon.cy = 16; // GetSystemMetrics(SM_CYSMICON);
@@ -1076,12 +957,10 @@ OS::OS()
osvi.dwOSVersionInfoSize = sizeof(osvi);
- if (GetVersionEx(&osvi))
- {
+ if (GetVersionEx(&osvi)) {
m_bIsXPPlus = ((osvi.dwMajorVersion == 5 && osvi.dwMinorVersion >= 1) || osvi.dwMajorVersion >= 6);
- if (m_bIsXPPlus)
- {
+ if (m_bIsXPPlus) {
m_ImageListColor = ILC_COLOR32;
}
}
@@ -1095,11 +974,8 @@ OS OS::m_Data;
void Locale::init()
{
- setlocale(LC_ALL, muA(""));
- // setlocale(LC_ALL, muA("French_France"));
- // setlocale(LC_ALL, muA("English_USA"));
- // setlocale(LC_ALL, muA("Russian_Russia"));
-
+ setlocale(LC_ALL, "");
+
m_Data.m_ThousandSep = utils::fromA(localeconv()->thousands_sep).c_str()[0];
m_Data.m_DecimalPoint = utils::fromA(localeconv()->decimal_point).c_str()[0];
m_Data.m_Grouping = localeconv()->grouping;
@@ -1111,25 +987,19 @@ Locale Locale::m_Data;
* RTFFilter
*/
-RTFFilter::RTFFilter()
- : m_hRTFConv(NULL)
+RTFFilter::RTFFilter() :
+ m_hRTFConv(NULL)
{
}
void RTFFilter::init()
{
- if (!(m_Data.m_hRTFConv = LoadLibrary(muT("rtfconv.dll"))))
- {
- if (!(m_Data.m_hRTFConv = LoadLibrary(muT("plugins\\rtfconv.dll"))))
- {
+ if (!(m_Data.m_hRTFConv = LoadLibrary(_T("rtfconv.dll"))))
+ if (!(m_Data.m_hRTFConv = LoadLibrary(_T("plugins\\rtfconv.dll"))))
return;
- }
- }
- if (!(m_Data.m_RTFConvString = reinterpret_cast<RTFCONVSTRING>(GetProcAddress(m_Data.m_hRTFConv, muA("RtfconvString")))))
- {
+ if (!(m_Data.m_RTFConvString = reinterpret_cast<RTFCONVSTRING>(GetProcAddress(m_Data.m_hRTFConv, "RtfconvString")))) {
FreeLibrary(m_Data.m_hRTFConv);
-
m_Data.m_hRTFConv = NULL;
}
@@ -1138,8 +1008,7 @@ void RTFFilter::init()
void RTFFilter::uninit()
{
- if (m_Data.m_hRTFConv)
- {
+ if (m_Data.m_hRTFConv) {
DeleteCriticalSection(&m_Data.m_RTFConvCS);
FreeLibrary(m_Data.m_hRTFConv);
@@ -1153,49 +1022,45 @@ ext::t::string RTFFilter::filter(const ext::t::string& str)
// protect, because library is not thread-safe
EnterCriticalSection(&m_Data.m_RTFConvCS);
-#if defined(MU_WIDE)
+#if defined(_UNICODE)
const ext::a::string strA = utils::toA(str);
-#else // MU_WIDE
+#else // _UNICODE
const ext::a::string& strA = str;
-#endif // MU_WIDE
+#endif // _UNICODE
intptr_t len = m_Data.m_RTFConvString(
strA.c_str(),
NULL,
0,
- MU_DO_BOTH(GetACP(), CP_UNICODE),
- CONVMODE_USE_SYSTEM_TABLE | MU_DO_BOTH(0, CONVMODE_NO_OUTPUT_BOM),
+ CP_UNICODE,
+ CONVMODE_USE_SYSTEM_TABLE | CONVMODE_NO_OUTPUT_BOM,
0);
- if (len == -1)
- {
+ if (len == -1) {
// someting went wrong, maybe it's not a real RTF string
LeaveCriticalSection(&m_Data.m_RTFConvCS);
-
return str;
}
- mu_text* out_buf = new mu_text[len / sizeof(mu_text)];
+ TCHAR* out_buf = new TCHAR[len / sizeof(TCHAR)];
intptr_t res = m_Data.m_RTFConvString(
strA.c_str(),
out_buf,
0,
- MU_DO_BOTH(GetACP(), CP_UNICODE),
- CONVMODE_USE_SYSTEM_TABLE | MU_DO_BOTH(0, CONVMODE_NO_OUTPUT_BOM),
+ CP_UNICODE,
+ CONVMODE_USE_SYSTEM_TABLE | CONVMODE_NO_OUTPUT_BOM,
len);
- if (res == -1)
- {
+ if (res == -1) {
// someting went wrong, maybe it's not a real RTF string
delete[] out_buf;
LeaveCriticalSection(&m_Data.m_RTFConvCS);
-
return str;
}
- ext::t::string out_str(out_buf, res / sizeof(mu_text) - 1);
+ ext::t::string out_str(out_buf, res / sizeof(TCHAR)-1);
delete[] out_buf;
LeaveCriticalSection(&m_Data.m_RTFConvCS);