Major POSIX overhaul

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6416 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2013-12-08 14:34:38 +00:00
parent 1e55e30ff4
commit be6c7e6a1d
35 changed files with 1718 additions and 1412 deletions

View file

@ -12,18 +12,98 @@
*
* This software is provided 'as-is', without any express or implied
* warranty.
*
* Reviewed for Unicode support by Jim Park -- 08/13/2007
*/
#include "Platform.h"
#include "winchar.h"
#include "util.h"
#include "utf.h"
#include <stdexcept>
#include <cassert>
using std::runtime_error;
int WinWStrICmpASCII(const WINWCHAR *a, const char *b)
{
int diff = 0;
do
diff = static_cast<int>(S7ChLwr(*a)) - static_cast<int>(S7ChLwr(*b++));
while (*a++ && !diff);
return diff;
}
int WinWStrNICmpASCII(const WINWCHAR *a, const char *b, size_t n)
{
int diff = 0;
for ( ; n--; ++a, ++b )
{
diff = static_cast<int>(S7ChLwr(*a)) - static_cast<int>(S7ChLwr(*b));
if (diff || !*a) break;
}
return diff;
}
#ifndef _WIN32
size_t WinWStrLen(const WINWCHAR *s)
{
return StrLenUTF16(s);
}
WINWCHAR* WinWStrCpy(WINWCHAR *d, const WINWCHAR *s)
{
WINWCHAR *ret = d;
while (*s) *d++ = *s++;
*d = 0;
return ret;
}
WINWCHAR* WinWStrNCpy(WINWCHAR *d, const WINWCHAR *s, size_t n)
{
WINWCHAR *ret = d;
while (n && *s) *d++ = *s++, n--;
while (n--) *d++ = 0;
return ret;
}
int WinWStrCmp(const WINWCHAR *a, const WINWCHAR *b)
{
int diff = 0;
do
diff = static_cast<int>(*a) - static_cast<int>(*b++);
while (*a++ && !diff);
return diff;
}
WINWCHAR* WinWStrDupFromWinWStr(const WINWCHAR *s)
{
WINWCHAR *d = (WINWCHAR*) malloc((WinWStrLen(s) + 1) * sizeof(WINWCHAR));
if (d) WinWStrCpy(d, s);
assert(!d || !IS_INTRESOURCE(d)); // DialogTemplate strings can be ATOMs
return d;
}
WINWCHAR* WinWStrDupFromTChar(const TCHAR *s)
{
WCToUTF16LEHlpr cnv;
if (!cnv.Create(s)) throw runtime_error("Unicode conversion failed");
return (WINWCHAR*) cnv.Detach();
}
int WinWStrToInt(const WINWCHAR *s)
{
unsigned int v = 0, base = 10, top = '9';
int sign = 1;
if (*s == _T('-')) ++s, sign = -1;
for ( unsigned int c;; )
{
if ((c = *s++) >= '0' && c <= top) c -= '0'; else break;
v *= base, v += c;
}
return ((int)v) * sign;
}
#endif // ~!_WIN32
#if 0
WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage/* = CP_ACP*/)
{
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
@ -31,75 +111,8 @@ WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage/* = CP_ACP*/)
throw runtime_error("Unicode conversion failed");
WCHAR *ws = new WCHAR[l + 1];
if (MultiByteToWideChar(codepage, 0, s, -1, ws, l + 1) == 0)
throw runtime_error("Unicode conversion failed");
return ws;
}
#if 0 // Needed by some RTL missing wchar string functions ?
WCHAR *wcscpy(WCHAR *ws1, const WCHAR *ws2)
{
WCHAR *ret = ws1;
while (*ws2)
{
*ws1++ = *ws2++;
}
*ws1 = 0;
return ret;
}
WCHAR *wcsncpy(WCHAR *ws1, const WCHAR *ws2, size_t n)
{
WCHAR *ret = ws1;
while (n && *ws2)
{
*ws1++ = *ws2++;
n--;
}
while (n--)
{
*ws1++ = 0;
}
return ret;
}
size_t wcslen(const WCHAR *ws)
{
size_t len = 0;
while (*ws++)
{
len++;
}
return len;
}
WCHAR *_wcsdup(const WCHAR *ws)
{
WCHAR *dup = (WCHAR*) malloc(sizeof(WCHAR)*(wcslen(ws)+1)];
wcscpy(dup, ws);
return dup;
}
int wcscmp(const WCHAR *ws1, const WCHAR *ws2)
{
int diff = 0;
do
{
diff = static_cast<int>(*ws1) - static_cast<int>(*ws2);
}
while (*ws1++ && *ws2++ && !diff);
return diff;
}
#endif