Make more improvements
This change includes many bug fixes, for the NT polyfills, strings, memory, boot, and math libraries which were discovered by adding more tools for recreational programming, such as PC emulation. Lemon has also been vendored because it works so well at parsing languages.
This commit is contained in:
@@ -26,6 +26,13 @@
|
||||
* @see getline
|
||||
*/
|
||||
char *(chomp)(char *line) {
|
||||
if (line) line[strcspn(line, "\r\n")] = '\0';
|
||||
size_t i;
|
||||
for (i = strlen(line); i--;) {
|
||||
if (line[i] == '\r' || line[i] == '\n') {
|
||||
line[i] = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@
|
||||
* @see getline
|
||||
*/
|
||||
char16_t *chomp16(char16_t *line) {
|
||||
if (line) line[strcspn(line, u"\r\n")] = '\0';
|
||||
if (line) line[strcspn16(line, u"\r\n")] = '\0';
|
||||
return line;
|
||||
}
|
||||
|
||||
@@ -283,24 +283,6 @@ extern int (*const hook$wcsncmp)(const wchar_t *, const wchar_t *, size_t);
|
||||
|
||||
#if __STDC_VERSION__ + 0 >= 201112
|
||||
|
||||
#define strstr(haystack, needle) \
|
||||
_Generic(*(haystack), wchar_t \
|
||||
: wcsstr, char16_t \
|
||||
: strstr16, default \
|
||||
: strstr)(haystack, needle)
|
||||
|
||||
#define strrchr(s, c) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: wcsrchr, char16_t \
|
||||
: strrchr16, default \
|
||||
: strrchr)(s, c)
|
||||
|
||||
#define strchrnul(s, c) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: wcschrnul, char16_t \
|
||||
: strchrnul16, default \
|
||||
: strchrnul)(s, c)
|
||||
|
||||
#define strnlen(s, n) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: wcsnlen, char16_t \
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
/**
|
||||
* Returns prefix length, consisting of chars not in reject.
|
||||
* a.k.a. Return index of first byte that's in charset.
|
||||
*
|
||||
* @param reject is nul-terminated character set
|
||||
* @see strspn(), strtok_r()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
size_t(strcspn)(const char *s, const char *reject) {
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
char *(strstr)(const char *haystack, const char *needle) {
|
||||
if (needle[0]) {
|
||||
if (needle[1]) {
|
||||
if (!((intptr_t)needle & 0xf) && X86_HAVE(SSE4_2) && !IsTiny()) {
|
||||
if (!((intptr_t)needle & 0xf) && X86_HAVE(SSE4_2)) {
|
||||
return strstr$sse42(haystack, needle);
|
||||
} else {
|
||||
size_t needlelen;
|
||||
alignas(16) char needle2[64];
|
||||
needlelen = strlen(needle);
|
||||
if (needlelen < 64 && X86_HAVE(SSE4_2) && !IsTiny()) {
|
||||
if (needlelen < 64 && X86_HAVE(SSE4_2)) {
|
||||
memcpy(needle2, needle, (needlelen + 1) * sizeof(char));
|
||||
return strstr$sse42(haystack, needle2);
|
||||
} else {
|
||||
|
||||
@@ -26,6 +26,6 @@
|
||||
* @see getline
|
||||
*/
|
||||
wchar_t *wchomp(wchar_t *line) {
|
||||
if (line) line[strcspn(line, L"\r\n")] = '\0';
|
||||
if (line) line[wcscspn(line, L"\r\n")] = '\0';
|
||||
return line;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user