+ rfc: moving common methods to helper module

This commit is contained in:
Rainer Kottenhoff 2018-04-26 09:06:11 +02:00
parent 29125b8227
commit bd5d443f2a
4 changed files with 81 additions and 77 deletions

View File

@ -2826,6 +2826,76 @@ void UrlUnescapeEx(LPWSTR lpURL, LPWSTR lpUnescaped, DWORD* pcchUnescaped)
}
//=============================================================================
//
// ReadStrgsFromCSV()
//
//
int ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int const iCount, int const iLen, LPCWSTR sDefault)
{
static WCHAR wchTmpBuff[MIDSZ_BUFFER];
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchCSVStrg);
TrimString(wchTmpBuff);
// separate values
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
for (int i = 0; i < len; ++i) {
if (wchTmpBuff[i] == L',') { wchTmpBuff[i] = L'\0'; }
}
// fill default
for (int i = 0; i < iCount; ++i) { StringCchCopyW(sMatrix[i], (size_t)iLen, sDefault); }
// insert values
int n = 0;
WCHAR* p = wchTmpBuff;
while (*p) {
if (n < iCount) {
StringCchCopyW(sMatrix[n++], (size_t)iLen, p);
}
p = StrEnd(p) + 1;
}
return n;
}
//=============================================================================
//
// ReadVectorFromString()
//
//
int ReadVectorFromString(LPCWSTR wchStrg, int* iVector, int iCount, int iMin, int iMax, int iDefault)
{
static WCHAR wchTmpBuff[SMALL_BUFFER];
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchStrg);
TrimString(wchTmpBuff);
// ensure single spaces only
WCHAR *p = StrStr(wchTmpBuff, L" ");
while (p) {
MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR));
p = StrStr(wchTmpBuff, L" "); // next
}
// separate values
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
for (int i = 0; i < len; ++i) {
if (wchTmpBuff[i] == L' ') { wchTmpBuff[i] = L'\0'; }
}
// fill default
for (int i = 0; i < iCount; ++i) { iVector[i] = iDefault; }
// insert values
int n = 0;
p = wchTmpBuff;
while (*p) {
int iValue;
if (swscanf_s(p, L"%i", &iValue) == 1) {
if ((n < iCount) && (iValue >= iMin) && (iValue <= iMax)) {
iVector[n++] = iValue;
}
}
p = StrEnd(p) + 1;
}
return n;
}
///////////////////////////////////////////////////////////////////////////////
//

View File

@ -389,9 +389,11 @@ __forceinline int GetHexDigit(char ch) {
}
void UrlUnescapeEx(LPWSTR, LPWSTR, DWORD*);
int ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int const iCount, int const iLen, LPCWSTR sDefault);
int ReadVectorFromString(LPCWSTR wchStrg, int* iVector, int iCount, int iMin, int iMax, int iDefault);
// --------------------------------------------------------------------------------------------------------------------------------
// including <pathcch.h> and linking against pathcch.lib
@ -402,6 +404,8 @@ __forceinline HRESULT PathCchCanonicalize(PWSTR p,size_t l,PCWSTR a) { UNUSED
__forceinline HRESULT PathCchRenameExtension(PWSTR p,size_t l,PCWSTR a) { UNUSED(l); return (PathRenameExtension(p,a) ? S_OK : E_FAIL); }
__forceinline HRESULT PathCchRemoveFileSpec(PWSTR p,size_t l) { UNUSED(l); return (PathRemoveFileSpec(p) ? S_OK : E_FAIL); }
// special Drag and Drop Handling
typedef struct tDROPDATA

View File

@ -733,83 +733,10 @@ bool InitApplication(HINSTANCE hInstance)
}
typedef WCHAR prefix_t[MICRO_BUFFER];
static prefix_t g_mxStatusBarPrefix[STATUS_SECTOR_COUNT];
static int g_vStatusbarSectionWidth[STATUS_SECTOR_COUNT];
static int g_aSBSOrder[STATUS_SECTOR_COUNT];
//=============================================================================
//
// _ReadVectorFromString()
//
//
static int __fastcall _ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int const iCount, int const iLen, LPCWSTR sDefault)
{
static WCHAR wchTmpBuff[MIDSZ_BUFFER];
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchCSVStrg);
TrimString(wchTmpBuff);
// separate values
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
for (int i = 0; i < len; ++i) {
if (wchTmpBuff[i] == L',') { wchTmpBuff[i] = L'\0'; }
}
// fill default
for (int i = 0; i < iCount; ++i) { StringCchCopyW(sMatrix[i], (size_t)iLen, sDefault); }
// insert values
int n = 0;
WCHAR* p = wchTmpBuff;
while (*p) {
if (n < iCount) {
StringCchCopyW(sMatrix[n++], (size_t)iLen, p);
}
p = StrEnd(p) + 1;
}
return n;
}
//=============================================================================
//
// _ReadVectorFromString()
//
//
static int __fastcall _ReadVectorFromString(LPCWSTR wchStrg, int* iVector, int iCount, int iMin, int iMax, int iDefault)
{
static WCHAR wchTmpBuff[SMALL_BUFFER];
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchStrg);
TrimString(wchTmpBuff);
// ensure single spaces only
WCHAR *p = StrStr(wchTmpBuff, L" ");
while (p) {
MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR));
p = StrStr(wchTmpBuff, L" "); // next
}
// separate values
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
for (int i = 0; i < len; ++i) {
if (wchTmpBuff[i] == L' ') { wchTmpBuff[i] = L'\0'; }
}
// fill default
for (int i = 0; i < iCount; ++i) { iVector[i] = iDefault; }
// insert values
int n = 0;
p = wchTmpBuff;
while (*p) {
int iValue;
if (swscanf_s(p, L"%i", &iValue) == 1) {
if ((n < iCount) && (iValue >= iMin) && (iValue <= iMax)) {
iVector[n++] = iValue;
}
}
p = StrEnd(p) + 1;
}
return n;
}
//=============================================================================
//
// _StatusbarSetSections()
@ -827,10 +754,10 @@ static void __fastcall _StatusbarSetSections(int cx)
}
int vSections[STATUS_SECTOR_COUNT];
_ReadVectorFromString(g_tchStatusbarSections, vSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1);
ReadVectorFromString(g_tchStatusbarSections, vSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1);
int vWeights[STATUS_SECTOR_COUNT];
_ReadVectorFromString(g_tchStatusbarRelWidths, vWeights, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), 1);
ReadVectorFromString(g_tchStatusbarRelWidths, vWeights, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), 1);
int cnt = 0;
int totalWeight = 0;
@ -954,7 +881,7 @@ static void __fastcall _InitWindowPosition(HWND hwnd)
}
}
_ReadStrgsFromCSV(g_tchStatusbarPrefixes, g_mxStatusBarPrefix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"");
ReadStrgsFromCSV(g_tchStatusbarPrefixes, g_mxStatusBarPrefix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"");
_StatusbarSetSections(g_WinInfo.cx);
}

View File

@ -80,6 +80,9 @@ typedef enum { MBINFO = 0, MBWARN, MBYESNO, MBYESNOWARN, MBYESNOCANCEL, MBOKCANC
//==== Statusbar ==============================================================
typedef WCHAR prefix_t[MICRO_BUFFER];
typedef enum {
STATUS_DOCLINE = 0, STATUS_DOCCOLUMN, STATUS_SELECTION, STATUS_SELCTLINES, STATUS_OCCURRENCE,
STATUS_DOCSIZE, STATUS_CODEPAGE, STATUS_EOLMODE, STATUS_OVRMODE, STATUS_2ND_DEF, STATUS_LEXER,