Skip to content

Commit

Permalink
Remove ambiguous symbols (part 9)
Browse files Browse the repository at this point in the history
Relace TCHAR, generic_string & TEXT("") par wchar_t, wstring & L"" respectively.
Follow up: 94af271

Close notepad-plus-plus#15386
  • Loading branch information
donho committed Jul 1, 2024
1 parent dc5cea8 commit a301ffc
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 290 deletions.
25 changes: 13 additions & 12 deletions PowerEditor/src/MISC/Common/FileInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "FileInterface.h"
#include "Parameters.h"

using namespace std;

Win32_IO_File::Win32_IO_File(const wchar_t *fname)
{
Expand Down Expand Up @@ -68,9 +69,9 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname)
NppParameters& nppParam = NppParameters::getInstance();
if (nppParam.isEndSessionStarted() && nppParam.doNppLogNulContentCorruptionIssue())
{
generic_string issueFn = nppLogNulContentCorruptionIssue;
issueFn += TEXT(".log");
generic_string nppIssueLog = nppParam.getUserPath();
wstring issueFn = nppLogNulContentCorruptionIssue;
issueFn += L".log";
wstring nppIssueLog = nppParam.getUserPath();
pathAppend(nppIssueLog, issueFn);

std::string msg = _path;
Expand Down Expand Up @@ -157,9 +158,9 @@ Please try using another storage and also check if your saved data is not corrup

if (nppParam.isEndSessionStarted() && nppParam.doNppLogNulContentCorruptionIssue())
{
generic_string issueFn = nppLogNulContentCorruptionIssue;
issueFn += TEXT(".log");
generic_string nppIssueLog = nppParam.getUserPath();
wstring issueFn = nppLogNulContentCorruptionIssue;
issueFn += L".log";
wstring nppIssueLog = nppParam.getUserPath();
pathAppend(nppIssueLog, issueFn);

std::string msg;
Expand Down Expand Up @@ -219,9 +220,9 @@ bool Win32_IO_File::write(const void *wbuf, size_t buf_size)
{
if (nppParam.isEndSessionStarted() && nppParam.doNppLogNulContentCorruptionIssue())
{
generic_string issueFn = nppLogNulContentCorruptionIssue;
issueFn += TEXT(".log");
generic_string nppIssueLog = nppParam.getUserPath();
wstring issueFn = nppLogNulContentCorruptionIssue;
issueFn += L".log";
wstring nppIssueLog = nppParam.getUserPath();
pathAppend(nppIssueLog, issueFn);

std::string msg = _path;
Expand All @@ -238,9 +239,9 @@ bool Win32_IO_File::write(const void *wbuf, size_t buf_size)
{
if (nppParam.isEndSessionStarted() && nppParam.doNppLogNulContentCorruptionIssue())
{
generic_string issueFn = nppLogNulContentCorruptionIssue;
issueFn += TEXT(".log");
generic_string nppIssueLog = nppParam.getUserPath();
wstring issueFn = nppLogNulContentCorruptionIssue;
issueFn += L".log";
wstring nppIssueLog = nppParam.getUserPath();
pathAppend(nppIssueLog, issueFn);

std::string msg = _path;
Expand Down
20 changes: 10 additions & 10 deletions PowerEditor/src/MISC/sha1/sha1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ void CSHA1::Update(const UINT_8* pbData, UINT_32 uLen)
}

#ifdef SHA1_UTILITY_FUNCTIONS
bool CSHA1::HashFile(const TCHAR* tszFileName)
bool CSHA1::HashFile(const wchar_t* tszFileName)
{
if(tszFileName == NULL) return false;

FILE* fpIn = _tfopen(tszFileName, _T("rb"));
FILE* fpIn = _tfopen(tszFileName, L"rb");
if(fpIn == NULL) return false;

UINT_8* pbData = new UINT_8[SHA1_MAX_FILE_BUFFER];
Expand Down Expand Up @@ -203,18 +203,18 @@ void CSHA1::Final()
}

#ifdef SHA1_UTILITY_FUNCTIONS
bool CSHA1::ReportHash(TCHAR* tszReport, REPORT_TYPE rtReportType) const
bool CSHA1::ReportHash(wchar_t* tszReport, REPORT_TYPE rtReportType) const
{
if(tszReport == NULL) return false;

TCHAR tszTemp[16]{};
wchar_t tszTemp[16]{};

if((rtReportType == REPORT_HEX) || (rtReportType == REPORT_HEX_SHORT))
{
_sntprintf(tszTemp, 15, _T("%02X"), m_digest[0]);
_sntprintf(tszTemp, 15, L"%02X", m_digest[0]);
_tcscpy(tszReport, tszTemp);

const TCHAR* lpFmt = ((rtReportType == REPORT_HEX) ? _T(" %02X") : _T("%02X"));
const wchar_t* lpFmt = ((rtReportType == REPORT_HEX) ? L" %02X" : L"%02X");
for(size_t i = 1; i < 20; ++i)
{
_sntprintf(tszTemp, 15, lpFmt, m_digest[i]);
Expand All @@ -223,12 +223,12 @@ bool CSHA1::ReportHash(TCHAR* tszReport, REPORT_TYPE rtReportType) const
}
else if(rtReportType == REPORT_DIGIT)
{
_sntprintf(tszTemp, 15, _T("%u"), m_digest[0]);
_sntprintf(tszTemp, 15, L"%u", m_digest[0]);
_tcscpy(tszReport, tszTemp);

for(size_t i = 1; i < 20; ++i)
{
_sntprintf(tszTemp, 15, _T(" %u"), m_digest[i]);
_sntprintf(tszTemp, 15, L" %u", m_digest[i]);
_tcscat(tszReport, tszTemp);
}
}
Expand All @@ -239,9 +239,9 @@ bool CSHA1::ReportHash(TCHAR* tszReport, REPORT_TYPE rtReportType) const
#endif

#ifdef SHA1_STL_FUNCTIONS
bool CSHA1::ReportHashStl(std::basic_string<TCHAR>& strOut, REPORT_TYPE rtReportType) const
bool CSHA1::ReportHashStl(std::basic_string<wchar_t>& strOut, REPORT_TYPE rtReportType) const
{
TCHAR tszOut[84]{};
wchar_t tszOut[84]{};
const bool bResult = ReportHash(tszOut, rtReportType);
if(bResult) strOut = tszOut;
return bResult;
Expand Down
20 changes: 3 additions & 17 deletions PowerEditor/src/MISC/sha1/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,6 @@
#ifdef _MSC_VER
#include <tchar.h>
#else
#ifndef TCHAR
#define TCHAR char
#endif
#ifndef _T
#define _T(__x) (__x)
#define _tmain main
#define _tprintf printf
#define _getts gets
#define _tcslen strlen
#define _tfopen fopen
#define _tcscpy strcpy
#define _tcscat strcat
#define _sntprintf snprintf
#endif
#endif
#endif

Expand Down Expand Up @@ -245,18 +231,18 @@ class CSHA1

#ifdef SHA1_UTILITY_FUNCTIONS
// Hash in file contents
bool HashFile(const TCHAR* tszFileName);
bool HashFile(const wchar_t* tszFileName);
#endif

// Finalize hash; call it before using ReportHash(Stl)
void Final();

#ifdef SHA1_UTILITY_FUNCTIONS
bool ReportHash(TCHAR* tszReport, REPORT_TYPE rtReportType = REPORT_HEX) const;
bool ReportHash(wchar_t* tszReport, REPORT_TYPE rtReportType = REPORT_HEX) const;
#endif

#ifdef SHA1_STL_FUNCTIONS
bool ReportHashStl(std::basic_string<TCHAR>& strOut, REPORT_TYPE rtReportType =
bool ReportHashStl(std::basic_string<wchar_t>& strOut, REPORT_TYPE rtReportType =
REPORT_HEX) const;
#endif

Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ void FindReplaceDlg::fillComboHistory(int id, const vector<wstring> & strings)
//empty string is not added to CB items, so we need to set it manually
if (!strings.empty() && strings.begin()->empty())
{
SetWindowText(hCombo, _T(""));
SetWindowText(hCombo, L"");
return;
}

Expand Down
77 changes: 39 additions & 38 deletions PowerEditor/src/ScintillaComponent/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

#include "Printer.h"
#include "RunDlg.h"
//#include "Parameters.h"

void replaceStr(generic_string & str, generic_string str2BeReplaced, generic_string replacement)
using namespace std;

void replaceStr(wstring & str, wstring str2BeReplaced, wstring replacement)
{
size_t pos = str.find(str2BeReplaced);

Expand Down Expand Up @@ -131,7 +132,7 @@ size_t Printer::doPrint(bool justDoIt)
int fontSize = nppGUI._printSettings._headerFontSize?nppGUI._printSettings._headerFontSize:9;
int fontWeight = (nppGUI._printSettings._headerFontStyle & FONTSTYLE_BOLD) ? FW_BOLD : FW_NORMAL;
int isFontItalic = (nppGUI._printSettings._headerFontStyle & FONTSTYLE_ITALIC) ? TRUE : FALSE;
const TCHAR *fontFace = (nppGUI._printSettings._headerFontName != TEXT(""))?nppGUI._printSettings._headerFontName.c_str():TEXT("Arial");
const wchar_t *fontFace = (nppGUI._printSettings._headerFontName != L"")?nppGUI._printSettings._headerFontName.c_str():L"Arial";

int headerLineHeight = ::MulDiv(fontSize, ptDpi.y, 72);

Expand All @@ -151,7 +152,7 @@ size_t Printer::doPrint(bool justDoIt)
fontSize = nppGUI._printSettings._footerFontSize?nppGUI._printSettings._footerFontSize:9;
fontWeight = (nppGUI._printSettings._footerFontStyle & FONTSTYLE_BOLD) ? FW_BOLD : FW_NORMAL;
isFontItalic = (nppGUI._printSettings._footerFontStyle & FONTSTYLE_ITALIC) ? TRUE : FALSE;
fontFace = (nppGUI._printSettings._footerFontName != TEXT(""))?nppGUI._printSettings._footerFontName.c_str():TEXT("Arial");
fontFace = (nppGUI._printSettings._footerFontName != L"")?nppGUI._printSettings._footerFontName.c_str():L"Arial";

int footerLineHeight = ::MulDiv(fontSize, ptDpi.y, 72);
HFONT fontFooter = ::CreateFont(footerLineHeight,
Expand Down Expand Up @@ -181,7 +182,7 @@ size_t Printer::doPrint(bool justDoIt)

if (::StartDoc(_pdlg.hDC, &docInfo) < 0)
{
MessageBox(NULL, TEXT("Can not start printer document."), 0, MB_OK);
MessageBox(NULL, L"Can not start printer document.", 0, MB_OK);
return 0;
}

Expand Down Expand Up @@ -227,22 +228,22 @@ size_t Printer::doPrint(bool justDoIt)
frPrint.rc.right -= printMarge;

const int headerSize = 256;
TCHAR headerL[headerSize] = TEXT("");
TCHAR headerM[headerSize] = TEXT("");
TCHAR headerR[headerSize] = TEXT("");
TCHAR footerL[headerSize] = TEXT("");
TCHAR footerM[headerSize] = TEXT("");
TCHAR footerR[headerSize] = TEXT("");
wchar_t headerL[headerSize] = L"";
wchar_t headerM[headerSize] = L"";
wchar_t headerR[headerSize] = L"";
wchar_t footerL[headerSize] = L"";
wchar_t footerM[headerSize] = L"";
wchar_t footerR[headerSize] = L"";


const TCHAR shortDateVar[] = TEXT("$(SHORT_DATE)");
const TCHAR longDateVar[] = TEXT("$(LONG_DATE)");
const TCHAR timeVar[] = TEXT("$(TIME)");
const wchar_t shortDateVar[] = L"$(SHORT_DATE)";
const wchar_t longDateVar[] = L"$(LONG_DATE)";
const wchar_t timeVar[] = L"$(TIME)";

const int bufferSize = 64;
TCHAR shortDate[bufferSize];
TCHAR longDate[bufferSize];
TCHAR time[bufferSize];
wchar_t shortDate[bufferSize];
wchar_t longDate[bufferSize];
wchar_t time[bufferSize];

SYSTEMTIME st{};
::GetLocalTime(&st);
Expand All @@ -254,26 +255,26 @@ size_t Printer::doPrint(bool justDoIt)
{
frPrint.rc.top += headerLineHeight + headerLineHeight / 2;

generic_string headerLeftPart = nppGUI._printSettings._headerLeft;
if (headerLeftPart != TEXT(""))
wstring headerLeftPart = nppGUI._printSettings._headerLeft;
if (headerLeftPart != L"")
{
replaceStr(headerLeftPart, shortDateVar, shortDate);
replaceStr(headerLeftPart, longDateVar, longDate);
replaceStr(headerLeftPart, timeVar, time);
expandNppEnvironmentStrs(headerLeftPart.c_str(), headerL, headerSize, _pdlg.hwndOwner);
}

generic_string headerMiddlePart = nppGUI._printSettings._headerMiddle;
if (headerMiddlePart != TEXT(""))
wstring headerMiddlePart = nppGUI._printSettings._headerMiddle;
if (headerMiddlePart != L"")
{
replaceStr(headerMiddlePart, shortDateVar, shortDate);
replaceStr(headerMiddlePart, longDateVar, longDate);
replaceStr(headerMiddlePart, timeVar, time);
expandNppEnvironmentStrs(headerMiddlePart.c_str(), headerM, headerSize, _pdlg.hwndOwner);
}

generic_string headerRightPart = nppGUI._printSettings._headerRight;
if (headerRightPart != TEXT(""))
wstring headerRightPart = nppGUI._printSettings._headerRight;
if (headerRightPart != L"")
{
replaceStr(headerRightPart, shortDateVar, shortDate);
replaceStr(headerRightPart, longDateVar, longDate);
Expand All @@ -287,26 +288,26 @@ size_t Printer::doPrint(bool justDoIt)
{
frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2;

generic_string footerLeftPart = nppGUI._printSettings._footerLeft;
if (footerLeftPart != TEXT(""))
wstring footerLeftPart = nppGUI._printSettings._footerLeft;
if (footerLeftPart != L"")
{
replaceStr(footerLeftPart, shortDateVar, shortDate);
replaceStr(footerLeftPart, longDateVar, longDate);
replaceStr(footerLeftPart, timeVar, time);
expandNppEnvironmentStrs(footerLeftPart.c_str(), footerL, headerSize, _pdlg.hwndOwner);
}

generic_string footerMiddlePart = nppGUI._printSettings._footerMiddle;
if (footerMiddlePart != TEXT(""))
wstring footerMiddlePart = nppGUI._printSettings._footerMiddle;
if (footerMiddlePart != L"")
{
replaceStr(footerMiddlePart, shortDateVar, shortDate);
replaceStr(footerMiddlePart, longDateVar, longDate);
replaceStr(footerMiddlePart, timeVar, time);
expandNppEnvironmentStrs(footerMiddlePart.c_str(), footerM, headerSize, _pdlg.hwndOwner);
}

generic_string footerRightPart = nppGUI._printSettings._footerRight;
if (footerRightPart != TEXT(""))
wstring footerRightPart = nppGUI._printSettings._footerRight;
if (footerRightPart != L"")
{
replaceStr(footerRightPart, shortDateVar, shortDate);
replaceStr(footerRightPart, longDateVar, longDate);
Expand All @@ -321,7 +322,7 @@ size_t Printer::doPrint(bool justDoIt)
_pSEView->showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, false);

int pageNum = 1;
const TCHAR pageVar[] = TEXT("$(CURRENT_PRINTING_PAGE)");
const wchar_t pageVar[] = L"$(CURRENT_PRINTING_PAGE)";

_pSEView->execute(SCI_SETPRINTCOLOURMODE, nppGUI._printSettings._printOption); // setting mode once is enough
while (lengthPrinted < lengthDoc)
Expand All @@ -332,8 +333,8 @@ size_t Printer::doPrint(bool justDoIt)
if (!justDoIt)
printPage = false;

TCHAR pageString[32]{};
wsprintf(pageString, TEXT("%0d"), pageNum);
wchar_t pageString[32]{};
wsprintf(pageString, L"%0d", pageNum);

if (printPage)
{
Expand All @@ -357,7 +358,7 @@ size_t Printer::doPrint(bool justDoIt)
// Left part
if (headerL[0] != '\0')
{
generic_string headerLeft(headerL);
wstring headerLeft(headerL);
size_t pos = headerLeft.find(pageVar);

if (pos != headerLeft.npos)
Expand All @@ -370,7 +371,7 @@ size_t Printer::doPrint(bool justDoIt)
// Middle part
if (headerM[0] != '\0')
{
generic_string headerMiddle(headerM);
wstring headerMiddle(headerM);
size_t pos = headerMiddle.find(pageVar);
if (pos != headerMiddle.npos)
headerMiddle.replace(pos, lstrlen(pageVar), pageString);
Expand All @@ -382,7 +383,7 @@ size_t Printer::doPrint(bool justDoIt)
// Right part
if (headerR[0] != '\0')
{
generic_string headerRight(headerR);
wstring headerRight(headerR);
size_t pos = headerRight.find(pageVar);
if (pos != headerRight.npos)
headerRight.replace(pos, lstrlen(pageVar), pageString);
Expand Down Expand Up @@ -424,7 +425,7 @@ size_t Printer::doPrint(bool justDoIt)
// Left part
if (footerL[0] != '\0')
{
generic_string footerLeft(footerL);
wstring footerLeft(footerL);
size_t pos = footerLeft.find(pageVar);
if (pos != footerLeft.npos)
footerLeft.replace(pos, lstrlen(pageVar), pageString);
Expand All @@ -436,7 +437,7 @@ size_t Printer::doPrint(bool justDoIt)
// Middle part
if (footerM[0] != '\0')
{
generic_string footerMiddle(footerM);
wstring footerMiddle(footerM);
size_t pos = footerMiddle.find(pageVar);
if (pos != footerMiddle.npos)
footerMiddle.replace(pos, lstrlen(pageVar), pageString);
Expand All @@ -448,7 +449,7 @@ size_t Printer::doPrint(bool justDoIt)
// Right part
if (footerR[0] != '\0')
{
generic_string footerRight(footerR);
wstring footerRight(footerR);
size_t pos = footerRight.find(pageVar);
if (pos != footerRight.npos)
footerRight.replace(pos, lstrlen(pageVar), pageString);
Expand Down
Loading

0 comments on commit a301ffc

Please sign in to comment.