path
stringlengths
14
112
content
stringlengths
0
6.32M
size
int64
0
6.32M
max_lines
int64
1
100k
repo_name
stringclasses
2 values
autogenerated
bool
1 class
cosmopolitan/libc/str/getzipcfiletimestamps.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/conv.h" #include "libc/zip.h" static inline int pop(int x) { return !!(x & 1) + !!(x & 2) + !!(x & 4); } /** * Extracts modified/access/creation timestamps from zip entry. * * @param cf is pointer to central directory header for file * @param mtim optionally receives last modified timestamp * @param atim optionally receives modified timestamp * @param ctim optionally receives creation timestamp * @param gmtoff is seconds adjustment for legacy dos timestamps */ void GetZipCfileTimestamps(const uint8_t *cf, struct timespec *mtim, struct timespec *atim, struct timespec *ctim, int gmtoff) { const uint8_t *p, *pe; if (mtim) *mtim = (struct timespec){0}; if (atim) *atim = (struct timespec){0}; if (ctim) *ctim = (struct timespec){0}; for (p = ZIP_CFILE_EXTRA(cf), pe = p + ZIP_CFILE_EXTRASIZE(cf); p + 4 <= pe; p += ZIP_EXTRA_SIZE(p)) { if (ZIP_EXTRA_HEADERID(p) == kZipExtraNtfs && ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 && READ16LE(ZIP_EXTRA_CONTENT(p) + 4) == 1 && READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 8) { if (mtim) { *mtim = WindowsTimeToTimeSpec(READ64LE(ZIP_EXTRA_CONTENT(p) + 8)); } if (atim && ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 * 2 && READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 16) { *atim = WindowsTimeToTimeSpec(READ64LE(ZIP_EXTRA_CONTENT(p) + 8 * 2)); } if (ctim && ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 * 3 && READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 24) { *ctim = WindowsTimeToTimeSpec(READ64LE(ZIP_EXTRA_CONTENT(p) + 8 * 3)); } return; } } for (p = ZIP_CFILE_EXTRA(cf), pe = p + ZIP_CFILE_EXTRASIZE(cf); p + 4 <= pe; p += ZIP_EXTRA_SIZE(p)) { if (ZIP_EXTRA_HEADERID(p) == kZipExtraExtendedTimestamp && ZIP_EXTRA_CONTENTSIZE(p) > 1 && ZIP_EXTRA_CONTENTSIZE(p) == 1 + 4 * pop(*ZIP_EXTRA_CONTENT(p) & 7)) { if (mtim) { if (*ZIP_EXTRA_CONTENT(p) & 1) { mtim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 1); } else { mtim->tv_sec = DosDateTimeToUnix(ZIP_CFILE_LASTMODIFIEDDATE(cf), ZIP_CFILE_LASTMODIFIEDTIME(cf)) - gmtoff; } } if (atim && (*ZIP_EXTRA_CONTENT(p) & 2)) { atim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 1 + 4 * (*ZIP_EXTRA_CONTENT(p) & 1)); } if (ctim && (*ZIP_EXTRA_CONTENT(p) & 4)) { ctim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 1 + 4 * pop(*ZIP_EXTRA_CONTENT(p) & 3)); } return; } } for (p = ZIP_CFILE_EXTRA(cf), pe = p + ZIP_CFILE_EXTRASIZE(cf); p + 4 <= pe; p += ZIP_EXTRA_SIZE(p)) { if (ZIP_EXTRA_HEADERID(p) == kZipExtraUnix && ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4) { if (atim) atim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 0); if (mtim) mtim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 4); return; } } if (mtim) { mtim->tv_sec = DosDateTimeToUnix(ZIP_CFILE_LASTMODIFIEDDATE(cf), ZIP_CFILE_LASTMODIFIEDTIME(cf)) - gmtoff; } }
5,151
102
jart/cosmopolitan
false
cosmopolitan/libc/str/lz4check.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/nexgen32e/kompressor.h" #include "libc/nexgen32e/lz4.h" const unsigned char *lz4check(const void *data) { const unsigned char *frame = data; if (LZ4_MAGIC(frame) == LZ4_MAGICNUMBER && LZ4_FRAME_VERSION(frame) == 1 && LZ4_FRAME_BLOCKINDEPENDENCE(frame) == true && LZ4_FRAME_BLOCKCONTENTSIZEFLAG(frame) == true && LZ4_FRAME_RESERVED1(frame) == 0 && LZ4_FRAME_RESERVED2(frame) == 0 && LZ4_FRAME_RESERVED3(frame) == 0) { return frame; } else { return NULL; } }
2,349
34
jart/cosmopolitan
false
cosmopolitan/libc/str/strxfrm.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ This is free and unencumbered software released into the public domain. │ │ │ │ Anyone is free to copy, modify, publish, use, compile, sell, or │ │ distribute this software, either in source code form or as a compiled │ │ binary, for any purpose, commercial or non-commercial, and by any │ │ means. │ │ │ │ In jurisdictions that recognize copyright laws, the author or authors │ │ of this software dedicate any and all copyright interest in the │ │ software to the public domain. We make this dedication for the benefit │ │ of the public at large and to the detriment of our heirs and │ │ successors. We intend this dedication to be an overt act of │ │ relinquishment in perpetuity of all present and future rights to this │ │ software under copyright law. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ │ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ │ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │ │ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │ │ OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/str/str.h" /** * Transforms strings into current C locale. * calling strcmp() on two strxfrm()-ed strings * is same as calling strcoll() on the originals. * * @param dest is buffer which needn't be initialized * @param src is a NUL-terminated string * @param count is number of bytes to write to destination * @return length of transformed string * @note dest and src can't overlap * @note dest array size should be greater than count * @note if dest is NULL, count has to be zero */ size_t strxfrm(char *dest, const char *src, size_t count) { _unassert(dest == NULL ? count == 0 : 1); return strlcpy(dest, src, count); }
3,280
48
jart/cosmopolitan
false
cosmopolitan/libc/str/islower.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is lowercase alpha ascii character. */ int islower(int c) { return 'a' <= c && c <= 'z'; }
1,985
27
jart/cosmopolitan
false
cosmopolitan/libc/str/wcrtomb.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╚──────────────────────────────────────────────────────────────────────────────╝ │ │ │ Musl Libc │ │ Copyright © 2005-2014 Rich Felker, et al. │ │ │ │ Permission is hereby granted, free of charge, to any person obtaining │ │ a copy of this software and associated documentation files (the │ │ "Software"), to deal in the Software without restriction, including │ │ without limitation the rights to use, copy, modify, merge, publish, │ │ distribute, sublicense, and/or sell copies of the Software, and to │ │ permit persons to whom the Software is furnished to do so, subject to │ │ the following conditions: │ │ │ │ The above copyright notice and this permission notice shall be │ │ included in all copies or substantial portions of the Software. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ │ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ │ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │ │ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │ │ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/limits.h" #include "libc/str/mb.internal.h" #include "libc/str/str.h" asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) { if (!s) return 1; if ((unsigned)wc < 0x80) { *s = wc; return 1; } else if (MB_CUR_MAX == 1) { if (!IS_CODEUNIT(wc)) { errno = EILSEQ; return -1; } *s = wc; return 1; } else if ((unsigned)wc < 0x800) { *s++ = 0xc0 | (wc >> 6); *s = 0x80 | (wc & 0x3f); return 2; } else if ((unsigned)wc < 0xd800 || (unsigned)wc - 0xe000 < 0x2000) { *s++ = 0xe0 | (wc >> 12); *s++ = 0x80 | ((wc >> 6) & 0x3f); *s = 0x80 | (wc & 0x3f); return 3; } else if ((unsigned)wc - 0x10000 < 0x100000) { *s++ = 0xf0 | (wc >> 18); *s++ = 0x80 | ((wc >> 12) & 0x3f); *s++ = 0x80 | ((wc >> 6) & 0x3f); *s = 0x80 | (wc & 0x3f); return 4; } errno = EILSEQ; return -1; }
3,641
69
jart/cosmopolitan
false
cosmopolitan/libc/str/wcscmp.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Compares NUL-terminated wide strings. * * @param a is first non-null NUL-terminated string pointer * @param b is second non-null NUL-terminated string pointer * @return is <0, 0, or >0 based on uint8_t comparison * @asyncsignalsafe */ int wcscmp(const wchar_t *a, const wchar_t *b) { size_t i = 0; if (a == b) return 0; while (a[i] == b[i] && b[i]) ++i; return (int)a[i] < (int)b[i] ? -1 : (int)a[i] > (int)b[i]; }
2,299
35
jart/cosmopolitan
false
cosmopolitan/libc/str/iswprint_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int iswprint_l(wint_t c, locale_t l) { return iswprint(c); }
1,955
25
jart/cosmopolitan
false
cosmopolitan/libc/str/blake2.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Google LLC │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/blake2.h" #include "libc/assert.h" #include "libc/macros.internal.h" #include "libc/str/str.h" #define ROR(v, n) (((v) >> (n)) | ((v) << (64 - (n)))) asm(".ident\t\"\\n\\n\ boringssl blake2b (ISC License)\\n\ Copyright 2021 Google LLC\""); asm(".include \"libc/disclaimer.inc\""); // https://tools.ietf.org/html/rfc7693#section-2.6 static const uint64_t kIV[8] = { 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1, 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179, }; // https://tools.ietf.org/html/rfc7693#section-2.7 static const uint8_t kSigma[10][16] = { // clang-format off {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8}, {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13}, {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9}, {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11}, {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10}, {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5}, {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0}, // clang-format on }; // https://tools.ietf.org/html/rfc7693#section-3.1 static void Blake2bMix(uint64_t v[16], int a, int b, int c, int d, uint64_t x, uint64_t y) { v[a] = v[a] + v[b] + x; v[d] = ROR(v[d] ^ v[a], 32); v[c] = v[c] + v[d]; v[b] = ROR(v[b] ^ v[c], 24); v[a] = v[a] + v[b] + y; v[d] = ROR(v[d] ^ v[a], 16); v[c] = v[c] + v[d]; v[b] = ROR(v[b] ^ v[c], 63); } static void Blake2bTransform( struct Blake2b *b2b, const uint64_t w[BLAKE2B_CBLOCK / sizeof(uint64_t)], size_t num_bytes, int is_final_block) { // https://tools.ietf.org/html/rfc7693#section-3.2 uint64_t v[16]; _Static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), ""); memcpy(v, b2b->h, sizeof(b2b->h)); memcpy(&v[8], kIV, sizeof(kIV)); b2b->t_low += num_bytes; if (b2b->t_low < num_bytes) { b2b->t_high++; } v[12] ^= b2b->t_low; v[13] ^= b2b->t_high; if (is_final_block) { v[14] = ~v[14]; } for (int i = 0; i < 12; i++) { Blake2bMix(v, 0, 4, 8, 12, w[kSigma[i % 10][0]], w[kSigma[i % 10][1]]); Blake2bMix(v, 1, 5, 9, 13, w[kSigma[i % 10][2]], w[kSigma[i % 10][3]]); Blake2bMix(v, 2, 6, 10, 14, w[kSigma[i % 10][4]], w[kSigma[i % 10][5]]); Blake2bMix(v, 3, 7, 11, 15, w[kSigma[i % 10][6]], w[kSigma[i % 10][7]]); Blake2bMix(v, 0, 5, 10, 15, w[kSigma[i % 10][8]], w[kSigma[i % 10][9]]); Blake2bMix(v, 1, 6, 11, 12, w[kSigma[i % 10][10]], w[kSigma[i % 10][11]]); Blake2bMix(v, 2, 7, 8, 13, w[kSigma[i % 10][12]], w[kSigma[i % 10][13]]); Blake2bMix(v, 3, 4, 9, 14, w[kSigma[i % 10][14]], w[kSigma[i % 10][15]]); } for (size_t i = 0; i < ARRAYLEN(b2b->h); i++) { b2b->h[i] ^= v[i]; b2b->h[i] ^= v[i + 8]; } } int BLAKE2B256_Init(struct Blake2b *b2b) { bzero(b2b, sizeof(struct Blake2b)); _Static_assert(sizeof(kIV) == sizeof(b2b->h), ""); memcpy(&b2b->h, kIV, sizeof(kIV)); // https://tools.ietf.org/html/rfc7693#section-2.5 b2b->h[0] ^= 0x01010000 | BLAKE2B256_DIGEST_LENGTH; return 0; } int BLAKE2B256_Process(struct Blake2b *b2b, const uint64_t data[BLAKE2B_CBLOCK / 8]) { Blake2bTransform(b2b, data, BLAKE2B_CBLOCK, /*is_final_block=*/0); return 0; } int BLAKE2B256_Update(struct Blake2b *b2b, const void *in_data, size_t len) { const uint8_t *data = (const uint8_t *)in_data; size_t todo = sizeof(b2b->block.bytes) - b2b->block_used; if (todo > len) { todo = len; } if (todo) memcpy(&b2b->block.bytes[b2b->block_used], data, todo); b2b->block_used += todo; data += todo; len -= todo; if (!len) { return 0; } // More input remains therefore we must have filled |b2b->block|. _unassert(b2b->block_used == BLAKE2B_CBLOCK); Blake2bTransform(b2b, b2b->block.words, BLAKE2B_CBLOCK, /*is_final_block=*/0); b2b->block_used = 0; while (len > BLAKE2B_CBLOCK) { uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)]; memcpy(block_words, data, sizeof(block_words)); Blake2bTransform(b2b, block_words, BLAKE2B_CBLOCK, /*is_final_block=*/0); data += BLAKE2B_CBLOCK; len -= BLAKE2B_CBLOCK; } if (len) memcpy(b2b->block.bytes, data, len); b2b->block_used = len; return 0; } int BLAKE2B256_Final(struct Blake2b *b2b, uint8_t out[BLAKE2B256_DIGEST_LENGTH]) { bzero(&b2b->block.bytes[b2b->block_used], sizeof(b2b->block.bytes) - b2b->block_used); Blake2bTransform(b2b, b2b->block.words, b2b->block_used, /*is_final_block=*/1); _Static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), ""); memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH); return 0; } /** * Computes blake2b 256bit message digest. * * blake2b256 n=0 191 nanoseconds * blake2b256 n=8 23 ns/byte 40,719 kb/s * blake2b256 n=31 6 ns/byte 153 mb/s * blake2b256 n=32 6 ns/byte 158 mb/s * blake2b256 n=63 3 ns/byte 312 mb/s * blake2b256 n=64 3 ns/byte 317 mb/s * blake2b256 n=128 1 ns/byte 640 mb/s * blake2b256 n=256 1 ns/byte 662 mb/s * blake2b256 n=22851 1 ns/byte 683 mb/s * * @param data is binary memory to hash * @param len is bytes in `data` * @param out receives 32 byte binary digest * @return 0 on success (always successful) */ int BLAKE2B256(const void *data, size_t len, uint8_t out[BLAKE2B256_DIGEST_LENGTH]) { struct Blake2b ctx; BLAKE2B256_Init(&ctx); BLAKE2B256_Update(&ctx, data, len); BLAKE2B256_Final(&ctx, out); return 0; }
7,845
182
jart/cosmopolitan
false
cosmopolitan/libc/str/iswcntrl.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is C0 or C1 control code. */ int iswcntrl(wint_t c) { return (0x00 <= c && c <= 0x1F) || (0x7F <= c && c <= 0x9F); }
2,011
27
jart/cosmopolitan
false
cosmopolitan/libc/str/isgraph.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is printable ascii that isn't space. */ int isgraph(int c) { return 0x21 <= c && c <= 0x7E; }
1,988
27
jart/cosmopolitan
false
cosmopolitan/libc/str/getzipcfileuncompressedsize.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/zip.h" /** * Returns uncompressed size in bytes from zip central directory header. */ uint64_t GetZipCfileUncompressedSize(const uint8_t *z) { uint64_t x; const uint8_t *p, *pe; if ((x = ZIP_CFILE_UNCOMPRESSEDSIZE(z)) == 0xFFFFFFFF) { for (p = ZIP_CFILE_EXTRA(z), pe = p + ZIP_CFILE_EXTRASIZE(z); p < pe; p += ZIP_EXTRA_SIZE(p)) { if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64 && 0 + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { return READ64LE(ZIP_EXTRA_CONTENT(p) + 0); } } } return x; }
2,387
38
jart/cosmopolitan
false
cosmopolitan/libc/str/wcspbrk.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** * Returns pointer to first byte matching any in accept, or NULL. * @asyncsignalsafe */ wchar_t *wcspbrk(const wchar_t *s, const wchar_t *accept) { size_t i; if (accept[0]) { if (!accept[1]) { return wcschr(s, accept[0]); } else { for (i = 0; s[i]; ++i) { if (HasCharacterWide(s[i], accept)) { return (/*unconst*/ wchar_t *)&s[i]; } } } } return NULL; }
2,337
41
jart/cosmopolitan
false
cosmopolitan/libc/str/mbsinit.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" int mbsinit(const mbstate_t *t) { return !t || !*t; }
1,919
24
jart/cosmopolitan
false
cosmopolitan/libc/str/windowsdurationtotimespec.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/conv.h" struct timespec WindowsDurationToTimeSpec(int64_t x) { return (struct timespec){x / HECTONANOSECONDS, x % HECTONANOSECONDS * 100}; }
1,999
24
jart/cosmopolitan
false
cosmopolitan/libc/str/istext.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns true if buffer is most likely plaintext. */ bool _istext(const void *data, size_t size) { const unsigned char *p, *pe; for (p = data, pe = p + size; p < pe; ++p) { if (*p <= 3) { return false; } } return true; }
2,113
33
jart/cosmopolitan
false
cosmopolitan/libc/str/iswlower_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int iswlower_l(wint_t c, locale_t l) { return iswlower(c); }
1,955
25
jart/cosmopolitan
false
cosmopolitan/libc/str/iswupper_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int iswupper_l(wint_t c, locale_t l) { return iswupper(c); }
1,955
25
jart/cosmopolitan
false
cosmopolitan/libc/str/str.h
#ifndef COSMOPOLITAN_LIBC_STR_STR_H_ #define COSMOPOLITAN_LIBC_STR_STR_H_ #define INVALID_CODEPOINT 0xfffd #define _tolower(u) (0040 | (u)) #define _toupper(u) (0137 & (u)) #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ int isascii(int); int isspace(int); int isalpha(int); int isdigit(int); int isalnum(int); int isxdigit(int); int isprint(int); int islower(int); int isupper(int); int isblank(int); int iscntrl(int); int isgraph(int); int tolower(int); int ispunct(int); int toupper(int); int toascii(int); int hextoint(int); int _cescapec(int); int iswalnum(wint_t); int iswalpha(wint_t); int iswblank(wint_t); int iswcntrl(wint_t); int iswdigit(wint_t); int iswgraph(wint_t); int iswlower(wint_t); int iswspace(wint_t); int iswupper(wint_t); int iswxdigit(wint_t); int iswpunct(wint_t); int iswprint(wint_t); int iswseparator(wint_t); wint_t towlower(wint_t); wint_t towupper(wint_t); void bzero(void *, size_t) memcpyesque; void *memset(void *, int, size_t) memcpyesque; void *memmove(void *, const void *, size_t) memcpyesque; void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque; void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque; char *hexpcpy(char *restrict, const void *restrict, size_t) memcpyesque; void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque; void bcopy(const void *, void *, size_t) memcpyesque; void explicit_bzero(void *, size_t); int bcmp(const void *, const void *, size_t) strlenesque; int memcmp(const void *, const void *, size_t) strlenesque; int timingsafe_bcmp(const void *, const void *, size_t); int timingsafe_memcmp(const void *, const void *, size_t); size_t strlen(const char *) strlenesque; size_t strnlen(const char *, size_t) strlenesque; size_t strnlen_s(const char *, size_t); char *strchr(const char *, int) strlenesque; char *index(const char *, int) strlenesque; void *memchr(const void *, int, size_t) strlenesque; char *strchrnul(const char *, int) strlenesque returnsnonnull; void *rawmemchr(const void *, int) strlenesque returnsnonnull; size_t strlen16(const char16_t *) strlenesque; size_t strnlen16(const char16_t *, size_t) strlenesque; char16_t *strchr16(const char16_t *, int) strlenesque; void *memchr16(const void *, int, size_t) strlenesque; char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull; void *rawmemchr16(const void *, int) strlenesque returnsnonnull; size_t wcslen(const wchar_t *) strlenesque; size_t wcsnlen(const wchar_t *, size_t) strlenesque; size_t wcsnlen_s(const wchar_t *, size_t); wchar_t *wcschr(const wchar_t *, wchar_t) strlenesque; wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque; wchar_t *wcschrnul(const wchar_t *, wchar_t) strlenesque returnsnonnull; char *strstr(const char *, const char *) strlenesque; char *strcasestr(const char *, const char *) strlenesque; char16_t *strstr16(const char16_t *, const char16_t *) strlenesque; wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque; int strcmp(const char *, const char *) strlenesque; int strncmp(const char *, const char *, size_t) strlenesque; int strcmp16(const char16_t *, const char16_t *) strlenesque; int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque; int wcscmp(const wchar_t *, const wchar_t *) strlenesque; int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque; int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque; int strcasecmp(const char *, const char *) strlenesque; int memcasecmp(const void *, const void *, size_t) strlenesque; int strcasecmp16(const char16_t *, const char16_t *) strlenesque; int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque; int strncasecmp(const char *, const char *, size_t) strlenesque; int strncasecmp16(const char16_t *, const char16_t *, size_t) strlenesque; int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque; char *strrchr(const char *, int) strlenesque; void *memrchr(const void *, int, size_t) strlenesque; char16_t *strrchr16(const char16_t *, int) strlenesque; void *memrchr16(const void *, int, size_t) strlenesque; wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque; void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque; char *strpbrk(const char *, const char *) strlenesque; char16_t *strpbrk16(const char16_t *, const char16_t *) strlenesque; wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque; size_t strspn(const char *, const char *) strlenesque; size_t strspn16(const char16_t *, const char16_t *) strlenesque; size_t wcsspn(const wchar_t *, const wchar_t *) strlenesque; size_t strcspn(const char *, const char *) strlenesque; size_t strcspn16(const char16_t *, const char16_t *) strlenesque; size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque; void *memfrob(void *, size_t) memcpyesque; int strcoll(const char *, const char *) strlenesque; char *strsep(char **, const char *) paramsnonnull(); int strcmpzbw(const uint16_t *, const char *) strlenesque; int strcasecmpzbw(const uint16_t *, const char *) strlenesque; char *stpcpy(char *, const char *) memcpyesque; char *stpncpy(char *, const char *, size_t) memcpyesque; char *strcat(char *, const char *) memcpyesque; char16_t *strcat16(char16_t *, const char16_t *) memcpyesque; wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque; size_t strlcpy(char *, const char *, size_t); size_t strlcat(char *, const char *, size_t); size_t strxfrm(char *, const char *, size_t); char *strcpy(char *, const char *) memcpyesque; char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque; wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque; char *strncat(char *, const char *, size_t) memcpyesque; char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque; wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque; char *strncpy(char *, const char *, size_t) memcpyesque; char *strtok(char *, const char *) paramsnonnull((2)) libcesque; char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3)); wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3)); char *wstrtrunc(uint16_t *) memcpyesque; char *wstrntrunc(uint16_t *, size_t) memcpyesque; bool _startswith(const char *, const char *) strlenesque; bool _startswithi(const char *, const char *) strlenesque; bool _startswith16(const char16_t *, const char16_t *) strlenesque; bool _wcsstartswith(const wchar_t *, const wchar_t *) strlenesque; bool _endswith(const char *, const char *) strlenesque; bool _endswith16(const char16_t *, const char16_t *) strlenesque; bool _wcsendswith(const wchar_t *, const wchar_t *) strlenesque; const char *IndexDoubleNulString(const char *, unsigned) strlenesque; int strverscmp(const char *, const char *); wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque; char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque; wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque; wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque; wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque; void *tinymemccpy(void *, const void *, int, size_t) memcpyesque; void *memmem(const void *, size_t, const void *, size_t) libcesque nosideeffect; ssize_t strfmon(char *, size_t, const char *, ...); long a64l(const char *); char *l64a(long); char *strntolower(char *, size_t) libcesque; char *strtolower(char *) libcesque paramsnonnull(); char *strntoupper(char *, size_t) libcesque; char *strtoupper(char *) libcesque paramsnonnull(); char *_chomp(char *) libcesque; char16_t *_chomp16(char16_t *) libcesque; wchar_t *_wchomp(wchar_t *) libcesque; bool _istext(const void *, size_t) libcesque; bool _isutf8(const void *, size_t) libcesque; bool _escapedos(char16_t *, unsigned, const char16_t *, unsigned) libcesque; typedef unsigned mbstate_t; axdx_t tprecode8to16(char16_t *, size_t, const char *); axdx_t tprecode16to8(char *, size_t, const char16_t *); wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t); int mbtowc(wchar_t *, const char *, size_t); size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *); size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *); size_t mbstowcs(wchar_t *, const char *, size_t); size_t wcrtomb(char *, wchar_t, mbstate_t *); size_t c32rtomb(char *, char32_t, mbstate_t *); size_t mbrtoc32(char32_t *, const char *, size_t, mbstate_t *); size_t c16rtomb(char *, char16_t, mbstate_t *); size_t mbrtoc16(char16_t *, const char *, size_t, mbstate_t *); size_t mbrlen(const char *, size_t, mbstate_t *); size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *); size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *); size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *); size_t wcstombs(char *, const wchar_t *, size_t); int mbsinit(const mbstate_t *); int mblen(const char *, size_t); int wctomb(char *, wchar_t); int wctob(wint_t); wint_t btowc(int); typedef unsigned wctype_t; wctype_t wctype(const char *) strlenesque; int iswctype(wint_t, wctype_t) pureconst; typedef const int *wctrans_t; wctrans_t wctrans(const char *); wint_t towctrans(wint_t, wctrans_t); char *strsignal(int) returnsnonnull libcesque; char *strsignal_r(int, char[hasatleast 15]) returnsnonnull libcesque; char *strerror(int) returnsnonnull dontthrow nocallback; int strerror_r(int, char *, size_t) dontthrow nocallback; int strerror_wr(int, uint32_t, char *, size_t) dontthrow nocallback; char *_strerrno(int) nosideeffect libcesque; char *_strerdoc(int) nosideeffect libcesque; int __xpg_strerror_r(int, char *, size_t) dontthrow nocallback; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_STR_H_ */
9,688
221
jart/cosmopolitan
false
cosmopolitan/libc/str/index.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns pointer to first instance of character, the BSD way. * * @param s is a NUL-terminated string * @param is masked with 255 as byte to search for * @return is pointer to first instance of c or NULL if not found, * noting that c being NUL will return a pointer to terminator */ char *index(const char *s, int c) { return strchr(s, c); }
2,223
32
jart/cosmopolitan
false
cosmopolitan/libc/str/locale.h
#ifndef COSMOPOLITAN_LIBC_STR_LOCALE_H_ #define COSMOPOLITAN_LIBC_STR_LOCALE_H_ #include "libc/fmt/conv.h" #include "libc/time/struct/tm.h" #define LC_CTYPE 0 #define LC_NUMERIC 1 #define LC_CTYPE_MASK 1 #define LC_TIME 2 #define LC_NUMERIC_MASK 2 #define LC_COLLATE 3 #define LC_MONETARY 4 #define LC_TIME_MASK 4 #define LC_MESSAGES 5 #define LC_ALL 6 #define LC_COLLATE_MASK 8 #define LC_MONETARY_MASK 16 #define LC_MESSAGES_MASK 32 #define LC_ALL_MASK 0x1fbf #define LOCALE_NAME_MAX 23 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #define LC_GLOBAL_LOCALE ((locale_t)-1) struct __locale_map { const void *map; size_t map_size; char name[LOCALE_NAME_MAX + 1]; const struct __locale_map *next; }; struct __locale_struct { const struct __locale_map *cat[6]; }; typedef struct __locale_struct *locale_t; char *nl_langinfo_l(int, locale_t); char *setlocale(int, const char *); double strtod_l(const char *, char **, locale_t); double wcstod_l(const wchar_t *, wchar_t **, locale_t); float strtof_l(const char *, char **, locale_t); float wcstof_l(const wchar_t *, wchar_t **, locale_t); int isdigit_l(int, locale_t); int islower_l(int, locale_t); int isupper_l(int, locale_t); int iswalpha_l(wint_t, locale_t); int iswblank_l(wint_t, locale_t); int iswcntrl_l(wint_t, locale_t); int iswdigit_l(wint_t, locale_t); int iswlower_l(wint_t, locale_t); int iswprint_l(wint_t, locale_t); int iswpunct_l(wint_t, locale_t); int iswspace_l(wint_t, locale_t); int iswupper_l(wint_t, locale_t); int iswxdigit_l(wint_t, locale_t); int isxdigit_l(int, locale_t); int strcoll_l(const char *, const char *, locale_t); int tolower_l(int, locale_t); int toupper_l(int, locale_t); int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); locale_t duplocale(locale_t); locale_t newlocale(int, const char *, locale_t); locale_t uselocale(locale_t); long double strtold_l(const char *, char **, locale_t); long double wcstold_l(const wchar_t *, wchar_t **, locale_t); long long strtoll_l(const char *, char **, int, locale_t); long long wcstoll_l(const wchar_t *, wchar_t **, int, locale_t); size_t strftime_l(char *, size_t, char const *, struct tm const *, locale_t); size_t strxfrm_l(char *, const char *, size_t, locale_t); size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t); unsigned long long strtoull_l(const char *, char **, int, locale_t); unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t); void freelocale(locale_t); wint_t towlower_l(wint_t, locale_t); wint_t towupper_l(wint_t, locale_t); int strcasecmp_l(const char *, const char *, locale_t); int strncasecmp_l(const char *, const char *, size_t, locale_t); ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_LOCALE_H_ */
2,909
86
jart/cosmopolitan
false
cosmopolitan/libc/str/isdigit.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is decimal digit. */ int isdigit(int c) { return '0' <= c && c <= '9'; }
1,967
27
jart/cosmopolitan
false
cosmopolitan/libc/str/memrchr16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/str.h" typedef char16_t xmm_t __attribute__((__vector_size__(16), __aligned__(2))); static inline const char16_t *memrchr16_pure(const char16_t *s, char16_t c, size_t n) { size_t i; for (i = n; i--;) { if (s[i] == c) { return s + i; } } return 0; } #ifdef __x86_64__ noasan static inline const char16_t *memrchr16_sse(const char16_t *s, char16_t c, size_t n) { size_t i; unsigned k, m; xmm_t v, t = {c, c, c, c, c, c, c, c}; for (i = n; i >= 8;) { v = *(const xmm_t *)(s + (i -= 8)); m = __builtin_ia32_pmovmskb128(v == t); if (m) { m = __builtin_clzl(m) ^ (sizeof(long) * CHAR_BIT - 1); return s + i + m / 2; } } while (i--) { if (s[i] == c) { return s + i; } } return 0; } #endif /** * Returns pointer to first instance of character. * * @param s is memory to search * @param c is search byte which is masked with 65535 * @param n is number of char16_t elements in `s` * @return is pointer to first instance of c or NULL if not found * @asyncsignalsafe */ void *memrchr16(const void *s, int c, size_t n) { #ifdef __x86_64__ const void *r; if (!IsTiny() && X86_HAVE(SSE)) { if (IsAsan()) __asan_verify(s, n * 2); r = memrchr16_sse(s, c, n); } else { r = memrchr16_pure(s, c, n); } return (void *)r; #else return memrchr16_pure(s, c, n); #endif }
3,414
83
jart/cosmopolitan
false
cosmopolitan/libc/str/isblank.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is space or tab. */ int isblank(int c) { return c == ' ' || c == '\t'; }
1,967
27
jart/cosmopolitan
false
cosmopolitan/libc/str/windowsdurationtotimeval.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/conv.h" struct timeval WindowsDurationToTimeVal(int64_t x) { return (struct timeval){x / HECTONANOSECONDS, x % HECTONANOSECONDS / 10}; }
1,995
24
jart/cosmopolitan
false
cosmopolitan/libc/str/iswspace.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is space character. * * We define this as invisible characters which move the cursor. That * means `\t\r\n\f\v` and unicodes whose category begins with `Z` but * not ogham since it's not invisible and non-breaking spaces neither * since they're not invisible to emacs users. */ int iswspace(wint_t c) { switch (c) { case '\t': // CHARACTER TABULATION case '\n': // LINE FEED case '\f': // FORM FEED case '\v': // LINE TABULATION case '\r': // CARRIAGE RETURN case ' ': // SPACE case 0x2000: // EN QUAD (Zs) case 0x2001: // EM QUAD (Zs) case 0x2002: // EN SPACE (Zs) case 0x2003: // EM SPACE (Zs) case 0x2004: // THREE-PER-EM SPACE (Zs) case 0x2005: // FOUR-PER-EM SPACE (Zs) case 0x2006: // SIX-PER-EM SPACE (Zs) case 0x2007: // FIGURE SPACE (Zs) case 0x2008: // PUNCTUATION SPACE (Zs) case 0x2009: // THIN SPACE (Zs) case 0x200a: // HAIR SPACE (Zs) case 0x2028: // LINE SEPARATOR (Zl) case 0x2029: // PARAGRAPH SEPARATOR (Zp) case 0x205f: // MEDIUM MATHEMATICAL SPACE (Zs) case 0x3000: // IDEOGRAPHIC SPACE (Zs) return 1; default: return 0; } }
3,081
57
jart/cosmopolitan
false
cosmopolitan/libc/str/wmemcpy.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count) { size_t bytes; if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1; return memcpy(dest, src, bytes); }
2,058
26
jart/cosmopolitan
false
cosmopolitan/libc/str/wcsncmp.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Compares NUL-terminated wide strings w/ limit. * * @param a is first non-null NUL-terminated string pointer * @param b is second non-null NUL-terminated string pointer * @return is <0, 0, or >0 based on uint8_t comparison * @asyncsignalsafe */ int wcsncmp(const wchar_t *a, const wchar_t *b, size_t n) { size_t i = 0; if (!n-- || a == b) return 0; while (i < n && a[i] == b[i] && b[i]) ++i; return (int)a[i] < (int)b[i] ? -1 : (int)a[i] > (int)b[i]; }
2,336
35
jart/cosmopolitan
false
cosmopolitan/libc/str/strtok.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Extracts non-empty tokens from string. * * @param s is mutated and should be NULL on subsequent calls * @param sep is a NUL-terminated set of bytes to consider separators * @return pointer to next token or NULL for end * @see strtok_r() and strsep() for superior functions * @notasyncsignalsafe */ char *strtok(char *s, const char *sep) { static char *state; return strtok_r(s, sep, &state); }
2,275
34
jart/cosmopolitan
false
cosmopolitan/libc/str/towlower_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" wint_t towlower_l(wint_t c, locale_t l) { return towlower(c); }
1,958
25
jart/cosmopolitan
false
cosmopolitan/libc/str/mb.internal.h
#ifndef COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_ #define COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #define SA 0xc2u #define SB 0xf4u #define CODEUNIT(c) (0xdfff & (signed char)(c)) #define IS_CODEUNIT(c) ((unsigned)(c)-0xdf80 < 0x80) #define R(a, b) ((uint32_t)((a == 0x80 ? 0x40u - b : 0u - a) << 23)) #define FAILSTATE R(0x80, 0x80) #define OOB(c, b) \ (((((b) >> 3) - 0x10) | (((b) >> 3) + ((int32_t)(c) >> 26))) & ~7) extern const uint32_t kMbBittab[51]; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_ */
671
20
jart/cosmopolitan
false
cosmopolitan/libc/str/iswupper.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is uppercase letter. */ int iswupper(wint_t c) { int r; if (c < 0200) { return 'A' <= c && c <= 'Z'; } else { if (towlower(c) != c) return 1; switch (c) { case 0x03d2: /* ϒ Greek */ case 0x03d3: /* ϓ Greek */ case 0x03d4: /* ϔ Greek */ case 0x2102: /* ℂ Letterlike */ case 0x2107: /* ℇ Letterlike */ case 0x210b: /* ℋ Letterlike */ case 0x210c: /* ℌ Letterlike */ case 0x210d: /* ℍ Letterlike */ case 0x2110: /* ℐ Letterlike */ case 0x2111: /* ℑ Letterlike */ case 0x2112: /* ℒ Letterlike */ case 0x2115: /* ℕ Letterlike */ case 0x2119: /* ℙ Letterlike */ case 0x211a: /* ℚ Letterlike */ case 0x211b: /* ℛ Letterlike */ case 0x211c: /* ℜ Letterlike */ case 0x211d: /* ℝ Letterlike */ case 0x2124: /* ℤ Letterlike */ case 0x2128: /* ℨ Letterlike */ case 0x212c: /* ℬ Letterlike */ case 0x212d: /* ℭ Letterlike */ case 0x2130: /* ℰ Letterlike */ case 0x2131: /* ℱ Letterlike */ case 0x2133: /* ℳ Letterlike */ case 0x213e: /* ℾ Letterlike */ case 0x213f: /* ℿ Letterlike */ case 0x2145: /* ⅅ Letterlike */ case 0x1d434: /* 𝐴 Math */ case 0x1d435: /* 𝐵 Math */ case 0x1d436: /* 𝐶 Math */ case 0x1d437: /* 𝐷 Math */ case 0x1d438: /* 𝐸 Math */ case 0x1d439: /* 𝐹 Math */ case 0x1d43a: /* 𝐺 Math */ case 0x1d43b: /* 𝐻 Math */ case 0x1d49c: /* 𝒜 Math */ case 0x1d49e: /* 𝒞 Math */ case 0x1d49f: /* 𝒟 Math */ case 0x1d4a2: /* 𝒢 Math */ case 0x1d4a5: /* 𝒥 Math */ case 0x1d4a6: /* 𝒦 Math */ case 0x1d4a9: /* 𝒩 Math */ case 0x1d4aa: /* 𝒪 Math */ case 0x1d4ab: /* 𝒫 Math */ case 0x1d4ac: /* 𝒬 Math */ case 0x1d504: /* 𝔄 Math */ case 0x1d505: /* 𝔅 Math */ case 0x1d507: /* 𝔇 Math */ case 0x1d508: /* 𝔈 Math */ case 0x1d509: /* 𝔉 Math */ case 0x1d50a: /* 𝔊 Math */ case 0x1d516: /* 𝔖 Math */ case 0x1d517: /* 𝔗 Math */ case 0x1d518: /* 𝔘 Math */ case 0x1d519: /* 𝔙 Math */ case 0x1d51a: /* 𝔚 Math */ case 0x1d51b: /* 𝔛 Math */ case 0x1d51c: /* 𝔜 Math */ case 0x1d538: /* 𝔸 Math */ case 0x1d539: /* 𝔹 Math */ case 0x1d53b: /* 𝔻 Math */ case 0x1d53c: /* 𝔼 Math */ case 0x1d53d: /* 𝔽 Math */ case 0x1d53e: /* 𝔾 Math */ case 0x1d540: /* 𝕀 Math */ case 0x1d541: /* 𝕁 Math */ case 0x1d542: /* 𝕂 Math */ case 0x1d543: /* 𝕃 Math */ case 0x1d544: /* 𝕄 Math */ case 0x1d546: /* 𝕆 Math */ case 0x1d54a: /* 𝕊 Math */ case 0x1d54b: /* 𝕋 Math */ case 0x1d54c: /* 𝕌 Math */ case 0x1d54d: /* 𝕍 Math */ case 0x1d54e: /* 𝕎 Math */ case 0x1d54f: /* 𝕏 Math */ case 0x1d550: /* 𝕐 Math */ case 0x1d6e3: /* 𝛣 Math */ case 0x1d6e4: /* 𝛤 Math */ case 0x1d6e5: /* 𝛥 Math */ case 0x1d6e6: /* 𝛦 Math */ case 0x1d6e7: /* 𝛧 Math */ case 0x1d6e8: /* 𝛨 Math */ case 0x1d6e9: /* 𝛩 Math */ case 0x1d6ea: /* 𝛪 Math */ case 0x1d6eb: /* 𝛫 Math */ case 0x1d6ec: /* 𝛬 Math */ case 0x1d6ed: /* 𝛭 Math */ case 0x1d6ee: /* 𝛮 Math */ case 0x1d6ef: /* 𝛯 Math */ case 0x1d6f0: /* 𝛰 Math */ case 0x1d6f1: /* 𝛱 Math */ case 0x1d6f2: /* 𝛲 Math */ case 0x1d6f3: /* 𝛳 Math */ case 0x1d6f4: /* 𝛴 Math */ case 0x1d6f5: /* 𝛵 Math */ case 0x1d6f6: /* 𝛶 Math */ case 0x1d6f7: /* 𝛷 Math */ case 0x1d6f8: /* 𝛸 Math */ case 0x1d6f9: /* 𝛹 Math */ case 0x1d6fa: /* 𝛺 Math */ case 0x1d72d: /* 𝜭 Math */ case 0x1d72e: /* 𝜮 Math */ case 0x1d72f: /* 𝜯 Math */ case 0x1d730: /* 𝜰 Math */ case 0x1d731: /* 𝜱 Math */ case 0x1d732: /* 𝜲 Math */ case 0x1d733: /* 𝜳 Math */ case 0x1d734: /* 𝜴 Math */ case 0x1d767: /* 𝝧 Math */ case 0x1d768: /* 𝝨 Math */ case 0x1d769: /* 𝝩 Math */ case 0x1d76a: /* 𝝪 Math */ case 0x1d76b: /* 𝝫 Math */ case 0x1d76c: /* 𝝬 Math */ case 0x1d76d: /* 𝝭 Math */ case 0x1d76e: /* 𝝮 Math */ case 0x1d7a1: /* 𝞡 Math */ case 0x1d7a2: /* 𝞢 Math */ case 0x1d7a3: /* 𝞣 Math */ case 0x1d7a4: /* 𝞤 Math */ case 0x1d7a5: /* 𝞥 Math */ case 0x1d7a6: /* 𝞦 Math */ case 0x1d7a7: /* 𝞧 Math */ case 0x1d7a8: /* 𝞨 Math */ case 0x1d7ca: /* 𝟊 Math */ return 1; default: return 0; } } }
6,781
163
jart/cosmopolitan
false
cosmopolitan/libc/str/unicode-properties.txt
Lu = Letter, uppercase Ll = Letter, lowercase Lt = Letter, titlecase Lm = Letter, modifier Lo = Letter, other Mn = Mark, nonspacing Mc = Mark, spacing combining Me = Mark, enclosing Nd = Number, decimal digit Nl = Number, letter No = Number, other Pc = Punctuation, connector Pd = Punctuation, dash Ps = Punctuation, open Pe = Punctuation, close Pi = Punctuation, initial quote (may behave like Ps or Pe depending on usage) Pf = Punctuation, final quote (may behave like Ps or Pe depending on usage) Po = Punctuation, other Sm = Symbol, math Sc = Symbol, currency Sk = Symbol, modifier So = Symbol, other Zs = Separator, space Zl = Separator, line Zp = Separator, paragraph Cc = Other, control Cf = Other, format Cs = Other, surrogate Co = Other, private use Cn = Other, not assigned (including noncharacters) W Wide Naturally wide character, e.g. Hiragana. Na Narrow Naturally narrow character, e.g. ISO Basic Latin alphabet. F Fullwidth Wide variant with compatibility normalisation to naturally narrow character, e.g. fullwidth Latin script. H Halfwidth Narrow variant with compatibility normalisation to naturally wide character, e.g. half-width kana. Includes U+20A9 (₩) as an exception. A Ambiguous Characters included in East Asian DBCS codes but also in European SBCS codes, e.g. Greek alphabet. Duospaced behaviour can consequently vary. N Neutral Characters which do not appear in East Asian DBCS codes, e.g. Devanagari.
1,449
38
jart/cosmopolitan
false
cosmopolitan/libc/str/strpbrk16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** * Returns pointer to first byte matching any in accept, or NULL. * @asyncsignalsafe */ char16_t *strpbrk16(const char16_t *s, const char16_t *accept) { size_t i; if (accept[0]) { if (!accept[1]) { return strchr16(s, accept[0]); } else { for (i = 0; s[i]; ++i) { if (HasCharacter16(s[i], accept)) { return (/*unconst*/ char16_t *)&s[i]; } } } } return NULL; }
2,343
41
jart/cosmopolitan
false
cosmopolitan/libc/str/memset16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Sets wide memory. * @asyncsignalsafe */ char16_t *memset16(char16_t *p, char16_t c, size_t n) { size_t i; for (i = 0; i < n; ++i) { p[i] = c; } return p; }
2,040
32
jart/cosmopolitan
false
cosmopolitan/libc/str/iswpunct.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is punctuation mark. */ int iswpunct(wint_t c) { if (c < 0xa0) { switch (c) { case '!': case '"': case '#': case '$': case '%': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case '-': case '.': case '/': case ':': case ';': case '<': case '=': case '>': case '?': case '@': case '[': case '\\': case ']': case '^': case '_': case '`': case '{': case '|': case '}': case '~': return 1; default: return 0; } } switch (c) { case u'¡': // INVERTED EXCLAMATION MARK (0x00a1 Po) case u'§': // SECTION SIGN (0x00a7 Po) case u'«': // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (0x00ab Pi) case u'¶': // PILCROW SIGN (0x00b6 Po) case u'·': // MIDDLE DOT (0x00b7 Po) case u'»': // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (0x00bb Pf) case u'¿': // INVERTED QUESTION MARK (0x00bf Po) case u';': // GREEK QUESTION MARK (0x037e Po) case u'·': // GREEK ANO TELEIA (0x0387 Po) case u'՚': // ARMENIAN APOSTROPHE (0x055a Po) case u'՛': // ARMENIAN EMPHASIS MARK (0x055b Po) case u'՜': // ARMENIAN EXCLAMATION MARK (0x055c Po) case u'՝': // ARMENIAN COMMA (0x055d Po) case u'՞': // ARMENIAN QUESTION MARK (0x055e Po) case u'՟': // ARMENIAN ABBREVIATION MARK (0x055f Po) case u'։': // ARMENIAN FULL STOP (0x0589 Po) case u'֊': // ARMENIAN HYPHEN (0x058a Pd) case 0x05be: // HEBREW PUNCTUATION MAQAF (0x05be Pd) case 0x05c0: // HEBREW PUNCTUATION PASEQ (0x05c0 Po) case 0x05c3: // HEBREW PUNCTUATION SOF PASUQ (0x05c3 Po) case 0x05c6: // HEBREW PUNCTUATION NUN HAFUKHA (0x05c6 Po) case 0x05f3: // HEBREW PUNCTUATION GERESH (0x05f3 Po) case 0x05f4: // HEBREW PUNCTUATION GERSHAYIM (0x05f4 Po) case 0x0609: // ARABIC-INDIC PER MILLE SIGN (0x0609 Po) case 0x060a: // ARABIC-INDIC PER TEN THOUSAND SIGN (0x060a Po) case 0x060c: // ARABIC COMMA (0x060c Po) case 0x060d: // ARABIC DATE SEPARATOR (0x060d Po) case 0x061b: // ARABIC SEMICOLON (0x061b Po) case u'؞': // ARABIC TRIPLE DOT PUNCTUATION MARK (0x061e Po) case u'؟': // ARABIC QUESTION MARK (0x061f Po) case u'٪': // ARABIC PERCENT SIGN (0x066a Po) case u'٫': // ARABIC DECIMAL SEPARATOR (0x066b Po) case u'٬': // ARABIC THOUSANDS SEPARATOR (0x066c Po) case u'٭': // ARABIC FIVE POINTED STAR (0x066d Po) case u'۔': // ARABIC FULL STOP (0x06d4 Po) case u'߷': // NKO SYMBOL GBAKURUNEN (0x07f7 Po) case u'߸': // NKO COMMA (0x07f8 Po) case u'߹': // NKO EXCLAMATION MARK (0x07f9 Po) case u'।': // DEVANAGARI DANDA (0x0964 Po) case u'॥': // DEVANAGARI DOUBLE DANDA (0x0965 Po) case u'॰': // DEVANAGARI ABBREVIATION SIGN (0x0970 Po) case 0x09fd: // BENGALI ABBREVIATION SIGN (0x09fd Po) case 0x0a76: // GURMUKHI ABBREVIATION SIGN (0x0a76 Po) case 0x0af0: // GUJARATI ABBREVIATION SIGN (0x0af0 Po) case 0x0c77: // TELUGU SIGN SIDDHAM (0x0c77 Po) case 0x0c84: // KANNADA SIGN SIDDHAM (0x0c84 Po) case u'෴': // SINHALA PUNCTUATION KUNDDALIYA (0x0df4 Po) case u'๏': // THAI CHARACTER FONGMAN (0x0e4f Po) case u'๚': // THAI CHARACTER ANGKHANKHU (0x0e5a Po) case u'๛': // THAI CHARACTER KHOMUT (0x0e5b Po) case u'༄': // TIBETAN MARK INITIAL YIG MGO MDUN MA (0x0f04 Po) case u'༅': // TIBETAN MARK CLOSING YIG MGO SGAB MA (0x0f05 Po) case u'༆': // TIBETAN MARK CARET YIG MGO PHUR SHAD MA (0x0f06 Po) case u'༇': // TIBETAN MARK YIG MGO TSHEG SHAD MA (0x0f07 Po) case u'༈': // TIBETAN MARK SBRUL SHAD (0x0f08 Po) case u'༉': // TIBETAN MARK BSKUR YIG MGO (0x0f09 Po) case u'༊': // TIBETAN MARK BKA- SHOG YIG MGO (0x0f0a Po) case u'་': // TIBETAN MARK INTERSYLLABIC TSHEG (0x0f0b Po) case u'༌': // TIBETAN MARK DELIMITER TSHEG BSTAR (0x0f0c Po) case u'།': // TIBETAN MARK SHAD (0x0f0d Po) case u'༎': // TIBETAN MARK NYIS SHAD (0x0f0e Po) case u'༏': // TIBETAN MARK TSHEG SHAD (0x0f0f Po) case u'༐': // TIBETAN MARK NYIS TSHEG SHAD (0x0f10 Po) case u'༑': // TIBETAN MARK RIN CHEN SPUNGS SHAD (0x0f11 Po) case u'༒': // TIBETAN MARK RGYA GRAM SHAD (0x0f12 Po) case u'༔': // TIBETAN MARK GTER TSHEG (0x0f14 Po) case u'༺': // TIBETAN MARK GUG RTAGS GYON (0x0f3a Ps) case u'༻': // TIBETAN MARK GUG RTAGS GYAS (0x0f3b Pe) case u'༼': // TIBETAN MARK ANG KHANG GYON (0x0f3c Ps) case u'༽': // TIBETAN MARK ANG KHANG GYAS (0x0f3d Pe) case u'྅': // TIBETAN MARK PALUTA (0x0f85 Po) case u'࿐': // TIBETAN MARK BSKA- SHOG GI MGO RGYAN (0x0fd0 Po) case u'࿑': // TIBETAN MARK MNYAM YIG GI MGO RGYAN (0x0fd1 Po) case u'࿒': // TIBETAN MARK NYIS TSHEG (0x0fd2 Po) case u'࿓': // TIBETAN MARK INITIAL BRDA RNYING YIG MGO MDUN MA (0x0fd3 Po) case u'࿔': // TIBETAN MARK CLOSING BRDA RNYING YIG MGO SGAB MA (0x0fd4 Po) case u'࿙': // TIBETAN MARK LEADING MCHAN RTAGS (0x0fd9 Po) case u'࿚': // TIBETAN MARK TRAILING MCHAN RTAGS (0x0fda Po) case u'၊': // MYANMAR SIGN LITTLE SECTION (0x104a Po) case u'။': // MYANMAR SIGN SECTION (0x104b Po) case u'၌': // MYANMAR SYMBOL LOCATIVE (0x104c Po) case u'၍': // MYANMAR SYMBOL COMPLETED (0x104d Po) case u'၎': // MYANMAR SYMBOL AFOREMENTIONED (0x104e Po) case u'၏': // MYANMAR SYMBOL GENITIVE (0x104f Po) case u'჻': // GEORGIAN PARAGRAPH SEPARATOR (0x10fb Po) case u'፠': // ETHIOPIC SECTION MARK (0x1360 Po) case u'፡': // ETHIOPIC WORDSPACE (0x1361 Po) case u'።': // ETHIOPIC FULL STOP (0x1362 Po) case u'፣': // ETHIOPIC COMMA (0x1363 Po) case u'፤': // ETHIOPIC SEMICOLON (0x1364 Po) case u'፥': // ETHIOPIC COLON (0x1365 Po) case u'፦': // ETHIOPIC PREFACE COLON (0x1366 Po) case u'፧': // ETHIOPIC QUESTION MARK (0x1367 Po) case u'፨': // ETHIOPIC PARAGRAPH SEPARATOR (0x1368 Po) case u'᐀': // CANADIAN SYLLABICS HYPHEN (0x1400 Pd) case u'᙮': // CANADIAN SYLLABICS FULL STOP (0x166e Po) case u'᚛': // OGHAM FEATHER MARK (0x169b Ps) case u'᚜': // OGHAM REVERSED FEATHER MARK (0x169c Pe) case u'᛫': // RUNIC SINGLE PUNCTUATION (0x16eb Po) case u'᛬': // RUNIC MULTIPLE PUNCTUATION (0x16ec Po) case u'᛭': // RUNIC CROSS PUNCTUATION (0x16ed Po) case u'᜵': // PHILIPPINE SINGLE PUNCTUATION (0x1735 Po) case u'᜶': // PHILIPPINE DOUBLE PUNCTUATION (0x1736 Po) case u'។': // KHMER SIGN KHAN (0x17d4 Po) case u'៕': // KHMER SIGN BARIYOOSAN (0x17d5 Po) case u'៖': // KHMER SIGN CAMNUC PII KUUH (0x17d6 Po) case u'៘': // KHMER SIGN BEYYAL (0x17d8 Po) case u'៙': // KHMER SIGN PHNAEK MUAN (0x17d9 Po) case u'៚': // KHMER SIGN KOOMUUT (0x17da Po) case u'᠀': // MONGOLIAN BIRGA (0x1800 Po) case u'᠁': // MONGOLIAN ELLIPSIS (0x1801 Po) case u'᠂': // MONGOLIAN COMMA (0x1802 Po) case u'᠃': // MONGOLIAN FULL STOP (0x1803 Po) case u'᠄': // MONGOLIAN COLON (0x1804 Po) case u'᠅': // MONGOLIAN FOUR DOTS (0x1805 Po) case u'᠆': // MONGOLIAN TODO SOFT HYPHEN (0x1806 Pd) case u'᠇': // MONGOLIAN SIBE SYLLABLE BOUNDARY MARKER (0x1807 Po) case u'᠈': // MONGOLIAN MANCHU COMMA (0x1808 Po) case u'᠉': // MONGOLIAN MANCHU FULL STOP (0x1809 Po) case u'᠊': // MONGOLIAN NIRUGU (0x180a Po) case u'᥄': // LIMBU EXCLAMATION MARK (0x1944 Po) case u'᥅': // LIMBU QUESTION MARK (0x1945 Po) case u'᨞': // BUGINESE PALLAWA (0x1a1e Po) case u'᨟': // BUGINESE END OF SECTION (0x1a1f Po) case u'᱾': // OL CHIKI PUNCTUATION MUCAAD (0x1c7e Po) case u'᱿': // OL CHIKI PUNCTUATION DOUBLE MUCAAD (0x1c7f Po) case u'‐': // HYPHEN (0x2010 Pd) case u'‑': // NON-BREAKING HYPHEN (0x2011 Pd) case u'‒': // FIGURE DASH (0x2012 Pd) case u'–': // EN DASH (0x2013 Pd) case u'—': // EM DASH (0x2014 Pd) case u'―': // HORIZONTAL BAR (0x2015 Pd) case u'‖': // DOUBLE VERTICAL LINE (0x2016 Po) case u'‗': // DOUBLE LOW LINE (0x2017 Po) case u'‘': // LEFT SINGLE QUOTATION MARK (0x2018 Pi) case u'’': // RIGHT SINGLE QUOTATION MARK (0x2019 Pf) case u'‚': // SINGLE LOW-9 QUOTATION MARK (0x201a Ps) case u'‛': // SINGLE HIGH-REVERSED-9 QUOTATION MARK (0x201b Pi) case u'“': // LEFT DOUBLE QUOTATION MARK (0x201c Pi) case u'”': // RIGHT DOUBLE QUOTATION MARK (0x201d Pf) case u'„': // DOUBLE LOW-9 QUOTATION MARK (0x201e Ps) case u'‟': // DOUBLE HIGH-REVERSED-9 QUOTATION MARK (0x201f Pi) case u'†': // DAGGER (0x2020 Po) case u'‡': // DOUBLE DAGGER (0x2021 Po) case u'•': // BULLET (0x2022 Po) case u'‣': // TRIANGULAR BULLET (0x2023 Po) case u'․': // ONE DOT LEADER (0x2024 Po) case u'‥': // TWO DOT LEADER (0x2025 Po) case u'…': // HORIZONTAL ELLIPSIS (0x2026 Po) case u'‧': // HYPHENATION POINT (0x2027 Po) case u'‰': // PER MILLE SIGN (0x2030 Po) case u'‱': // PER TEN THOUSAND SIGN (0x2031 Po) case u'′': // PRIME (0x2032 Po) case u'″': // DOUBLE PRIME (0x2033 Po) case u'‴': // TRIPLE PRIME (0x2034 Po) case u'‵': // REVERSED PRIME (0x2035 Po) case u'‶': // REVERSED DOUBLE PRIME (0x2036 Po) case u'‷': // REVERSED TRIPLE PRIME (0x2037 Po) case u'‸': // CARET (0x2038 Po) case u'‹': // SINGLE LEFT-POINTING ANGLE QUOTATION MARK (0x2039 Pi) case u'›': // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (0x203a Pf) case u'※': // REFERENCE MARK (0x203b Po) case u'‼': // DOUBLE EXCLAMATION MARK (0x203c Po) case u'‽': // INTERROBANG (0x203d Po) case u'‾': // OVERLINE (0x203e Po) case u'‿': // UNDERTIE (0x203f Pc) case u'⁀': // CHARACTER TIE (0x2040 Pc) case u'⁁': // CARET INSERTION POINT (0x2041 Po) case u'⁂': // ASTERISM (0x2042 Po) case u'⁃': // HYPHEN BULLET (0x2043 Po) case u'⁅': // LEFT SQUARE BRACKET WITH QUILL (0x2045 Ps) case u'⁆': // RIGHT SQUARE BRACKET WITH QUILL (0x2046 Pe) case u'⁇': // DOUBLE QUESTION MARK (0x2047 Po) case u'⁈': // QUESTION EXCLAMATION MARK (0x2048 Po) case u'⁉': // EXCLAMATION QUESTION MARK (0x2049 Po) case u'⁊': // TIRONIAN SIGN ET (0x204a Po) case u'⁋': // REVERSED PILCROW SIGN (0x204b Po) case u'⁌': // BLACK LEFTWARDS BULLET (0x204c Po) case u'⁍': // BLACK RIGHTWARDS BULLET (0x204d Po) case u'⁎': // LOW ASTERISK (0x204e Po) case u'⁏': // REVERSED SEMICOLON (0x204f Po) case u'⁐': // CLOSE UP (0x2050 Po) case u'⁑': // TWO ASTERISKS ALIGNED VERTICALLY (0x2051 Po) case u'⁓': // SWUNG DASH (0x2053 Po) case u'⁔': // INVERTED UNDERTIE (0x2054 Pc) case u'⁕': // FLOWER PUNCTUATION MARK (0x2055 Po) case u'⁖': // THREE DOT PUNCTUATION (0x2056 Po) case u'⁗': // QUADRUPLE PRIME (0x2057 Po) case u'⁘': // FOUR DOT PUNCTUATION (0x2058 Po) case u'⁙': // FIVE DOT PUNCTUATION (0x2059 Po) case u'⁚': // TWO DOT PUNCTUATION (0x205a Po) case u'⁛': // FOUR DOT MARK (0x205b Po) case u'⁜': // DOTTED CROSS (0x205c Po) case u'⁝': // TRICOLON (0x205d Po) case u'⁞': // VERTICAL FOUR DOTS (0x205e Po) case u'⁽': // SUPERSCRIPT LEFT PARENTHESIS (0x207d Ps) case u'⁾': // SUPERSCRIPT RIGHT PARENTHESIS (0x207e Pe) case u'₍': // SUBSCRIPT LEFT PARENTHESIS (0x208d Ps) case u'₎': // SUBSCRIPT RIGHT PARENTHESIS (0x208e Pe) case u'⌈': // LEFT CEILING (0x2308 Ps) case u'⌉': // RIGHT CEILING (0x2309 Pe) case u'⌊': // LEFT FLOOR (0x230a Ps) case u'⌋': // RIGHT FLOOR (0x230b Pe) case u'〈': // LEFT-POINTING ANGLE BRACKET (0x2329 Ps) case u'〉': // RIGHT-POINTING ANGLE BRACKET (0x232a Pe) case u'❨': // MEDIUM LEFT PARENTHESIS ORNAMENT (0x2768 Ps) case u'❩': // MEDIUM RIGHT PARENTHESIS ORNAMENT (0x2769 Pe) case u'❪': // MEDIUM FLATTENED LEFT PARENTHESIS ORNAMENT (0x276a Ps) case u'❫': // MEDIUM FLATTENED RIGHT PARENTHESIS ORNAMENT (0x276b Pe) case u'❬': // MEDIUM LEFT-POINTING ANGLE BRACKET ORNAMENT (0x276c Ps) case u'❭': // MEDIUM RIGHT-POINTING ANGLE BRACKET ORNAMENT (0x276d Pe) case u'❮': // HEAVY LEFT-POINTING ANGLE QUOTATION MARK ORNAMENT (0x276e Ps) case u'❯': // HEAVY RIGHT-POINTING ANGLE QUOT MARK ORNAMENT (0x276f Pe) case u'❰': // HEAVY LEFT-POINTING ANGLE BRACKET ORNAMENT (0x2770 Ps) case u'❱': // HEAVY RIGHT-POINTING ANGLE BRACKET ORNAMENT (0x2771 Pe) case u'❲': // LIGHT LEFT TORTOISE SHELL BRACKET ORNAMENT (0x2772 Ps) case u'❳': // LIGHT RIGHT TORTOISE SHELL BRACKET ORNAMENT (0x2773 Pe) case u'❴': // MEDIUM LEFT CURLY BRACKET ORNAMENT (0x2774 Ps) case u'❵': // MEDIUM RIGHT CURLY BRACKET ORNAMENT (0x2775 Pe) case u'⟅': // LEFT S-SHAPED BAG DELIMITER (0x27c5 Ps) case u'⟆': // RIGHT S-SHAPED BAG DELIMITER (0x27c6 Pe) case u'⟦': // MATHEMATICAL LEFT WHITE SQUARE BRACKET (0x27e6 Ps) case u'⟧': // MATHEMATICAL RIGHT WHITE SQUARE BRACKET (0x27e7 Pe) case u'⟨': // MATHEMATICAL LEFT ANGLE BRACKET (0x27e8 Ps) case u'⟩': // MATHEMATICAL RIGHT ANGLE BRACKET (0x27e9 Pe) case u'⟪': // MATHEMATICAL LEFT DOUBLE ANGLE BRACKET (0x27ea Ps) case u'⟫': // MATHEMATICAL RIGHT DOUBLE ANGLE BRACKET (0x27eb Pe) case u'⟬': // MATHEMATICAL LEFT WHITE TORTOISE SHELL BRACKET (0x27ec Ps) case u'⟭': // MATHEMATICAL RIGHT WHITE TORTOISE SHELL BRACKET (0x27ed Pe) case u'⟮': // MATHEMATICAL LEFT FLATTENED PARENTHESIS (0x27ee Ps) case u'⟯': // MATHEMATICAL RIGHT FLATTENED PARENTHESIS (0x27ef Pe) case u'⦃': // LEFT WHITE CURLY BRACKET (0x2983 Ps) case u'⦄': // RIGHT WHITE CURLY BRACKET (0x2984 Pe) case u'⦅': // LEFT WHITE PARENTHESIS (0x2985 Ps) case u'⦆': // RIGHT WHITE PARENTHESIS (0x2986 Pe) case u'⦇': // Z NOTATION LEFT IMAGE BRACKET (0x2987 Ps) case u'⦈': // Z NOTATION RIGHT IMAGE BRACKET (0x2988 Pe) case u'⦉': // Z NOTATION LEFT BINDING BRACKET (0x2989 Ps) case u'⦊': // Z NOTATION RIGHT BINDING BRACKET (0x298a Pe) case u'⦋': // LEFT SQUARE BRACKET WITH UNDERBAR (0x298b Ps) case u'⦌': // RIGHT SQUARE BRACKET WITH UNDERBAR (0x298c Pe) case u'⦍': // LEFT SQUARE BRACKET WITH TICK IN TOP CORNER (0x298d Ps) case u'⦎': // RIGHT SQUARE BRACKET WITH TICK IN BOTTOM CORNER (0x298e Pe) case u'⦏': // LEFT SQUARE BRACKET WITH TICK IN BOTTOM CORNER (0x298f Ps) case u'⦐': // RIGHT SQUARE BRACKET WITH TICK IN TOP CORNER (0x2990 Pe) case u'⦑': // LEFT ANGLE BRACKET WITH DOT (0x2991 Ps) case u'⦒': // RIGHT ANGLE BRACKET WITH DOT (0x2992 Pe) case u'⦓': // LEFT ARC LESS-THAN BRACKET (0x2993 Ps) case u'⦔': // RIGHT ARC GREATER-THAN BRACKET (0x2994 Pe) case u'⦗': // LEFT BLACK TORTOISE SHELL BRACKET (0x2997 Ps) case u'⦘': // RIGHT BLACK TORTOISE SHELL BRACKET (0x2998 Pe) case u'⧘': // LEFT WIGGLY FENCE (0x29d8 Ps) case u'⧙': // RIGHT WIGGLY FENCE (0x29d9 Pe) case u'⧚': // LEFT DOUBLE WIGGLY FENCE (0x29da Ps) case u'⧛': // RIGHT DOUBLE WIGGLY FENCE (0x29db Pe) case u'⧼': // LEFT-POINTING CURVED ANGLE BRACKET (0x29fc Ps) case u'⧽': // RIGHT-POINTING CURVED ANGLE BRACKET (0x29fd Pe) case u'⵰': // TIFINAGH SEPARATOR MARK (0x2d70 Po) case u'⸎': // EDITORIAL CORONIS (0x2e0e Po) case u'⸏': // PARAGRAPHOS (0x2e0f Po) case u'⸐': // FORKED PARAGRAPHOS (0x2e10 Po) case u'⸑': // REVERSED FORKED PARAGRAPHOS (0x2e11 Po) case u'⸒': // HYPODIASTOLE (0x2e12 Po) case u'⸓': // DOTTED OBELOS (0x2e13 Po) case u'⸔': // DOWNWARDS ANCORA (0x2e14 Po) case u'⸕': // UPWARDS ANCORA (0x2e15 Po) case u'⸖': // DOTTED RIGHT-POINTING ANGLE (0x2e16 Po) case u'⸗': // DOUBLE OBLIQUE HYPHEN (0x2e17 Pd) case u'⸙': // PALM BRANCH (0x2e19 Po) case u'⸚': // HYPHEN WITH DIAERESIS (0x2e1a Pd) case u'⸛': // TILDE WITH RING ABOVE (0x2e1b Po) case u'⸞': // TILDE WITH DOT ABOVE (0x2e1e Po) case u'⸟': // TILDE WITH DOT BELOW (0x2e1f Po) case u'⸪': // TWO DOTS OVER ONE DOT PUNCTUATION (0x2e2a Po) case u'⸫': // ONE DOT OVER TWO DOTS PUNCTUATION (0x2e2b Po) case u'⸬': // SQUARED FOUR DOT PUNCTUATION (0x2e2c Po) case u'⸭': // FIVE DOT MARK (0x2e2d Po) case u'⸮': // REVERSED QUESTION MARK (0x2e2e Po) case u'⸰': // RING POINT (0x2e30 Po) case u'⸱': // WORD SEPARATOR MIDDLE DOT (0x2e31 Po) case u'⸲': // TURNED COMMA (0x2e32 Po) case u'⸳': // RAISED DOT (0x2e33 Po) case u'⸴': // RAISED COMMA (0x2e34 Po) case u'⸵': // TURNED SEMICOLON (0x2e35 Po) case u'⸶': // DAGGER WITH LEFT GUARD (0x2e36 Po) case u'⸷': // DAGGER WITH RIGHT GUARD (0x2e37 Po) case u'⸸': // TURNED DAGGER (0x2e38 Po) case u'⸹': // TOP HALF SECTION SIGN (0x2e39 Po) case u'⸺': // TWO-EM DASH (0x2e3a Pd) case u'⸻': // THREE-EM DASH (0x2e3b Pd) case u'⸼': // STENOGRAPHIC FULL STOP (0x2e3c Po) case u'⸽': // VERTICAL SIX DOTS (0x2e3d Po) case u'⸾': // WIGGLY VERTICAL LINE (0x2e3e Po) case u'⸿': // CAPITULUM (0x2e3f Po) case u'⹀': // DOUBLE HYPHEN (0x2e40 Pd) case u'⹁': // REVERSED COMMA (0x2e41 Po) case u'⹂': // DOUBLE LOW-REVERSED-9 QUOTATION MARK (0x2e42 Ps) case u'⹃': // DASH WITH LEFT UPTURN (0x2e43 Po) case u'⹄': // DOUBLE SUSPENSION MARK (0x2e44 Po) case u'⹅': // INVERTED LOW KAVYKA (0x2e45 Po) case u'⹆': // INVERTED LOW KAVYKA WITH KAVYKA ABOVE (0x2e46 Po) case u'⹇': // LOW KAVYKA (0x2e47 Po) case u'⹈': // LOW KAVYKA WITH DOT (0x2e48 Po) case u'⹉': // DOUBLE STACKED COMMA (0x2e49 Po) case u'⹊': // DOTTED SOLIDUS (0x2e4a Po) case u'⹋': // TRIPLE DAGGER (0x2e4b Po) case u'⹌': // MEDIEVAL COMMA (0x2e4c Po) case u'⹍': // PARAGRAPHUS MARK (0x2e4d Po) case u'⹎': // PUNCTUS ELEVATUS MARK (0x2e4e Po) case u'⹏': // CORNISH VERSE DIVIDER (0x2e4f Po) case u'、': // IDEOGRAPHIC COMMA (0x3001 Po) case u'。': // IDEOGRAPHIC FULL STOP (0x3002 Po) case u'〃': // DITTO MARK (0x3003 Po) case u'〈': // LEFT ANGLE BRACKET (0x3008 Ps) case u'〉': // RIGHT ANGLE BRACKET (0x3009 Pe) case u'《': // LEFT DOUBLE ANGLE BRACKET (0x300a Ps) case u'》': // RIGHT DOUBLE ANGLE BRACKET (0x300b Pe) case u'「': // LEFT CORNER BRACKET (0x300c Ps) case u'」': // RIGHT CORNER BRACKET (0x300d Pe) case u'『': // LEFT WHITE CORNER BRACKET (0x300e Ps) case u'』': // RIGHT WHITE CORNER BRACKET (0x300f Pe) case u'【': // LEFT BLACK LENTICULAR BRACKET (0x3010 Ps) case u'】': // RIGHT BLACK LENTICULAR BRACKET (0x3011 Pe) case u'〔': // LEFT TORTOISE SHELL BRACKET (0x3014 Ps) case u'〕': // RIGHT TORTOISE SHELL BRACKET (0x3015 Pe) case u'〖': // LEFT WHITE LENTICULAR BRACKET (0x3016 Ps) case u'〗': // RIGHT WHITE LENTICULAR BRACKET (0x3017 Pe) case u'〘': // LEFT WHITE TORTOISE SHELL BRACKET (0x3018 Ps) case u'〙': // RIGHT WHITE TORTOISE SHELL BRACKET (0x3019 Pe) case u'〚': // LEFT WHITE SQUARE BRACKET (0x301a Ps) case u'〛': // RIGHT WHITE SQUARE BRACKET (0x301b Pe) case u'〜': // WAVE DASH (0x301c Pd) case u'〝': // REVERSED DOUBLE PRIME QUOTATION MARK (0x301d Ps) case u'〞': // DOUBLE PRIME QUOTATION MARK (0x301e Pe) case u'〟': // LOW DOUBLE PRIME QUOTATION MARK (0x301f Pe) case u'〰': // WAVY DASH (0x3030 Pd) case u'〽': // PART ALTERNATION MARK (0x303d Po) case u'゠': // KATAKANA-HIRAGANA DOUBLE HYPHEN (0x30a0 Pd) case u'・': // KATAKANA MIDDLE DOT (0x30fb Po) case u'꓾': // LISU PUNCTUATION COMMA (0xa4fe Po) case u'꓿': // LISU PUNCTUATION FULL STOP (0xa4ff Po) case u'꘍': // VAI COMMA (0xa60d Po) case u'꘎': // VAI FULL STOP (0xa60e Po) case u'꘏': // VAI QUESTION MARK (0xa60f Po) case u'꙾': // CYRILLIC KAVYKA (0xa67e Po) case u'꡴': // PHAGS-PA SINGLE HEAD MARK (0xa874 Po) case u'꡵': // PHAGS-PA DOUBLE HEAD MARK (0xa875 Po) case u'꡶': // PHAGS-PA MARK SHAD (0xa876 Po) case u'꡷': // PHAGS-PA MARK DOUBLE SHAD (0xa877 Po) case u'꣎': // SAURASHTRA DANDA (0xa8ce Po) case u'꣏': // SAURASHTRA DOUBLE DANDA (0xa8cf Po) case u'꣸': // DEVANAGARI SIGN PUSHPIKA (0xa8f8 Po) case u'꣹': // DEVANAGARI GAP FILLER (0xa8f9 Po) case u'꣺': // DEVANAGARI CARET (0xa8fa Po) case u'꣼': // DEVANAGARI SIGN SIDDHAM (0xa8fc Po) case u'꧁': // JAVANESE LEFT RERENGGAN (0xa9c1 Po) case u'꧂': // JAVANESE RIGHT RERENGGAN (0xa9c2 Po) case u'꧃': // JAVANESE PADA ANDAP (0xa9c3 Po) case u'꧄': // JAVANESE PADA MADYA (0xa9c4 Po) case u'꧅': // JAVANESE PADA LUHUR (0xa9c5 Po) case u'꧆': // JAVANESE PADA WINDU (0xa9c6 Po) case u'꧇': // JAVANESE PADA PANGKAT (0xa9c7 Po) case u'꧈': // JAVANESE PADA LINGSA (0xa9c8 Po) case u'꧉': // JAVANESE PADA LUNGSI (0xa9c9 Po) case u'꧊': // JAVANESE PADA ADEG (0xa9ca Po) case u'꧋': // JAVANESE PADA ADEG ADEG (0xa9cb Po) case u'꧌': // JAVANESE PADA PISELEH (0xa9cc Po) case u'꧍': // JAVANESE TURNED PADA PISELEH (0xa9cd Po) case u'꧞': // JAVANESE PADA TIRTA TUMETES (0xa9de Po) case u'꧟': // JAVANESE PADA ISEN-ISEN (0xa9df Po) case u'꩜': // CHAM PUNCTUATION SPIRAL (0xaa5c Po) case u'꩝': // CHAM PUNCTUATION DANDA (0xaa5d Po) case u'꩞': // CHAM PUNCTUATION DOUBLE DANDA (0xaa5e Po) case u'꩟': // CHAM PUNCTUATION TRIPLE DANDA (0xaa5f Po) case u'꫞': // TAI VIET SYMBOL HO HOI (0xaade Po) case u'꫟': // TAI VIET SYMBOL KOI KOI (0xaadf Po) case u'꫰': // MEETEI MAYEK CHEIKHAN (0xaaf0 Po) case u'꫱': // MEETEI MAYEK AHANG KHUDAM (0xaaf1 Po) case u'꯫': // MEETEI MAYEK CHEIKHEI (0xabeb Po) case u'︐': // PRESENTATION FORM FOR VERTICAL COMMA (0xfe10 Po) case u'︑': // PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC COMMA (0xfe11 Po) case u'︒': // PRESENTATION FORM FOR VERTICAL IDEO FULL STOP (0xfe12 Po) case u'︓': // PRESENTATION FORM FOR VERTICAL COLON (0xfe13 Po) case u'︔': // PRESENTATION FORM FOR VERTICAL SEMICOLON (0xfe14 Po) case u'︕': // PRESENTATION FORM FOR VERTICAL EXCLAMATION MARK (0xfe15 Po) case u'︖': // PRESENTATION FORM FOR VERTICAL QUESTION MARK (0xfe16 Po) case u'︗': // PRESENTATION ... LEFT WHITE LENTICULAR BRACKET (0xfe17 Ps) case u'︘': // PRESENTATION ... RIGHT WHITE LENTICULAR BRAKCET (0xfe18 Pe) case u'︙': // PRESENTATION ... VERTICAL HORIZONTAL ELLIPSIS (0xfe19 Po) case u'︰': // PRESENTATION FORM FOR VERTICAL TWO DOT LEADER (0xfe30 Po) case u'︱': // PRESENTATION FORM FOR VERTICAL EM DASH (0xfe31 Pd) case u'︲': // PRESENTATION FORM FOR VERTICAL EN DASH (0xfe32 Pd) case u'︳': // PRESENTATION FORM FOR VERTICAL LOW LINE (0xfe33 Pc) case u'︴': // PRESENTATION FORM FOR VERTICAL WAVY LOW LINE (0xfe34 Pc) case u'︵': // PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS (0xfe35 Ps) case u'︶': // PRESENTATION FORM FOR VERTICAL RIGHT PARENTHESIS (0xfe36 Pe) case u'︷': // PRESENTATION ... VERTICAL LEFT CURLY BRACKET (0xfe37 Ps) case u'︸': // PRESENTATION ... VERTICAL RIGHT CURLY BRACKET (0xfe38 Pe) case u'︹': // PRESENTATION ... LEFT TORTOISE SHELL BRACKET (0xfe39 Ps) case u'︺': // PRESENTATION ... RIGHT TORTOISE SHELL BRACKET (0xfe3a Pe) case u'︻': // PRESENTATION ... LEFT BLACK LENTICULAR BRACKET (0xfe3b Ps) case u'︼': // PRESENTATION ... RIGHT BLACK LENTICULAR BRACKET (0xfe3c Pe) case u'︽': // PRESENTATION ... LEFT DOUBLE ANGLE BRACKET (0xfe3d Ps) case u'︾': // PRESENTATION ... RIGHT DOUBLE ANGLE BRACKET (0xfe3e Pe) case u'︿': // PRESENTATION ... LEFT ANGLE BRACKET (0xfe3f Ps) case u'﹀': // PRESENTATION ... RIGHT ANGLE BRACKET (0xfe40 Pe) case u'﹁': // PRESENTATION ... LEFT CORNER BRACKET (0xfe41 Ps) case u'﹂': // PRESENTATION ... RIGHT CORNER BRACKET (0xfe42 Pe) case u'﹃': // PRESENTATION ... LEFT WHITE CORNER BRACKET (0xfe43 Ps) case u'﹄': // PRESENTATION ... RIGHT WHITE CORNER BRACKET Pe) case u'﹅': // SESAME DOT (0xfe45 Po) case u'﹆': // WHITE SESAME DOT (0xfe46 Po) case u'﹇': // PRESENTATION ... VERTICAL LEFT SQUARE BRACKET (0xfe47 Ps) case u'﹈': // PRESENTATION ... VERTICAL RIGHT SQUARE BRACKET (0xfe48 Pe) case u'﹉': // DASHED OVERLINE (0xfe49 Po) case u'﹊': // CENTRELINE OVERLINE (0xfe4a Po) case u'﹋': // WAVY OVERLINE (0xfe4b Po) case u'﹌': // DOUBLE WAVY OVERLINE (0xfe4c Po) case u'﹍': // DASHED LOW LINE (0xfe4d Pc) case u'﹎': // CENTRELINE LOW LINE (0xfe4e Pc) case u'﹏': // WAVY LOW LINE (0xfe4f Pc) case u'﹐': // SMALL COMMA (0xfe50 Po) case u'﹑': // SMALL IDEOGRAPHIC COMMA (0xfe51 Po) case u'﹒': // SMALL FULL STOP (0xfe52 Po) case u'﹔': // SMALL SEMICOLON (0xfe54 Po) case u'﹕': // SMALL COLON (0xfe55 Po) case u'﹖': // SMALL QUESTION MARK (0xfe56 Po) case u'﹗': // SMALL EXCLAMATION MARK (0xfe57 Po) case u'﹘': // SMALL EM DASH (0xfe58 Pd) case u'﹙': // SMALL LEFT PARENTHESIS (0xfe59 Ps) case u'﹚': // SMALL RIGHT PARENTHESIS (0xfe5a Pe) case u'﹛': // SMALL LEFT CURLY BRACKET (0xfe5b Ps) case u'﹜': // SMALL RIGHT CURLY BRACKET (0xfe5c Pe) case u'﹝': // SMALL LEFT TORTOISE SHELL BRACKET (0xfe5d Ps) case u'﹞': // SMALL RIGHT TORTOISE SHELL BRACKET (0xfe5e Pe) case u'﹟': // SMALL NUMBER SIGN (0xfe5f Po) case u'﹠': // SMALL AMPERSAND (0xfe60 Po) case u'﹡': // SMALL ASTERISK (0xfe61 Po) case u'﹣': // SMALL HYPHEN-MINUS (0xfe63 Pd) case u'﹨': // SMALL REVERSE SOLIDUS (0xfe68 Po) case u'﹪': // SMALL PERCENT SIGN (0xfe6a Po) case u'﹫': // SMALL COMMERCIAL AT (0xfe6b Po) case u'!': // FULLWIDTH EXCLAMATION MARK (0xff01 Po) case u'"': // FULLWIDTH QUOTATION MARK (0xff02 Po) case u'#': // FULLWIDTH NUMBER SIGN (0xff03 Po) case u'%': // FULLWIDTH PERCENT SIGN (0xff05 Po) case u'&': // FULLWIDTH AMPERSAND (0xff06 Po) case u''': // FULLWIDTH APOSTROPHE (0xff07 Po) case u'(': // FULLWIDTH LEFT PARENTHESIS (0xff08 Ps) case u')': // FULLWIDTH RIGHT PARENTHESIS (0xff09 Pe) case u'*': // FULLWIDTH ASTERISK (0xff0a Po) case u',': // FULLWIDTH COMMA (0xff0c Po) case u'-': // FULLWIDTH HYPHEN-MINUS (0xff0d Pd) case u'.': // FULLWIDTH FULL STOP (0xff0e Po) case u'/': // FULLWIDTH SOLIDUS (0xff0f Po) case u':': // FULLWIDTH COLON (0xff1a Po) case u';': // FULLWIDTH SEMICOLON (0xff1b Po) case u'?': // FULLWIDTH QUESTION MARK (0xff1f Po) case u'@': // FULLWIDTH COMMERCIAL AT (0xff20 Po) case u'[': // FULLWIDTH LEFT SQUARE BRACKET (0xff3b Ps) case u'\': // FULLWIDTH REVERSE SOLIDUS (0xff3c Po) case u']': // FULLWIDTH RIGHT SQUARE BRACKET (0xff3d Pe) case u'_': // FULLWIDTH LOW LINE (0xff3f Pc) case u'{': // FULLWIDTH LEFT CURLY BRACKET (0xff5b Ps) case u'}': // FULLWIDTH RIGHT CURLY BRACKET (0xff5d Pe) case u'⦅': // FULLWIDTH LEFT WHITE PARENTHESIS (0xff5f Ps) case u'⦆': // FULLWIDTH RIGHT WHITE PARENTHESIS (0xff60 Pe) case u'。': // HALFWIDTH IDEOGRAPHIC FULL STOP (0xff61 Po) case u'「': // HALFWIDTH LEFT CORNER BRACKET (0xff62 Ps) case u'」': // HALFWIDTH RIGHT CORNER BRACKET (0xff63 Pe) case u'、': // HALFWIDTH IDEOGRAPHIC COMMA (0xff64 Po) case u'・': // HALFWIDTH KATAKANA MIDDLE DOT (0xff65 Po) return 1; default: return 0; } }
30,525
542
jart/cosmopolitan
false
cosmopolitan/libc/str/wmemcmp.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Compares arrays of 32-bit signed integers. * * @param a is first memory array * @param b is second memory array * @param n is number of elements in `a` and `b` to consider * @return is <0, 0, or >0 based on int32_t comparison * @asyncsignalsafe */ int wmemcmp(const wchar_t *a, const wchar_t *b, size_t n) { size_t i; for (i = 0; i < n; ++i) { if (a[i] != b[i]) { return a[i] - b[i]; } } return 0; }
2,299
39
jart/cosmopolitan
false
cosmopolitan/libc/str/towupper.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/macros.internal.h" #include "libc/str/str.h" /* clang-format off */ static const struct { unsigned short x; unsigned short y; short d; } kUpper[] = { {0x00b5, 0x00b5, +743}, /* 1x µ ..µ → Μ ..Μ Watin */ {0x00e0, 0x00f6, -32}, /* 23x à ..ö → À ..Ö Watin */ {0x00f8, 0x00fe, -32}, /* 7x ø ..þ → Ø ..Þ Watin */ {0x00ff, 0x00ff, +121}, /* 1x ÿ ..ÿ → Ÿ ..Ÿ Watin */ {0x017a, 0x017a, -1}, /* 1x ź ..ź → Ź ..Ź Watin-A */ {0x017c, 0x017c, -1}, /* 1x ż ..ż → Ż ..Ż Watin-A */ {0x017e, 0x017e, -1}, /* 1x ž ..ž → Ž ..Ž Watin-A */ {0x017f, 0x017f, -300}, /* 1x ſ ..ſ → S ..S Watin-A */ {0x0180, 0x0180, +195}, /* 1x ƀ ..ƀ → Ƀ ..Ƀ Watin-B */ {0x0183, 0x0183, -1}, /* 1x ƃ ..ƃ → Ƃ ..Ƃ Watin-B */ {0x0185, 0x0185, -1}, /* 1x ƅ ..ƅ → Ƅ ..Ƅ Watin-B */ {0x0188, 0x0188, -1}, /* 1x ƈ ..ƈ → Ƈ ..Ƈ Watin-B */ {0x018c, 0x018c, -1}, /* 1x ƌ ..ƌ → Ƌ ..Ƌ Watin-B */ {0x0192, 0x0192, -1}, /* 1x ƒ ..ƒ → Ƒ ..Ƒ Watin-B */ {0x0195, 0x0195, +97}, /* 1x ƕ ..ƕ → Ƕ ..Ƕ Watin-B */ {0x0199, 0x0199, -1}, /* 1x ƙ ..ƙ → Ƙ ..Ƙ Watin-B */ {0x019a, 0x019a, +163}, /* 1x ƚ ..ƚ → Ƚ ..Ƚ Watin-B */ {0x019e, 0x019e, +130}, /* 1x ƞ ..ƞ → Ƞ ..Ƞ Watin-B */ {0x01a1, 0x01a1, -1}, /* 1x ơ ..ơ → Ơ ..Ơ Watin-B */ {0x01a3, 0x01a3, -1}, /* 1x ƣ ..ƣ → Ƣ ..Ƣ Watin-B */ {0x01a5, 0x01a5, -1}, /* 1x ƥ ..ƥ → Ƥ ..Ƥ Watin-B */ {0x01a8, 0x01a8, -1}, /* 1x ƨ ..ƨ → Ƨ ..Ƨ Watin-B */ {0x01ad, 0x01ad, -1}, /* 1x ƭ ..ƭ → Ƭ ..Ƭ Watin-B */ {0x01b0, 0x01b0, -1}, /* 1x ư ..ư → Ư ..Ư Watin-B */ {0x01b4, 0x01b4, -1}, /* 1x ƴ ..ƴ → Ƴ ..Ƴ Watin-B */ {0x01b6, 0x01b6, -1}, /* 1x ƶ ..ƶ → Ƶ ..Ƶ Watin-B */ {0x01b9, 0x01b9, -1}, /* 1x ƹ ..ƹ → Ƹ ..Ƹ Watin-B */ {0x01bd, 0x01bd, -1}, /* 1x ƽ ..ƽ → Ƽ ..Ƽ Watin-B */ {0x01bf, 0x01bf, +56}, /* 1x ƿ ..ƿ → Ƿ ..Ƿ Watin-B */ {0x01c5, 0x01c5, -1}, /* 1x Dž ..Dž → DŽ ..DŽ Watin-B */ {0x01c6, 0x01c6, -2}, /* 1x dž ..dž → DŽ ..DŽ Watin-B */ {0x01c8, 0x01c8, -1}, /* 1x Lj ..Lj → LJ ..LJ Watin-B */ {0x01c9, 0x01c9, -2}, /* 1x lj ..lj → LJ ..LJ Watin-B */ {0x01cb, 0x01cb, -1}, /* 1x Nj ..Nj → NJ ..NJ Watin-B */ {0x01cc, 0x01cc, -2}, /* 1x nj ..nj → NJ ..NJ Watin-B */ {0x01ce, 0x01ce, -1}, /* 1x ǎ ..ǎ → Ǎ ..Ǎ Watin-B */ {0x01dd, 0x01dd, -79}, /* 1x ǝ ..ǝ → Ǝ ..Ǝ Watin-B */ {0x01f2, 0x01f2, -1}, /* 1x Dz ..Dz → DZ ..DZ Watin-B */ {0x01f3, 0x01f3, -2}, /* 1x dz ..dz → DZ ..DZ Watin-B */ {0x01f5, 0x01f5, -1}, /* 1x ǵ ..ǵ → Ǵ ..Ǵ Watin-B */ {0x023c, 0x023c, -1}, /* 1x ȼ ..ȼ → Ȼ ..Ȼ Watin-B */ {0x023f, 0x0240, +10815}, /* 2x ȿ ..ɀ → Ȿ ..Ɀ Watin-B */ {0x0242, 0x0242, -1}, /* 1x ɂ ..ɂ → Ɂ ..Ɂ Watin-B */ {0x0247, 0x0247, -1}, /* 1x ɇ ..ɇ → Ɇ ..Ɇ Watin-B */ {0x0249, 0x0249, -1}, /* 1x ɉ ..ɉ → Ɉ ..Ɉ Watin-B */ {0x024b, 0x024b, -1}, /* 1x ɋ ..ɋ → Ɋ ..Ɋ Watin-B */ {0x024d, 0x024d, -1}, /* 1x ɍ ..ɍ → Ɍ ..Ɍ Watin-B */ {0x024f, 0x024f, -1}, /* 1x ɏ ..ɏ → Ɏ ..Ɏ Watin-B */ {0x037b, 0x037d, +130}, /* 3x ͻ ..ͽ → Ͻ ..Ͽ Greek */ {0x03ac, 0x03ac, -38}, /* 1x ά ..ά → Ά ..Ά Greek */ {0x03ad, 0x03af, -37}, /* 3x έ ..ί → Έ ..Ί Greek */ {0x03b1, 0x03c1, -32}, /* 17x α ..ρ → Α ..Ρ Greek */ {0x03c2, 0x03c2, -31}, /* 1x ς ..ς → Σ ..Σ Greek */ {0x03c3, 0x03cb, -32}, /* 9x σ ..ϋ → Σ ..Ϋ Greek */ {0x03cc, 0x03cc, -64}, /* 1x ό ..ό → Ό ..Ό Greek */ {0x03cd, 0x03ce, -63}, /* 2x ύ ..ώ → Ύ ..Ώ Greek */ {0x03d0, 0x03d0, -62}, /* 1x ϐ ..ϐ → Β ..Β Greek */ {0x03d1, 0x03d1, -57}, /* 1x ϑ ..ϑ → Θ ..Θ Greek */ {0x03d5, 0x03d5, -47}, /* 1x ϕ ..ϕ → Φ ..Φ Greek */ {0x03d6, 0x03d6, -54}, /* 1x ϖ ..ϖ → Π ..Π Greek */ {0x03dd, 0x03dd, -1}, /* 1x ϝ ..ϝ → Ϝ ..Ϝ Greek */ {0x03f0, 0x03f0, -86}, /* 1x ϰ ..ϰ → Κ ..Κ Greek */ {0x03f1, 0x03f1, -80}, /* 1x ϱ ..ϱ → Ρ ..Ρ Greek */ {0x03f5, 0x03f5, -96}, /* 1x ϵ ..ϵ → Ε ..Ε Greek */ {0x0430, 0x044f, -32}, /* 32x а ..я → А ..Я Cyrillic */ {0x0450, 0x045f, -80}, /* 16x ѐ ..џ → Ѐ ..Џ Cyrillic */ {0x0461, 0x0461, -1}, /* 1x ѡ ..ѡ → Ѡ ..Ѡ Cyrillic */ {0x0463, 0x0463, -1}, /* 1x ѣ ..ѣ → Ѣ ..Ѣ Cyrillic */ {0x0465, 0x0465, -1}, /* 1x ѥ ..ѥ → Ѥ ..Ѥ Cyrillic */ {0x0473, 0x0473, -1}, /* 1x ѳ ..ѳ → Ѳ ..Ѳ Cyrillic */ {0x0491, 0x0491, -1}, /* 1x ґ ..ґ → Ґ ..Ґ Cyrillic */ {0x0499, 0x0499, -1}, /* 1x ҙ ..ҙ → Ҙ ..Ҙ Cyrillic */ {0x049b, 0x049b, -1}, /* 1x қ ..қ → Қ ..Қ Cyrillic */ {0x0561, 0x0586, -48}, /* 38x ա ..ֆ → Ա ..Ֆ Armenian */ {0x10d0, 0x10fa, +3008}, /* 43x ა ..ჺ → Ა ..Ჺ Georgian */ {0x10fd, 0x10ff, +3008}, /* 3x ჽ ..ჿ → Ჽ ..Ჿ Georgian */ {0x13f8, 0x13fd, -8}, /* 6x ᏸ ..ᏽ → Ᏸ ..Ᏽ Cherokee */ {0x214e, 0x214e, -28}, /* 1x ⅎ ..ⅎ → Ⅎ ..Ⅎ Letterlike */ {0x2170, 0x217f, -16}, /* 16x ⅰ ..ⅿ → Ⅰ ..Ⅿ Numbery */ {0x2184, 0x2184, -1}, /* 1x ↄ ..ↄ → Ↄ ..Ↄ Numbery */ {0x24d0, 0x24e9, -26}, /* 26x ⓐ ..ⓩ → Ⓐ ..Ⓩ Enclosed */ {0x2c30, 0x2c5e, -48}, /* 47x ⰰ ..ⱞ → Ⰰ ..Ⱞ Glagolitic */ {0x2d00, 0x2d25, -7264}, /* 38x ⴀ ..ⴥ → Ⴀ ..Ⴥ Georgian2 */ {0x2d27, 0x2d27, -7264}, /* 1x ⴧ ..ⴧ → Ⴧ ..Ⴧ Georgian2 */ {0x2d2d, 0x2d2d, -7264}, /* 1x ⴭ ..ⴭ → Ⴭ ..Ⴭ Georgian2 */ {0xff41, 0xff5a, -32}, /* 26x a..z → A..Z Dubs */ }; static const int kAstralUpper[][3] = { {0x10428, 0x1044f, -40}, /* 40x 𐐨..𐑏 → 𐐀..𐐧 Deseret */ {0x104d8, 0x104fb, -40}, /* 36x 𐓘..𐓻 → 𐒰..𐓓 Osage */ {0x1d41a, 0x1d433, -26}, /* 26x 𝐚..𝐳 → 𝐀..𝐙 Math */ {0x1d456, 0x1d467, -26}, /* 18x 𝑖..𝑧 → 𝐼..𝑍 Math */ {0x1d482, 0x1d49b, -26}, /* 26x 𝒂..𝒛 → 𝑨..𝒁 Math */ {0x1d4c8, 0x1d4cf, -26}, /* 8x 𝓈..𝓏 → 𝒮..𝒵 Math */ {0x1d4ea, 0x1d503, -26}, /* 26x 𝓪..𝔃 → 𝓐..𝓩 Math */ {0x1d527, 0x1d52e, -26}, /* 8x 𝔧..𝔮 → 𝔍..𝔔 Math */ {0x1d586, 0x1d59f, -26}, /* 26x 𝖆..𝖟 → 𝕬..𝖅 Math */ {0x1d5ba, 0x1d5d3, -26}, /* 26x 𝖺..𝗓 → 𝖠..𝖹 Math */ {0x1d5ee, 0x1d607, -26}, /* 26x 𝗮..𝘇 → 𝗔..𝗭 Math */ {0x1d622, 0x1d63b, -26}, /* 26x 𝘢..𝘻 → 𝘈..𝘡 Math */ {0x1d68a, 0x1d6a3, +442}, /* 26x 𝒂..𝒛 → 𝘼..𝙕 Math */ {0x1d6c2, 0x1d6d2, -26}, /* 26x 𝚊..𝚣 → 𝙰..𝚉 Math */ {0x1d6fc, 0x1d70c, -26}, /* 17x 𝛂..𝛒 → 𝚨..𝚸 Math */ {0x1d736, 0x1d746, -26}, /* 17x 𝛼..𝜌 → 𝛢..𝛲 Math */ {0x1d770, 0x1d780, -26}, /* 17x 𝜶..𝝆 → 𝜜..𝜬 Math */ {0x1d770, 0x1d756, -26}, /* 17x 𝝰..𝞀 → 𝝖..𝝦 Math */ {0x1d736, 0x1d790, -90}, /* 17x 𝜶..𝝆 → 𝞐..𝞠 Math */ }; /** * Converts wide character to upper case. */ wint_t towupper(wint_t c) { int m, l, r, n; if (c < 0200) { if ('a' <= c && c <= 'z') { return c - 32; } else { return c; } } else if (c <= 0xffff) { if ((0x0101 <= c && c <= 0x0177) || /* 60x ā..ŵ → Ā..ā Watin-A */ (0x01df <= c && c <= 0x01ef) || /* 9x ǟ..ǯ → Ǟ..Ǯ Watin-B */ (0x01f8 <= c && c <= 0x021e) || /* 20x ǹ..ȟ → Ǹ..Ȟ Watin-B */ (0x0222 <= c && c <= 0x0232) || /* 9x ȣ..ȳ → Ȣ..Ȳ Watin-B */ (0x1e01 <= c && c <= 0x1eff)) { /*256x ḁ..ỿ → Ḁ..Ỿ Watin-C */ if (c == 0x0131) return c + 232; if (c == 0x1e9e) return c; return c - (c & 1); } else if (0x01d0 <= c && c <= 0x01dc) { return c - (~c & 1); /* 7x ǐ..ǜ → Ǐ..Ǜ Watin-B */ } else if (0xab70 <= c && c <= 0xabbf) { return c - 38864; /* 80x ꭰ ..ꮿ → Ꭰ ..Ꮿ Cherokee Supplement */ } else { l = 0; r = n = sizeof(kUpper) / sizeof(kUpper[0]); while (l < r) { m = (l + r) >> 1; if (kUpper[m].y < c) { l = m + 1; } else { r = m; } } if (l < n && kUpper[l].x <= c && c <= kUpper[l].y) { return c + kUpper[l].d; } else { return c; } } } else { l = 0; r = n = sizeof(kAstralUpper) / sizeof(kAstralUpper[0]); while (l < r) { m = (l + r) >> 1; if (kAstralUpper[m][1] < c) { l = m + 1; } else { r = m; } } if (l < n && kAstralUpper[l][0] <= c && c <= kAstralUpper[l][1]) { return c + kAstralUpper[l][2]; } else { return c; } } }
11,161
198
jart/cosmopolitan
false
cosmopolitan/libc/str/rawmemchr.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/str.h" static inline const unsigned char *rawmemchr_pure(const unsigned char *s, unsigned char c) { for (;; ++s) { if (*s == c) { return s; } } } #ifdef __x86_64__ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); noasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) { unsigned k; unsigned m; xmm_t v, *p; xmm_t n = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; k = (uintptr_t)s & 15; p = (const xmm_t *)((uintptr_t)s & -16); v = *p; m = __builtin_ia32_pmovmskb128(v == n); m >>= k; m <<= k; while (!m) { v = *++p; m = __builtin_ia32_pmovmskb128(v == n); } m = __builtin_ctzll(m); return (const char *)p + m; } #endif static inline noasan uint64_t UncheckedAlignedRead64(unsigned char *p) { return (uint64_t)p[7] << 070 | (uint64_t)p[6] << 060 | (uint64_t)p[5] << 050 | (uint64_t)p[4] << 040 | (uint64_t)p[3] << 030 | (uint64_t)p[2] << 020 | (uint64_t)p[1] << 010 | (uint64_t)p[0] << 000; } /** * Returns pointer to first instance of character. * * @param m is memory to search * @param c is search byte which is masked with 255 * @return is pointer to first instance of c */ void *rawmemchr(const void *s, int c) { #ifdef __x86_64__ const void *r; if (X86_HAVE(SSE)) { if (IsAsan()) __asan_verify(s, 1); r = rawmemchr_sse(s, c); } else { r = rawmemchr_pure(s, c); } return (void *)r; #else uint64_t v, w; const unsigned char *p; p = s; c &= 255; v = 0x0101010101010101ul * c; for (; (uintptr_t)p & 7; ++p) { if (*p == c) return p; } for (;; p += 8) { w = UncheckedAlignedRead64(p); if ((w = ~(w ^ v) & ((w ^ v) - 0x0101010101010101) & 0x8080808080808080)) { p += (unsigned)__builtin_ctzll(w) >> 3; break; } } assert(*p == c); return p; #endif }
3,886
99
jart/cosmopolitan
false
cosmopolitan/libc/str/iswlower.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is lowercase letter. */ int iswlower(wint_t c) { int r; if (c < 0200) { return 'a' <= c && c <= 'z'; } else { if (towupper(c) != c) return 1; switch (c) { case 0x00df: /* ß Watin */ case 0x0138: /* ĸ Watin-A */ case 0x0149: /* ʼn Watin-A */ case 0x018d: /* ƍ Watin-B */ case 0x019b: /* ƛ Watin-B */ case 0x01aa: /* ƪ Watin-B */ case 0x01ab: /* ƫ Watin-B */ case 0x01ba: /* ƺ Watin-B */ case 0x01be: /* ƾ Watin-B */ case 0x01f0: /* ǰ Watin-B */ case 0x0221: /* ȡ Watin-B */ case 0x0234: /* ȴ Watin-B */ case 0x0235: /* ȵ Watin-B */ case 0x0236: /* ȶ Watin-B */ case 0x0237: /* ȷ Watin-B */ case 0x0238: /* ȸ Watin-B */ case 0x0239: /* ȹ Watin-B */ case 0x0255: /* ɕ IPA */ case 0x0258: /* ɘ IPA */ case 0x025a: /* ɚ IPA */ case 0x025d: /* ɝ IPA */ case 0x025e: /* ɞ IPA */ case 0x025f: /* ɟ IPA */ case 0x0262: /* ɢ IPA */ case 0x0264: /* ɤ IPA */ case 0x0267: /* ɧ IPA */ case 0x026d: /* ɭ IPA */ case 0x026e: /* ɮ IPA */ case 0x0270: /* ɰ IPA */ case 0x0273: /* ɳ IPA */ case 0x0274: /* ɴ IPA */ case 0x0276: /* ɶ IPA */ case 0x0277: /* ɷ IPA */ case 0x0278: /* ɸ IPA */ case 0x0279: /* ɹ IPA */ case 0x027a: /* ɺ IPA */ case 0x027b: /* ɻ IPA */ case 0x027c: /* ɼ IPA */ case 0x027e: /* ɾ IPA */ case 0x027f: /* ɿ IPA */ case 0x0281: /* ʁ IPA */ case 0x0284: /* ʄ IPA */ case 0x0285: /* ʅ IPA */ case 0x0286: /* ʆ IPA */ case 0x028d: /* ʍ IPA */ case 0x028e: /* ʎ IPA */ case 0x028f: /* ʏ IPA */ case 0x0290: /* ʐ IPA */ case 0x0291: /* ʑ IPA */ case 0x0293: /* ʓ IPA */ case 0x0295: /* ʕ IPA */ case 0x0296: /* ʖ IPA */ case 0x0297: /* ʗ IPA */ case 0x0298: /* ʘ IPA */ case 0x0299: /* ʙ IPA */ case 0x029a: /* ʚ IPA */ case 0x029b: /* ʛ IPA */ case 0x029c: /* ʜ IPA */ case 0x029f: /* ʟ IPA */ case 0x02a0: /* ʠ IPA */ case 0x02a1: /* ʡ IPA */ case 0x02a2: /* ʢ IPA */ case 0x02a3: /* ʣ IPA */ case 0x02a4: /* ʤ IPA */ case 0x02a5: /* ʥ IPA */ case 0x02a6: /* ʦ IPA */ case 0x02a7: /* ʧ IPA */ case 0x02a8: /* ʨ IPA */ case 0x02a9: /* ʩ IPA */ case 0x02aa: /* ʪ IPA */ case 0x02ab: /* ʫ IPA */ case 0x02ac: /* ʬ IPA */ case 0x02ad: /* ʭ IPA */ case 0x02ae: /* ʮ IPA */ case 0x02af: /* ʯ IPA */ case 0x0390: /* ΐ Greek */ case 0x03b0: /* ΰ Greek */ case 0x03fc: /* ϼ Greek */ case 0x0560: /* ՠ Armenian */ case 0x0587: /* և Armenian */ case 0x0588: /* ֈ Armenian */ case 0x1d00: /* ᴀ Phonetic Extensions */ case 0x1d01: /* ᴁ Phonetic Extensions */ case 0x1d02: /* ᴂ Phonetic Extensions */ case 0x1d03: /* ᴃ Phonetic Extensions */ case 0x1d04: /* ᴄ Phonetic Extensions */ case 0x1d05: /* ᴅ Phonetic Extensions */ case 0x1d06: /* ᴆ Phonetic Extensions */ case 0x1d07: /* ᴇ Phonetic Extensions */ case 0x1d08: /* ᴈ Phonetic Extensions */ case 0x1d09: /* ᴉ Phonetic Extensions */ case 0x1d0a: /* ᴊ Phonetic Extensions */ case 0x1d0b: /* ᴋ Phonetic Extensions */ case 0x1d0c: /* ᴌ Phonetic Extensions */ case 0x1d0d: /* ᴍ Phonetic Extensions */ case 0x1d0e: /* ᴎ Phonetic Extensions */ case 0x1d0f: /* ᴏ Phonetic Extensions */ case 0x1d10: /* ᴐ Phonetic Extensions */ case 0x1d11: /* ᴑ Phonetic Extensions */ case 0x1d12: /* ᴒ Phonetic Extensions */ case 0x1d13: /* ᴓ Phonetic Extensions */ case 0x1d14: /* ᴔ Phonetic Extensions */ case 0x1d15: /* ᴕ Phonetic Extensions */ case 0x1d16: /* ᴖ Phonetic Extensions */ case 0x1d17: /* ᴗ Phonetic Extensions */ case 0x1d18: /* ᴘ Phonetic Extensions */ case 0x1d19: /* ᴙ Phonetic Extensions */ case 0x1d1a: /* ᴚ Phonetic Extensions */ case 0x1d1b: /* ᴛ Phonetic Extensions */ case 0x1d1c: /* ᴜ Phonetic Extensions */ case 0x1d1d: /* ᴝ Phonetic Extensions */ case 0x1d1e: /* ᴞ Phonetic Extensions */ case 0x1d1f: /* ᴟ Phonetic Extensions */ case 0x1d20: /* ᴠ Phonetic Extensions */ case 0x1d21: /* ᴡ Phonetic Extensions */ case 0x1d22: /* ᴢ Phonetic Extensions */ case 0x1d23: /* ᴣ Phonetic Extensions */ case 0x1d24: /* ᴤ Phonetic Extensions */ case 0x1d25: /* ᴥ Phonetic Extensions */ case 0x1d26: /* ᴦ Phonetic Extensions */ case 0x1d27: /* ᴧ Phonetic Extensions */ case 0x1d28: /* ᴨ Phonetic Extensions */ case 0x1d29: /* ᴩ Phonetic Extensions */ case 0x1d2a: /* ᴪ Phonetic Extensions */ case 0x1d2b: /* ᴫ Phonetic Extensions */ case 0x1d6b: /* ᵫ Phonetic Extensions */ case 0x1d6c: /* ᵬ Phonetic Extensions */ case 0x1d6d: /* ᵭ Phonetic Extensions */ case 0x1d6e: /* ᵮ Phonetic Extensions */ case 0x1d6f: /* ᵯ Phonetic Extensions */ case 0x1d70: /* ᵰ Phonetic Extensions */ case 0x1d71: /* ᵱ Phonetic Extensions */ case 0x1d72: /* ᵲ Phonetic Extensions */ case 0x1d73: /* ᵳ Phonetic Extensions */ case 0x1d74: /* ᵴ Phonetic Extensions */ case 0x1d75: /* ᵵ Phonetic Extensions */ case 0x1d76: /* ᵶ Phonetic Extensions */ case 0x1d77: /* ᵷ Phonetic Extensions */ case 0x1d7a: /* ᵺ Phonetic Extensions */ case 0x1d7b: /* ᵻ Phonetic Extensions */ case 0x1d7c: /* ᵼ Phonetic Extensions */ case 0x1d7e: /* ᵾ Phonetic Extensions */ case 0x1d7f: /* ᵿ Phonetic Extensions */ case 0x1d80: /* . Phonetic Extensions Supplement */ case 0x1d81: /* . Phonetic Extensions Supplement */ case 0x1d82: /* . Phonetic Extensions Supplement */ case 0x1d83: /* . Phonetic Extensions Supplement */ case 0x1d84: /* . Phonetic Extensions Supplement */ case 0x1d85: /* . Phonetic Extensions Supplement */ case 0x1d86: /* . Phonetic Extensions Supplement */ case 0x1d87: /* . Phonetic Extensions Supplement */ case 0x1d88: /* . Phonetic Extensions Supplement */ case 0x1d89: /* . Phonetic Extensions Supplement */ case 0x1d8a: /* . Phonetic Extensions Supplement */ case 0x1d8b: /* . Phonetic Extensions Supplement */ case 0x1d8c: /* . Phonetic Extensions Supplement */ case 0x1d8d: /* . Phonetic Extensions Supplement */ case 0x1d8f: /* . Phonetic Extensions Supplement */ case 0x1d90: /* . Phonetic Extensions Supplement */ case 0x1d91: /* . Phonetic Extensions Supplement */ case 0x1d92: /* . Phonetic Extensions Supplement */ case 0x1d93: /* . Phonetic Extensions Supplement */ case 0x1d94: /* . Phonetic Extensions Supplement */ case 0x1d95: /* . Phonetic Extensions Supplement */ case 0x1d96: /* . Phonetic Extensions Supplement */ case 0x1d97: /* . Phonetic Extensions Supplement */ case 0x1d98: /* . Phonetic Extensions Supplement */ case 0x1d99: /* . Phonetic Extensions Supplement */ case 0x1d9a: /* . Phonetic Extensions Supplement */ case 0x1e96: /* ẖ Watin-C */ case 0x1e97: /* ẗ Watin-C */ case 0x1e98: /* ẘ Watin-C */ case 0x1e99: /* ẙ Watin-C */ case 0x1e9a: /* ẚ Watin-C */ case 0x1e9c: /* ẜ Watin-C */ case 0x1e9d: /* ẝ Watin-C */ case 0x1e9f: /* ẟ Watin-C */ case 0x1f50: /* ὐ Greek2 */ case 0x1f52: /* ὒ Greek2 */ case 0x1f54: /* ὔ Greek2 */ case 0x1f56: /* ὖ Greek2 */ case 0x1fb2: /* ᾲ Greek2 */ case 0x1fb4: /* ᾴ Greek2 */ case 0x1fb6: /* ᾶ Greek2 */ case 0x1fb7: /* ᾷ Greek2 */ case 0x1fc2: /* ῂ Greek2 */ case 0x1fc4: /* ῄ Greek2 */ case 0x1fc6: /* ῆ Greek2 */ case 0x1fc7: /* ῇ Greek2 */ case 0x1fd2: /* ῒ Greek2 */ case 0x1fd3: /* ΐ Greek2 */ case 0x1fd6: /* ῖ Greek2 */ case 0x1fd7: /* ῗ Greek2 */ case 0x1fe2: /* ῢ Greek2 */ case 0x1fe3: /* ΰ Greek2 */ case 0x1fe4: /* ῤ Greek2 */ case 0x1fe6: /* ῦ Greek2 */ case 0x1fe7: /* ῧ Greek2 */ case 0x1ff2: /* ῲ Greek2 */ case 0x1ff4: /* ῴ Greek2 */ case 0x1ff6: /* ῶ Greek2 */ case 0x1ff7: /* ῷ Greek2 */ case 0x210a: /* ℊ Letterlike */ case 0x210e: /* ℎ Letterlike */ case 0x210f: /* ℏ Letterlike */ case 0x2113: /* ℓ Letterlike */ case 0x212f: /* ℯ Letterlike */ case 0x2134: /* ℴ Letterlike */ case 0x2139: /* ℹ Letterlike */ case 0x213c: /* ℼ Letterlike */ case 0x213d: /* ℽ Letterlike */ case 0x2146: /* ⅆ Letterlike */ case 0x2147: /* ⅇ Letterlike */ case 0x2148: /* ⅈ Letterlike */ case 0x2149: /* ⅉ Letterlike */ case 0x2c71: /* . Watin-D */ case 0x2c74: /* . Watin-D */ case 0x2c77: /* . Watin-D */ case 0x2c78: /* . Watin-D */ case 0x2c79: /* . Watin-D */ case 0x2c7a: /* . Watin-D */ case 0x2c7b: /* . Watin-D */ case 0x2ce4: /* . Coptic */ case 0xa730: /* . Latin Extended-D */ case 0xa731: /* . Latin Extended-D */ case 0xa771: /* . Latin Extended-D */ case 0xa772: /* . Latin Extended-D */ case 0xa773: /* . Latin Extended-D */ case 0xa774: /* . Latin Extended-D */ case 0xa775: /* . Latin Extended-D */ case 0xa776: /* . Latin Extended-D */ case 0xa777: /* . Latin Extended-D */ case 0xa778: /* . Latin Extended-D */ case 0xa78e: /* . Latin Extended-D */ case 0xa795: /* . Latin Extended-D */ case 0xa7af: /* . Latin Extended-D */ case 0xa7fa: /* . Latin Extended-D */ case 0xab30: /* . Latin Extended-E */ case 0xab31: /* . Latin Extended-E */ case 0xab32: /* . Latin Extended-E */ case 0xab33: /* . Latin Extended-E */ case 0xab34: /* . Latin Extended-E */ case 0xab35: /* . Latin Extended-E */ case 0xab36: /* . Latin Extended-E */ case 0xab37: /* . Latin Extended-E */ case 0xab38: /* . Latin Extended-E */ case 0xab39: /* . Latin Extended-E */ case 0xab3a: /* . Latin Extended-E */ case 0xab3b: /* . Latin Extended-E */ case 0xab3c: /* . Latin Extended-E */ case 0xab3d: /* . Latin Extended-E */ case 0xab3e: /* . Latin Extended-E */ case 0xab3f: /* . Latin Extended-E */ case 0xab40: /* . Latin Extended-E */ case 0xab41: /* . Latin Extended-E */ case 0xab42: /* . Latin Extended-E */ case 0xab43: /* . Latin Extended-E */ case 0xab44: /* . Latin Extended-E */ case 0xab45: /* . Latin Extended-E */ case 0xab46: /* . Latin Extended-E */ case 0xab47: /* . Latin Extended-E */ case 0xab48: /* . Latin Extended-E */ case 0xab49: /* . Latin Extended-E */ case 0xab4a: /* . Latin Extended-E */ case 0xab4b: /* . Latin Extended-E */ case 0xab4c: /* . Latin Extended-E */ case 0xab4d: /* . Latin Extended-E */ case 0xab4e: /* . Latin Extended-E */ case 0xab4f: /* . Latin Extended-E */ case 0xab50: /* . Latin Extended-E */ case 0xab51: /* . Latin Extended-E */ case 0xab52: /* . Latin Extended-E */ case 0xab54: /* . Latin Extended-E */ case 0xab55: /* . Latin Extended-E */ case 0xab56: /* . Latin Extended-E */ case 0xab57: /* . Latin Extended-E */ case 0xab58: /* . Latin Extended-E */ case 0xab59: /* . Latin Extended-E */ case 0xab5a: /* . Latin Extended-E */ case 0xab60: /* . Latin Extended-E */ case 0xab61: /* . Latin Extended-E */ case 0xab62: /* . Latin Extended-E */ case 0xab63: /* . Latin Extended-E */ case 0xab64: /* . Latin Extended-E */ case 0xab65: /* . Latin Extended-E */ case 0xab66: /* . Latin Extended-E */ case 0xab67: /* . Latin Extended-E */ case 0xfb00: /* . Alphabetic Presentation Forms */ case 0xfb01: /* . Alphabetic Presentation Forms */ case 0xfb02: /* . Alphabetic Presentation Forms */ case 0xfb03: /* . Alphabetic Presentation Forms */ case 0xfb04: /* . Alphabetic Presentation Forms */ case 0xfb05: /* . Alphabetic Presentation Forms */ case 0xfb06: /* . Alphabetic Presentation Forms */ case 0xfb13: /* . Alphabetic Presentation Forms */ case 0xfb14: /* . Alphabetic Presentation Forms */ case 0xfb15: /* . Alphabetic Presentation Forms */ case 0xfb16: /* . Alphabetic Presentation Forms */ case 0xfb17: /* . Alphabetic Presentation Forms */ case 0x1d44e: /* 𝑎 Math */ case 0x1d44f: /* 𝑏 Math */ case 0x1d450: /* 𝑐 Math */ case 0x1d451: /* 𝑑 Math */ case 0x1d452: /* 𝑒 Math */ case 0x1d453: /* 𝑓 Math */ case 0x1d454: /* 𝑔 Math */ case 0x1d45e: /* 𝑞 Math */ case 0x1d45f: /* 𝑟 Math */ case 0x1d460: /* 𝑠 Math */ case 0x1d461: /* 𝑡 Math */ case 0x1d462: /* 𝑢 Math */ case 0x1d463: /* 𝑣 Math */ case 0x1d464: /* 𝑤 Math */ case 0x1d465: /* 𝑥 Math */ case 0x1d466: /* 𝑦 Math */ case 0x1d467: /* 𝑧 Math */ case 0x1d4b6: /* 𝒶 Math */ case 0x1d4b7: /* 𝒷 Math */ case 0x1d4b8: /* 𝒸 Math */ case 0x1d4b9: /* 𝒹 Math */ case 0x1d4bb: /* 𝒻 Math */ case 0x1d4bd: /* 𝒽 Math */ case 0x1d4be: /* 𝒾 Math */ case 0x1d4bf: /* 𝒿 Math */ case 0x1d4c0: /* 𝓀 Math */ case 0x1d4c1: /* 𝓁 Math */ case 0x1d4c2: /* 𝓂 Math */ case 0x1d4c3: /* 𝓃 Math */ case 0x1d4c5: /* 𝓅 Math */ case 0x1d4c6: /* 𝓆 Math */ case 0x1d4c7: /* 𝓇 Math */ case 0x1d51e: /* 𝔞 Math */ case 0x1d51f: /* 𝔟 Math */ case 0x1d520: /* 𝔠 Math */ case 0x1d521: /* 𝔡 Math */ case 0x1d522: /* 𝔢 Math */ case 0x1d523: /* 𝔣 Math */ case 0x1d524: /* 𝔤 Math */ case 0x1d525: /* 𝔥 Math */ case 0x1d526: /* 𝔦 Math */ case 0x1d52f: /* 𝔯 Math */ case 0x1d530: /* 𝔰 Math */ case 0x1d531: /* 𝔱 Math */ case 0x1d532: /* 𝔲 Math */ case 0x1d533: /* 𝔳 Math */ case 0x1d534: /* 𝔴 Math */ case 0x1d535: /* 𝔵 Math */ case 0x1d536: /* 𝔶 Math */ case 0x1d537: /* 𝔷 Math */ case 0x1d552: /* 𝕒 Math */ case 0x1d553: /* 𝕓 Math */ case 0x1d554: /* 𝕔 Math */ case 0x1d555: /* 𝕕 Math */ case 0x1d556: /* 𝕖 Math */ case 0x1d557: /* 𝕗 Math */ case 0x1d558: /* 𝕘 Math */ case 0x1d559: /* 𝕙 Math */ case 0x1d55a: /* 𝕚 Math */ case 0x1d55b: /* 𝕛 Math */ case 0x1d55c: /* 𝕜 Math */ case 0x1d55d: /* 𝕝 Math */ case 0x1d55e: /* 𝕞 Math */ case 0x1d55f: /* 𝕟 Math */ case 0x1d560: /* 𝕠 Math */ case 0x1d561: /* 𝕡 Math */ case 0x1d562: /* 𝕢 Math */ case 0x1d563: /* 𝕣 Math */ case 0x1d564: /* 𝕤 Math */ case 0x1d565: /* 𝕥 Math */ case 0x1d566: /* 𝕦 Math */ case 0x1d567: /* 𝕧 Math */ case 0x1d568: /* 𝕨 Math */ case 0x1d569: /* 𝕩 Math */ case 0x1d56a: /* 𝕪 Math */ case 0x1d56b: /* 𝕫 Math */ case 0x1d656: /* 𝙖 Math */ case 0x1d657: /* 𝙗 Math */ case 0x1d658: /* 𝙘 Math */ case 0x1d659: /* 𝙙 Math */ case 0x1d65a: /* 𝙚 Math */ case 0x1d65b: /* 𝙛 Math */ case 0x1d65c: /* 𝙜 Math */ case 0x1d65d: /* 𝙝 Math */ case 0x1d65e: /* 𝙞 Math */ case 0x1d65f: /* 𝙟 Math */ case 0x1d660: /* 𝙠 Math */ case 0x1d661: /* 𝙡 Math */ case 0x1d662: /* 𝙢 Math */ case 0x1d663: /* 𝙣 Math */ case 0x1d664: /* 𝙤 Math */ case 0x1d665: /* 𝙥 Math */ case 0x1d666: /* 𝙦 Math */ case 0x1d667: /* 𝙧 Math */ case 0x1d668: /* 𝙨 Math */ case 0x1d669: /* 𝙩 Math */ case 0x1d66a: /* 𝙪 Math */ case 0x1d66b: /* 𝙫 Math */ case 0x1d66c: /* 𝙬 Math */ case 0x1d66d: /* 𝙭 Math */ case 0x1d66e: /* 𝙮 Math */ case 0x1d66f: /* 𝙯 Math */ case 0x1d6da: /* 𝛚 Math */ case 0x1d6dc: /* 𝛜 Math */ case 0x1d6dd: /* 𝛝 Math */ case 0x1d6de: /* 𝛞 Math */ case 0x1d6df: /* 𝛟 Math */ case 0x1d6e0: /* 𝛠 Math */ case 0x1d6e1: /* 𝛡 Math */ case 0x1d70d: /* 𝜍 Math */ case 0x1d70e: /* 𝜎 Math */ case 0x1d70f: /* 𝜏 Math */ case 0x1d710: /* 𝜐 Math */ case 0x1d711: /* 𝜑 Math */ case 0x1d712: /* 𝜒 Math */ case 0x1d713: /* 𝜓 Math */ case 0x1d714: /* 𝜔 Math */ case 0x1d716: /* 𝜖 Math */ case 0x1d717: /* 𝜗 Math */ case 0x1d718: /* 𝜘 Math */ case 0x1d719: /* 𝜙 Math */ case 0x1d71a: /* 𝜚 Math */ case 0x1d71b: /* 𝜛 Math */ case 0x1d747: /* 𝝇 Math */ case 0x1d748: /* 𝝈 Math */ case 0x1d749: /* 𝝉 Math */ case 0x1d74a: /* 𝝊 Math */ case 0x1d74b: /* 𝝋 Math */ case 0x1d74c: /* 𝝌 Math */ case 0x1d74d: /* 𝝍 Math */ case 0x1d74e: /* 𝝎 Math */ case 0x1d750: /* 𝝐 Math */ case 0x1d751: /* 𝝑 Math */ case 0x1d752: /* 𝝒 Math */ case 0x1d753: /* 𝝓 Math */ case 0x1d754: /* 𝝔 Math */ case 0x1d755: /* 𝝕 Math */ case 0x1d781: /* 𝞁 Math */ case 0x1d782: /* 𝞂 Math */ case 0x1d783: /* 𝞃 Math */ case 0x1d784: /* 𝞄 Math */ case 0x1d785: /* 𝞅 Math */ case 0x1d786: /* 𝞆 Math */ case 0x1d787: /* 𝞇 Math */ case 0x1d788: /* 𝞈 Math */ case 0x1d78a: /* 𝞊 Math */ case 0x1d78b: /* 𝞋 Math */ case 0x1d78c: /* 𝞌 Math */ case 0x1d78d: /* 𝞍 Math */ case 0x1d78e: /* 𝞎 Math */ case 0x1d78f: /* 𝞏 Math */ case 0x1d7aa: /* 𝞪 Math */ case 0x1d7ab: /* 𝞫 Math */ case 0x1d7ac: /* 𝞬 Math */ case 0x1d7ad: /* 𝞭 Math */ case 0x1d7ae: /* 𝞮 Math */ case 0x1d7af: /* 𝞯 Math */ case 0x1d7b0: /* 𝞰 Math */ case 0x1d7b1: /* 𝞱 Math */ case 0x1d7b2: /* 𝞲 Math */ case 0x1d7b3: /* 𝞳 Math */ case 0x1d7b4: /* 𝞴 Math */ case 0x1d7b5: /* 𝞵 Math */ case 0x1d7b6: /* 𝞶 Math */ case 0x1d7b7: /* 𝞷 Math */ case 0x1d7b8: /* 𝞸 Math */ case 0x1d7b9: /* 𝞹 Math */ case 0x1d7ba: /* 𝞺 Math */ case 0x1d7bb: /* 𝞻 Math */ case 0x1d7bc: /* 𝞼 Math */ case 0x1d7bd: /* 𝞽 Math */ case 0x1d7be: /* 𝞾 Math */ case 0x1d7bf: /* 𝞿 Math */ case 0x1d7c0: /* 𝟀 Math */ case 0x1d7c1: /* 𝟁 Math */ case 0x1d7c2: /* 𝟂 Math */ case 0x1d7c4: /* 𝟄 Math */ case 0x1d7c5: /* 𝟅 Math */ case 0x1d7c6: /* 𝟆 Math */ case 0x1d7c7: /* 𝟇 Math */ case 0x1d7c8: /* 𝟈 Math */ case 0x1d7c9: /* 𝟉 Math */ case 0x1d7cb: /* 𝟋 Math */ return 1; default: return 0; } } }
21,735
519
jart/cosmopolitan
false
cosmopolitan/libc/str/strchrnul16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns pointer to first instance of character. */ char16_t *strchrnul16(const char16_t *s, int c) { for (;; ++s) { if ((*s & 65535) == (c & 65535)) return (char16_t *)s; if (!*s) return (char16_t *)s; } }
2,089
30
jart/cosmopolitan
false
cosmopolitan/libc/str/strlcpy.c
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ │vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright (c) 1998, 2015 Todd C. Miller <[email protected]> │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" // clang-format off // $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ asm(".ident\t\"\\n\\n\ OpenBSD Strings (ISC)\\n\ Copyright (c) 1998, 2015 Todd C. Miller <[email protected]>\""); asm(".include \"libc/disclaimer.inc\""); /** * Copies string, the BSD way. * * Copy string src to buffer `dst` of size `dsize`. At most `dsize-1` * chars will be copied. Always NUL terminates (unless `dsize == 0`). * Returns `strlen(src)`; if `retval >= dsize`, truncation occurred. */ size_t strlcpy(char *dst, const char *src, size_t dsize) { const char *osrc = src; size_t nleft = dsize; /* Copy as many bytes as will fit. */ if (nleft != 0) { while (--nleft != 0) { if ((*dst++ = *src++) == '\0') break; } } /* Not enough room in dst, add NUL and traverse rest of src. */ if (nleft == 0) { if (dsize != 0) *dst = '\0'; /* NUL-terminate dst */ while (*src++) ; } return(src - osrc - 1); /* count does not include NUL */ }
2,829
59
jart/cosmopolitan
false
cosmopolitan/libc/str/dosdatetimetounix.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/conv.h" #include "libc/macros.internal.h" #include "libc/time/time.h" /** * Converts MS-DOS timestamp to UNIX. * * @note type signature supports dates greater than 2100 * @see PKZIP, FAT */ int64_t DosDateTimeToUnix(unsigned date, unsigned time) { unsigned weekday, year, month, day, hour, minute, second, yday, leap; year = ((date & 0xfffffe00) >> 9) + 1980 - 1900; month = MAX(1, MIN(12, (date & 0x01e0) >> 5)); day = (date & 0x001f) ? (date & 0x001f) - 1 : 0; hour = (time & 0x0000f800) >> 11; minute = (time & 0x000007e0) >> 5; second = (time & 0x0000001f) << 1; leap = year % 4 == 0 && (year % 100 || year % 400 == 0); yday = day + kMonthYearDay[leap][month - 1]; return second + minute * 60 + hour * 3600 + yday * 86400 + (year - 70) * 31536000ull + ((year - 69) / 4) * 86400ull - ((year - 1) / 100) * 86400ull + ((year + 299) / 400) * 86400ull; }
2,753
43
jart/cosmopolitan
false
cosmopolitan/libc/str/mbstowcs.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/fmt.h" #include "libc/str/str.h" size_t mbstowcs(wchar_t *pwc, const char *s, size_t wn) { return mbsrtowcs(pwc, (void *)&s, wn, 0); }
1,993
25
jart/cosmopolitan
false
cosmopolitan/libc/str/isxdigit.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/limits.h" #include "libc/str/str.h" /** * Returns true if c is hexadecimal digit. */ int isxdigit(int c) { return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); }
2,112
31
jart/cosmopolitan
false
cosmopolitan/libc/str/toupper_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int toupper_l(int c, locale_t l) { return toupper(c); }
1,950
25
jart/cosmopolitan
false
cosmopolitan/libc/str/wcsstartswith.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns true if s has prefix. * * @param s is a NUL-terminated string * @param prefix is also NUL-terminated */ bool _wcsstartswith(const wchar_t *s, const wchar_t *prefix) { for (;;) { if (!*prefix) return true; if (!*s) return false; if (*s++ != *prefix++) return false; } }
2,167
34
jart/cosmopolitan
false
cosmopolitan/libc/str/blocks.txt
# Blocks-14.0.0.txt # Date: 2021-01-22, 23:29:00 GMT [KW] # © 2021 Unicode®, Inc. # For terms of use, see http://www.unicode.org/terms_of_use.html # # Unicode Character Database # For documentation, see http://www.unicode.org/reports/tr44/ # # Format: # Start Code..End Code; Block Name # ================================================ # Note: When comparing block names, casing, whitespace, hyphens, # and underbars are ignored. # For example, "Latin Extended-A" and "latin extended a" are equivalent. # For more information on the comparison of property values, # see UAX #44: http://www.unicode.org/reports/tr44/ # # All block ranges start with a value where (cp MOD 16) = 0, # and end with a value where (cp MOD 16) = 15. In other words, # the last hexadecimal digit of the start of range is ...0 # and the last hexadecimal digit of the end of range is ...F. # This constraint on block ranges guarantees that allocations # are done in terms of whole columns, and that code chart display # never involves splitting columns in the charts. # # All code points not explicitly listed for Block # have the value No_Block. # Property: Block # # @missing: 0000..10FFFF; No_Block 0000..007F; Basic Latin 0080..00FF; Latin-1 Supplement 0100..017F; Latin Extended-A 0180..024F; Latin Extended-B 0250..02AF; IPA Extensions 02B0..02FF; Spacing Modifier Letters 0300..036F; Combining Diacritical Marks 0370..03FF; Greek and Coptic 0400..04FF; Cyrillic 0500..052F; Cyrillic Supplement 0530..058F; Armenian 0590..05FF; Hebrew 0600..06FF; Arabic 0700..074F; Syriac 0750..077F; Arabic Supplement 0780..07BF; Thaana 07C0..07FF; NKo 0800..083F; Samaritan 0840..085F; Mandaic 0860..086F; Syriac Supplement 0870..089F; Arabic Extended-B 08A0..08FF; Arabic Extended-A 0900..097F; Devanagari 0980..09FF; Bengali 0A00..0A7F; Gurmukhi 0A80..0AFF; Gujarati 0B00..0B7F; Oriya 0B80..0BFF; Tamil 0C00..0C7F; Telugu 0C80..0CFF; Kannada 0D00..0D7F; Malayalam 0D80..0DFF; Sinhala 0E00..0E7F; Thai 0E80..0EFF; Lao 0F00..0FFF; Tibetan 1000..109F; Myanmar 10A0..10FF; Georgian 1100..11FF; Hangul Jamo 1200..137F; Ethiopic 1380..139F; Ethiopic Supplement 13A0..13FF; Cherokee 1400..167F; Unified Canadian Aboriginal Syllabics 1680..169F; Ogham 16A0..16FF; Runic 1700..171F; Tagalog 1720..173F; Hanunoo 1740..175F; Buhid 1760..177F; Tagbanwa 1780..17FF; Khmer 1800..18AF; Mongolian 18B0..18FF; Unified Canadian Aboriginal Syllabics Extended 1900..194F; Limbu 1950..197F; Tai Le 1980..19DF; New Tai Lue 19E0..19FF; Khmer Symbols 1A00..1A1F; Buginese 1A20..1AAF; Tai Tham 1AB0..1AFF; Combining Diacritical Marks Extended 1B00..1B7F; Balinese 1B80..1BBF; Sundanese 1BC0..1BFF; Batak 1C00..1C4F; Lepcha 1C50..1C7F; Ol Chiki 1C80..1C8F; Cyrillic Extended-C 1C90..1CBF; Georgian Extended 1CC0..1CCF; Sundanese Supplement 1CD0..1CFF; Vedic Extensions 1D00..1D7F; Phonetic Extensions 1D80..1DBF; Phonetic Extensions Supplement 1DC0..1DFF; Combining Diacritical Marks Supplement 1E00..1EFF; Latin Extended Additional 1F00..1FFF; Greek Extended 2000..206F; General Punctuation 2070..209F; Superscripts and Subscripts 20A0..20CF; Currency Symbols 20D0..20FF; Combining Diacritical Marks for Symbols 2100..214F; Letterlike Symbols 2150..218F; Number Forms 2190..21FF; Arrows 2200..22FF; Mathematical Operators 2300..23FF; Miscellaneous Technical 2400..243F; Control Pictures 2440..245F; Optical Character Recognition 2460..24FF; Enclosed Alphanumerics 2500..257F; Box Drawing 2580..259F; Block Elements 25A0..25FF; Geometric Shapes 2600..26FF; Miscellaneous Symbols 2700..27BF; Dingbats 27C0..27EF; Miscellaneous Mathematical Symbols-A 27F0..27FF; Supplemental Arrows-A 2800..28FF; Braille Patterns 2900..297F; Supplemental Arrows-B 2980..29FF; Miscellaneous Mathematical Symbols-B 2A00..2AFF; Supplemental Mathematical Operators 2B00..2BFF; Miscellaneous Symbols and Arrows 2C00..2C5F; Glagolitic 2C60..2C7F; Latin Extended-C 2C80..2CFF; Coptic 2D00..2D2F; Georgian Supplement 2D30..2D7F; Tifinagh 2D80..2DDF; Ethiopic Extended 2DE0..2DFF; Cyrillic Extended-A 2E00..2E7F; Supplemental Punctuation 2E80..2EFF; CJK Radicals Supplement 2F00..2FDF; Kangxi Radicals 2FF0..2FFF; Ideographic Description Characters 3000..303F; CJK Symbols and Punctuation 3040..309F; Hiragana 30A0..30FF; Katakana 3100..312F; Bopomofo 3130..318F; Hangul Compatibility Jamo 3190..319F; Kanbun 31A0..31BF; Bopomofo Extended 31C0..31EF; CJK Strokes 31F0..31FF; Katakana Phonetic Extensions 3200..32FF; Enclosed CJK Letters and Months 3300..33FF; CJK Compatibility 3400..4DBF; CJK Unified Ideographs Extension A 4DC0..4DFF; Yijing Hexagram Symbols 4E00..9FFF; CJK Unified Ideographs A000..A48F; Yi Syllables A490..A4CF; Yi Radicals A4D0..A4FF; Lisu A500..A63F; Vai A640..A69F; Cyrillic Extended-B A6A0..A6FF; Bamum A700..A71F; Modifier Tone Letters A720..A7FF; Latin Extended-D A800..A82F; Syloti Nagri A830..A83F; Common Indic Number Forms A840..A87F; Phags-pa A880..A8DF; Saurashtra A8E0..A8FF; Devanagari Extended A900..A92F; Kayah Li A930..A95F; Rejang A960..A97F; Hangul Jamo Extended-A A980..A9DF; Javanese A9E0..A9FF; Myanmar Extended-B AA00..AA5F; Cham AA60..AA7F; Myanmar Extended-A AA80..AADF; Tai Viet AAE0..AAFF; Meetei Mayek Extensions AB00..AB2F; Ethiopic Extended-A AB30..AB6F; Latin Extended-E AB70..ABBF; Cherokee Supplement ABC0..ABFF; Meetei Mayek AC00..D7AF; Hangul Syllables D7B0..D7FF; Hangul Jamo Extended-B D800..DB7F; High Surrogates DB80..DBFF; High Private Use Surrogates DC00..DFFF; Low Surrogates E000..F8FF; Private Use Area F900..FAFF; CJK Compatibility Ideographs FB00..FB4F; Alphabetic Presentation Forms FB50..FDFF; Arabic Presentation Forms-A FE00..FE0F; Variation Selectors FE10..FE1F; Vertical Forms FE20..FE2F; Combining Half Marks FE30..FE4F; CJK Compatibility Forms FE50..FE6F; Small Form Variants FE70..FEFF; Arabic Presentation Forms-B FF00..FFEF; Halfwidth and Fullwidth Forms FFF0..FFFF; Specials 10000..1007F; Linear B Syllabary 10080..100FF; Linear B Ideograms 10100..1013F; Aegean Numbers 10140..1018F; Ancient Greek Numbers 10190..101CF; Ancient Symbols 101D0..101FF; Phaistos Disc 10280..1029F; Lycian 102A0..102DF; Carian 102E0..102FF; Coptic Epact Numbers 10300..1032F; Old Italic 10330..1034F; Gothic 10350..1037F; Old Permic 10380..1039F; Ugaritic 103A0..103DF; Old Persian 10400..1044F; Deseret 10450..1047F; Shavian 10480..104AF; Osmanya 104B0..104FF; Osage 10500..1052F; Elbasan 10530..1056F; Caucasian Albanian 10570..105BF; Vithkuqi 10600..1077F; Linear A 10780..107BF; Latin Extended-F 10800..1083F; Cypriot Syllabary 10840..1085F; Imperial Aramaic 10860..1087F; Palmyrene 10880..108AF; Nabataean 108E0..108FF; Hatran 10900..1091F; Phoenician 10920..1093F; Lydian 10980..1099F; Meroitic Hieroglyphs 109A0..109FF; Meroitic Cursive 10A00..10A5F; Kharoshthi 10A60..10A7F; Old South Arabian 10A80..10A9F; Old North Arabian 10AC0..10AFF; Manichaean 10B00..10B3F; Avestan 10B40..10B5F; Inscriptional Parthian 10B60..10B7F; Inscriptional Pahlavi 10B80..10BAF; Psalter Pahlavi 10C00..10C4F; Old Turkic 10C80..10CFF; Old Hungarian 10D00..10D3F; Hanifi Rohingya 10E60..10E7F; Rumi Numeral Symbols 10E80..10EBF; Yezidi 10F00..10F2F; Old Sogdian 10F30..10F6F; Sogdian 10F70..10FAF; Old Uyghur 10FB0..10FDF; Chorasmian 10FE0..10FFF; Elymaic 11000..1107F; Brahmi 11080..110CF; Kaithi 110D0..110FF; Sora Sompeng 11100..1114F; Chakma 11150..1117F; Mahajani 11180..111DF; Sharada 111E0..111FF; Sinhala Archaic Numbers 11200..1124F; Khojki 11280..112AF; Multani 112B0..112FF; Khudawadi 11300..1137F; Grantha 11400..1147F; Newa 11480..114DF; Tirhuta 11580..115FF; Siddham 11600..1165F; Modi 11660..1167F; Mongolian Supplement 11680..116CF; Takri 11700..1174F; Ahom 11800..1184F; Dogra 118A0..118FF; Warang Citi 11900..1195F; Dives Akuru 119A0..119FF; Nandinagari 11A00..11A4F; Zanabazar Square 11A50..11AAF; Soyombo 11AB0..11ABF; Unified Canadian Aboriginal Syllabics Extended-A 11AC0..11AFF; Pau Cin Hau 11C00..11C6F; Bhaiksuki 11C70..11CBF; Marchen 11D00..11D5F; Masaram Gondi 11D60..11DAF; Gunjala Gondi 11EE0..11EFF; Makasar 11FB0..11FBF; Lisu Supplement 11FC0..11FFF; Tamil Supplement 12000..123FF; Cuneiform 12400..1247F; Cuneiform Numbers and Punctuation 12480..1254F; Early Dynastic Cuneiform 12F90..12FFF; Cypro-Minoan 13000..1342F; Egyptian Hieroglyphs 13430..1343F; Egyptian Hieroglyph Format Controls 14400..1467F; Anatolian Hieroglyphs 16800..16A3F; Bamum Supplement 16A40..16A6F; Mro 16A70..16ACF; Tangsa 16AD0..16AFF; Bassa Vah 16B00..16B8F; Pahawh Hmong 16E40..16E9F; Medefaidrin 16F00..16F9F; Miao 16FE0..16FFF; Ideographic Symbols and Punctuation 17000..187FF; Tangut 18800..18AFF; Tangut Components 18B00..18CFF; Khitan Small Script 18D00..18D7F; Tangut Supplement 1AFF0..1AFFF; Kana Extended-B 1B000..1B0FF; Kana Supplement 1B100..1B12F; Kana Extended-A 1B130..1B16F; Small Kana Extension 1B170..1B2FF; Nushu 1BC00..1BC9F; Duployan 1BCA0..1BCAF; Shorthand Format Controls 1CF00..1CFCF; Znamenny Musical Notation 1D000..1D0FF; Byzantine Musical Symbols 1D100..1D1FF; Musical Symbols 1D200..1D24F; Ancient Greek Musical Notation 1D2E0..1D2FF; Mayan Numerals 1D300..1D35F; Tai Xuan Jing Symbols 1D360..1D37F; Counting Rod Numerals 1D400..1D7FF; Mathematical Alphanumeric Symbols 1D800..1DAAF; Sutton SignWriting 1DF00..1DFFF; Latin Extended-G 1E000..1E02F; Glagolitic Supplement 1E100..1E14F; Nyiakeng Puachue Hmong 1E290..1E2BF; Toto 1E2C0..1E2FF; Wancho 1E7E0..1E7FF; Ethiopic Extended-B 1E800..1E8DF; Mende Kikakui 1E900..1E95F; Adlam 1EC70..1ECBF; Indic Siyaq Numbers 1ED00..1ED4F; Ottoman Siyaq Numbers 1EE00..1EEFF; Arabic Mathematical Alphabetic Symbols 1F000..1F02F; Mahjong Tiles 1F030..1F09F; Domino Tiles 1F0A0..1F0FF; Playing Cards 1F100..1F1FF; Enclosed Alphanumeric Supplement 1F200..1F2FF; Enclosed Ideographic Supplement 1F300..1F5FF; Miscellaneous Symbols and Pictographs 1F600..1F64F; Emoticons 1F650..1F67F; Ornamental Dingbats 1F680..1F6FF; Transport and Map Symbols 1F700..1F77F; Alchemical Symbols 1F780..1F7FF; Geometric Shapes Extended 1F800..1F8FF; Supplemental Arrows-C 1F900..1F9FF; Supplemental Symbols and Pictographs 1FA00..1FA6F; Chess Symbols 1FA70..1FAFF; Symbols and Pictographs Extended-A 1FB00..1FBFF; Symbols for Legacy Computing 20000..2A6DF; CJK Unified Ideographs Extension B 2A700..2B73F; CJK Unified Ideographs Extension C 2B740..2B81F; CJK Unified Ideographs Extension D 2B820..2CEAF; CJK Unified Ideographs Extension E 2CEB0..2EBEF; CJK Unified Ideographs Extension F 2F800..2FA1F; CJK Compatibility Ideographs Supplement 30000..3134F; CJK Unified Ideographs Extension G E0000..E007F; Tags E0100..E01EF; Variation Selectors Supplement F0000..FFFFF; Supplementary Private Use Area-A 100000..10FFFF; Supplementary Private Use Area-B # EOF
10,720
357
jart/cosmopolitan
false
cosmopolitan/libc/str/langinfo.h
#ifndef COSMOPOLITAN_LIBC_STR_LANGINFO_H_ #define COSMOPOLITAN_LIBC_STR_LANGINFO_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #define ABDAY_1 0x20000 #define ABDAY_2 0x20001 #define ABDAY_3 0x20002 #define ABDAY_4 0x20003 #define ABDAY_5 0x20004 #define ABDAY_6 0x20005 #define ABDAY_7 0x20006 #define DAY_1 0x20007 #define DAY_2 0x20008 #define DAY_3 0x20009 #define DAY_4 0x2000A #define DAY_5 0x2000B #define DAY_6 0x2000C #define DAY_7 0x2000D #define ABMON_1 0x2000E #define ABMON_2 0x2000F #define ABMON_3 0x20010 #define ABMON_4 0x20011 #define ABMON_5 0x20012 #define ABMON_6 0x20013 #define ABMON_7 0x20014 #define ABMON_8 0x20015 #define ABMON_9 0x20016 #define ABMON_10 0x20017 #define ABMON_11 0x20018 #define ABMON_12 0x20019 #define MON_1 0x2001A #define MON_2 0x2001B #define MON_3 0x2001C #define MON_4 0x2001D #define MON_5 0x2001E #define MON_6 0x2001F #define MON_7 0x20020 #define MON_8 0x20021 #define MON_9 0x20022 #define MON_10 0x20023 #define MON_11 0x20024 #define MON_12 0x20025 #define AM_STR 0x20026 #define PM_STR 0x20027 #define D_T_FMT 0x20028 #define D_FMT 0x20029 #define T_FMT 0x2002A #define T_FMT_AMPM 0x2002B #define ERA 0x2002C #define ERA_D_FMT 0x2002E #define ALT_DIGITS 0x2002F #define ERA_D_T_FMT 0x20030 #define ERA_T_FMT 0x20031 #define CODESET 14 #define CRNCYSTR 0x4000F #define RADIXCHAR 0x10000 #define THOUSEP 0x10001 #define YESEXPR 0x50000 #define NOEXPR 0x50001 #define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff) #if defined(_GNU_SOURCE) #define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat) #endif #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #define YESSTR 0x50002 #define NOSTR 0x50003 #endif char *nl_langinfo(int); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_LANGINFO_H_ */
1,874
87
jart/cosmopolitan
false
cosmopolitan/libc/str/strncasecmp.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" #include "libc/str/tab.internal.h" /** * Compares NUL-terminated strings case-insensitively w/ limit. * * @param a is first non-null NUL-terminated string pointer * @param b is second non-null NUL-terminated string pointer * @return is <0, 0, or >0 based on uint8_t comparison * @asyncsignalsafe */ int strncasecmp(const char *a, const char *b, size_t n) { int x, y; size_t i = 0; if (!n-- || a == b) return 0; while ((x = kToLower[a[i] & 0xff]) == (y = kToLower[b[i] & 0xff]) && b[i] && i < n) { ++i; } return x - y; }
2,415
40
jart/cosmopolitan
false
cosmopolitan/libc/str/kmonthyearday.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/time/time.h" _Hide const unsigned short kMonthYearDay[2][12] = { {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}, };
2,042
25
jart/cosmopolitan
false
cosmopolitan/libc/str/tolower.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Converts character to ascii lower case. */ int tolower(int c) { return 'A' <= c && c <= 'Z' ? c + ('a' - 'A') : c; }
1,990
27
jart/cosmopolitan
false
cosmopolitan/libc/str/strchr16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns pointer to first instance of character. */ char16_t *strchr16(const char16_t *s, int c) { for (;; ++s) { if ((*s & 65535) == (c & 65535)) return (char16_t *)s; if (!*s) return (char16_t *)0; } }
2,086
30
jart/cosmopolitan
false
cosmopolitan/libc/str/towupper_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" wint_t towupper_l(wint_t c, locale_t l) { return towupper(c); }
1,958
25
jart/cosmopolitan
false
cosmopolitan/libc/str/strrchr16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Searches for last instance of char16_t in string. * * @param s is NUL-terminated char16_t string to search * @param c is treated as char16_t * @return address of last c in s, or NULL if not found * @asyncsignalsafe */ char16_t *strrchr16(const char16_t *s, int c) { return memrchr16(s, c, strlen16(s)); }
2,183
32
jart/cosmopolitan
false
cosmopolitan/libc/str/hexpcpy.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Turns data into lowercase hex. * * This routine always writes a nul terminator, even if `n` is zero. * There's no failure condition for this function. * * @param s must have `n*2+1` bytes * @param p must have `n` bytes * @param n is byte length of p * @return pointer to nul byte in `s` */ char *hexpcpy(char *restrict s, const void *restrict p, size_t n) { const char *d, *e; for (d = p, e = d + n; d < e; ++d) { *s++ = "0123456789abcdef"[(*d >> 4) & 15]; *s++ = "0123456789abcdef"[(*d >> 0) & 15]; } *s = 0; return s; }
2,419
41
jart/cosmopolitan
false
cosmopolitan/libc/str/strcasestr.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/str/tab.internal.h" typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); /** * Searches for substring case-insensitively. * * @param haystack is the search area, as a NUL-terminated string * @param needle is the desired substring, also NUL-terminated * @return pointer to first substring within haystack, or NULL * @note this implementation goes fast in practice but isn't hardened * against pathological cases, and therefore shouldn't be used on * untrustworthy data * @asyncsignalsafe * @see strstr() */ noasan char *strcasestr(const char *haystack, const char *needle) { #ifdef __x86_64__ char c; xmm_t *p; size_t i; unsigned k, m; xmm_t v, n1, n2, z = {0}; if (IsAsan()) __asan_verify(needle, 1); if (IsAsan()) __asan_verify(haystack, 1); if (haystack == needle || !*needle) return haystack; c = *needle; n1 = (xmm_t){c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; c = kToLower[c & 255]; n2 = (xmm_t){c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; for (;;) { k = (uintptr_t)haystack & 15; p = (const xmm_t *)((uintptr_t)haystack & -16); v = *p; m = __builtin_ia32_pmovmskb128((v == z) | (v == n1) | (v == n2)); m >>= k; m <<= k; while (!m) { v = *++p; m = __builtin_ia32_pmovmskb128((v == z) | (v == n1) | (v == n2)); } haystack = (const char *)p + __builtin_ctzl(m); for (i = 0;; ++i) { if (!needle[i]) return (/*unconst*/ char *)haystack; if (!haystack[i]) break; if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break; } if (!*haystack++) break; } return 0; #else size_t i; unsigned k, m; if (haystack == needle || !*needle) return haystack; for (;;) { for (i = 0;; ++i) { if (!needle[i]) return (/*unconst*/ char *)haystack; if (!haystack[i]) break; if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break; } if (!*haystack++) break; } return 0; #endif }
3,922
87
jart/cosmopolitan
false
cosmopolitan/libc/str/wcsncasecmp.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Compares NUL-terminated wide strings case-insensitively w/ limit. * * @param a is first non-null NUL-terminated string pointer * @param b is second non-null NUL-terminated string pointer * @return is <0, 0, or >0 based on uint8_t comparison * @asyncsignalsafe */ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) { size_t i = 0; unsigned x, y; if (!n-- || a == b) return 0; while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i] && i < n) ++i; return x - y; }
2,363
36
jart/cosmopolitan
false
cosmopolitan/libc/str/wcwidth_osx.internal.h
#ifndef COSMOPOLITAN_LIBC_STR_WCWIDTH_OSX_H_ #define COSMOPOLITAN_LIBC_STR_WCWIDTH_OSX_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ extern const uint32_t kWcwidthOsx[591]; extern const uint8_t kWcwidthOsxIndex1[136]; extern const uint16_t kWcwidthOsxIndex2[228]; extern const uint32_t kWcwidthOsxIndex3[917]; static inline int _wcwidth_osx(uint32_t codePoint) { uint32_t a, b, c, d; a = kWcwidthOsxIndex1[codePoint >> 13]; b = kWcwidthOsxIndex2[a + ((codePoint >> 9) & 0xf)]; c = kWcwidthOsxIndex3[b + ((codePoint >> 5) & 0xf)]; d = c + (codePoint & 0x1f); return (kWcwidthOsx[d >> 4] >> ((d & 0xf) << 1)) & 3; } COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_WCWIDTH_OSX_H_ */
763
23
jart/cosmopolitan
false
cosmopolitan/libc/str/strntoupper.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Mutates string to ASCII uppercase w/ limit. * * @praam s is string * @praam n is max bytes to consider * @return string */ char *strntoupper(char *s, size_t n) { size_t i; for (i = 0; s[i] && i < n; ++i) { if ('a' <= s[i] && s[i] <= 'z') { s[i] -= 'a' - 'A'; } } return s; }
2,172
37
jart/cosmopolitan
false
cosmopolitan/libc/str/uselocale.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/sysv/errfuns.h" locale_t uselocale(locale_t l) { // TODO: implement me! return 0; }
1,969
26
jart/cosmopolitan
false
cosmopolitan/libc/str/strnlen_s.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/str/str.h" static noasan size_t strnlen_s_x64(const char *s, size_t n, size_t i) { uint64_t w; for (; i + 8 < n; i += 8) { w = *(uint64_t *)(s + i); if ((w = ~w & (w - 0x0101010101010101) & 0x8080808080808080)) { i += (unsigned)__builtin_ctzll(w) >> 3; break; } } return i; } /** * Returns length of NUL-terminated string... securely. * * This is like strnlen() except it'll return 0 if `s` is null. We also * make the assumption for the purposes of ASAN that `n` is the size of * the buffer if `s` is non-null. * * @param s is string * @param n is max length * @return byte length * @asyncsignalsafe */ noasan size_t strnlen_s(const char *s, size_t n) { size_t i; if (!s) return 0; if (IsAsan()) __asan_verify(s, n); for (i = 0; (uintptr_t)(s + i) & 7; ++i) { if (i == n || !s[i]) return i; } i = strnlen_s_x64(s, n, i); for (;; ++i) { if (i == n || !s[i]) break; } _unassert(i == n || (i < n && !s[i])); return i; }
2,928
62
jart/cosmopolitan
false
cosmopolitan/libc/str/memcasecmp.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/str/str.h" #include "libc/str/tab.internal.h" /** * Compares memory case-insensitively. * * memcasecmp n=0 992 picoseconds * memcasecmp n=1 1 ns/byte 590 mb/s * memcasecmp n=2 1 ns/byte 843 mb/s * memcasecmp n=3 1 ns/byte 885 mb/s * memcasecmp n=4 1 ns/byte 843 mb/s * memcasecmp n=5 1 ns/byte 820 mb/s * memcasecmp n=6 1 ns/byte 770 mb/s * memcasecmp n=7 1 ns/byte 765 mb/s * memcasecmp n=8 206 ps/byte 4,724 mb/s * memcasecmp n=9 220 ps/byte 4,428 mb/s * memcasecmp n=15 617 ps/byte 1,581 mb/s * memcasecmp n=16 124 ps/byte 7,873 mb/s * memcasecmp n=17 155 ps/byte 6,274 mb/s * memcasecmp n=31 341 ps/byte 2,860 mb/s * memcasecmp n=32 82 ps/byte 11,810 mb/s * memcasecmp n=33 100 ps/byte 9,743 mb/s * memcasecmp n=80 53 ps/byte 18,169 mb/s * memcasecmp n=128 49 ps/byte 19,890 mb/s * memcasecmp n=256 45 ps/byte 21,595 mb/s * memcasecmp n=16384 42 ps/byte 22,721 mb/s * memcasecmp n=32768 40 ps/byte 24,266 mb/s * memcasecmp n=131072 40 ps/byte 24,337 mb/s * * @return is <0, 0, or >0 based on uint8_t comparison */ int memcasecmp(const void *p, const void *q, size_t n) { int c; size_t i; unsigned u; uint64_t w; const unsigned char *a, *b; if ((a = p) != (b = q)) { for (i = 0; i < n; ++i) { while (i + 8 <= n) { if ((w = (((uint64_t)a[0] << 000 | (uint64_t)a[1] << 010 | (uint64_t)a[2] << 020 | (uint64_t)a[3] << 030 | (uint64_t)a[4] << 040 | (uint64_t)a[5] << 050 | (uint64_t)a[6] << 060 | (uint64_t)a[7] << 070) ^ ((uint64_t)b[0] << 000 | (uint64_t)b[1] << 010 | (uint64_t)b[2] << 020 | (uint64_t)b[3] << 030 | (uint64_t)b[4] << 040 | (uint64_t)b[5] << 050 | (uint64_t)b[6] << 060 | (uint64_t)b[7] << 070)))) { u = __builtin_ctzll(w); i += u >> 3; break; } else { i += 8; } } if (i == n) { break; } else if ((c = kToLower[a[i]] - kToLower[b[i]])) { return c; } } } return 0; }
4,680
84
jart/cosmopolitan
false
cosmopolitan/libc/str/wcscspn.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** * 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 wcscspn(const wchar_t *s, const wchar_t *reject) { size_t i; for (i = 0; s[i]; ++i) { if (HasCharacterWide(s[i], reject)) { break; } } return i; }
2,315
39
jart/cosmopolitan
false
cosmopolitan/libc/str/isdirsep.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/str/str.h" /** * Returns true if character is directory separator slash. */ bool _isdirsep(int c) { return c == '/' || c == '\\'; }
2,010
28
jart/cosmopolitan
false
cosmopolitan/libc/str/getzipcdir.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/zip.h" typedef char v16qi __attribute__((__vector_size__(16))); typedef short v8hi __attribute__((__vector_size__(16))); typedef long long v2di __attribute__((__vector_size__(16), __aligned__(1))); /** * Locates End Of Central Directory record in ZIP file. * * The ZIP spec says this header can be anywhere in the last 64kb. We * search it backwards for the ZIP-64 "PK♠•" magic number. If that's not * found, then we search again for the original "PK♣♠" magnum. The * caller needs to check the first four bytes of the returned value to * determine whether to use ZIP_CDIR_xxx() or ZIP_CDIR64_xxx() macros. * * @param p points to file memory * @param n is byte size of file * @return pointer to EOCD64 or EOCD, or NULL if not found */ void *GetZipCdir(const uint8_t *p, size_t n) { v2di x; size_t i, j; uint32_t magic; i = n - 4; do { #ifdef __x86_64__ v8hi pk = {READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK")}; asm("" : "+x"(pk)); if (i >= 14) { x = *(const v2di *)(p + i - 14); if (!(__builtin_ia32_pmovmskb128( (v16qi)__builtin_ia32_pcmpeqw128((v8hi)x, pk)) | __builtin_ia32_pmovmskb128((v16qi)__builtin_ia32_pcmpeqw128( (v8hi)__builtin_ia32_psrldqi128(x, 8), pk)))) { i -= 13; continue; } } #endif while (magic = READ32LE(p + i), magic != kZipCdir64LocatorMagic && magic != kZipCdirHdrMagic && i + 0x10000 + 0x1000 >= n && i > 0) { --i; } if (magic == kZipCdir64LocatorMagic && i + kZipCdir64LocatorSize <= n && IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + i))) { return p + ZIP_LOCATE64_OFFSET(p + i); } else if (magic == kZipCdirHdrMagic && IsZipCdir32(p, n, i)) { j = i; do { if (READ32LE(p + j) == kZipCdir64LocatorMagic && j + kZipCdir64LocatorSize <= n && IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + j))) { return p + ZIP_LOCATE64_OFFSET(p + j); } } while (j-- && i - j < 128); return p + i; } } while (i > 0 && i-- + 0x10000 + 0x1000 >= n); return 0; }
4,159
82
jart/cosmopolitan
false
cosmopolitan/libc/str/strncpy.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Prepares static search buffer. * * 1. If SRC is too long, it's truncated and *not* NUL-terminated. * 2. If SRC is too short, the remainder is zero-filled. * * Please note this function isn't designed to prevent untrustworthy * data from modifying memory without authorization; the memccpy() * function can be used for that purpose. * * Here's an example of the only use case we know of for strncpy: * * static const struct People { * char name[8]; * int age; * } kPeople[] = { * {"alice", 29}, // * {"bob", 42}, // * }; * * int GetAge(const char *name) { * char k[8]; * int m, l, r; * l = 0; * r = ARRAYLEN(kPeople) - 1; * strncpy(k, name, 8); * while (l <= r) { * m = (l + r) >> 1; * if (READ64BE(kPeople[m].name) < READ64BE(k)) { * l = m + 1; * } else if (READ64BE(kPeople[m].name) > READ64BE(k)) { * r = m - 1; * } else { * return kPeople[m].age; * } * } * return -1; * } * * @return dest * @see stpncpy(), memccpy() * @asyncsignalsafe * @vforksafe */ char *strncpy(char *dest, const char *src, size_t stride) { size_t i; for (i = 0; i < stride; ++i) { if (!(dest[i] = src[i])) break; } bzero(dest + i, stride - i); return dest; }
3,230
73
jart/cosmopolitan
false
cosmopolitan/libc/str/mbsrtowcs.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╚──────────────────────────────────────────────────────────────────────────────╝ │ │ │ Musl Libc │ │ Copyright © 2005-2014 Rich Felker, et al. │ │ │ │ Permission is hereby granted, free of charge, to any person obtaining │ │ a copy of this software and associated documentation files (the │ │ "Software"), to deal in the Software without restriction, including │ │ without limitation the rights to use, copy, modify, merge, publish, │ │ distribute, sublicense, and/or sell copies of the Software, and to │ │ permit persons to whom the Software is furnished to do so, subject to │ │ the following conditions: │ │ │ │ The above copyright notice and this permission notice shall be │ │ included in all copies or substantial portions of the Software. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ │ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ │ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │ │ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │ │ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/str/mb.internal.h" #include "libc/str/str.h" asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) { const unsigned char *s = (const void *)*src; size_t wn0 = wn; unsigned c = 0; if (st && (c = *(unsigned *)st)) { if (ws) { *(unsigned *)st = 0; goto resume; } else { goto resume0; } } if (MB_CUR_MAX == 1) { if (!ws) return strlen((const char *)s); for (;;) { if (!wn) { *src = (const void *)s; return wn0; } if (!*s) break; c = *s++; *ws++ = CODEUNIT(c); wn--; } *ws = 0; *src = 0; return wn0 - wn; } if (!ws) for (;;) { if (*s - 1u < 0x7f) { s++; wn--; continue; } if (*s - SA > SB - SA) break; c = kMbBittab[*s++ - SA]; resume0: if (OOB(c, *s)) { s--; break; } s++; if (c & (1U << 25)) { if (*s - 0x80u >= 0x40) { s -= 2; break; } s++; if (c & (1U << 19)) { if (*s - 0x80u >= 0x40) { s -= 3; break; } s++; } } wn--; c = 0; } else for (;;) { if (!wn) { *src = (const void *)s; return wn0; } if (*s - 1u < 0x7f) { *ws++ = *s++; wn--; continue; } if (*s - SA > SB - SA) break; c = kMbBittab[*s++ - SA]; resume: if (OOB(c, *s)) { s--; break; } c = (c << 6) | *s++ - 0x80; if (c & (1U << 31)) { if (*s - 0x80u >= 0x40) { s -= 2; break; } c = (c << 6) | *s++ - 0x80; if (c & (1U << 31)) { if (*s - 0x80u >= 0x40) { s -= 3; break; } c = (c << 6) | *s++ - 0x80; } } *ws++ = c; wn--; c = 0; } if (!c && !*s) { if (ws) { *ws = 0; *src = 0; } return wn0 - wn; } errno = EILSEQ; if (ws) *src = (const void *)s; return -1; }
4,931
147
jart/cosmopolitan
false
cosmopolitan/libc/str/iswxdigit.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is ascii hex digit. */ int iswxdigit(wint_t c) { return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); }
2,037
28
jart/cosmopolitan
false
cosmopolitan/libc/str/strstr16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Searches for substring. * * @param haystack is the search area, as a NUL-terminated string * @param needle is the desired substring, also NUL-terminated * @return pointer to first substring within haystack, or NULL * @asyncsignalsafe * @see memmem() */ char16_t *strstr16(const char16_t *haystack, const char16_t *needle) { size_t i; for (;;) { for (i = 0;;) { if (!needle[i]) return (/*unconst*/ char16_t *)haystack; if (!haystack[i]) break; if (needle[i] != haystack[i]) break; ++i; } if (!*haystack++) break; } return NULL; }
2,450
43
jart/cosmopolitan
false
cosmopolitan/libc/str/wcsncpy.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) { wchar_t *a; for (a = d; n && *s; --n) { *d++ = *s++; } wmemset(d, 0, n); return a; }
2,021
29
jart/cosmopolitan
false
cosmopolitan/libc/str/intsort.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/strace.internal.h" #include "libc/runtime/runtime.h" static inline void InsertionSort(int *A, long n) { long i, j, t; for (i = 1; i < n; i++) { t = A[i]; j = i - 1; while (j >= 0 && A[j] > t) { A[j + 1] = A[j]; j = j - 1; } A[j + 1] = t; } } static void IntSort(int *A, long n) { int t, p; long i, j; if (n <= 32) { InsertionSort(A, n); } else { for (p = A[n >> 1], i = 0, j = n - 1;; i++, j--) { while (A[i] < p) i++; while (A[j] > p) j--; if (i >= j) break; t = A[i]; A[i] = A[j]; A[j] = t; } IntSort(A, i); IntSort(A + i, n - i); } } /** * Tiny and reasonably fast sorting for ints. * @see djbsort */ void _intsort(int *A, size_t n) { IntSort(A, n); if (n > 1000) { STRACE("_intsort(%p, %'zu)", A, n); } }
2,687
64
jart/cosmopolitan
false
cosmopolitan/libc/str/isabspath.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/path.h" #include "libc/str/str.h" /** * Returns true if pathname is considered absolute. * * - `/home/jart/foo.txt` is absolute * - `C:/Users/jart/foo.txt` is absolute on Windows * - `C:\Users\jart\foo.txt` is absolute on Windows * - `\??\C:\Users\jart\foo.txt` is absolute on Windows * - `\\.\C:\Users\jart\foo.txt` is absolute on Windows * - `/Users/jart/foo.txt` is effectively absolute on Windows * - `\Users\jart\foo.txt` is effectively absolute on Windows * */ bool _isabspath(const char *path) { return _classifypath(path) & _kPathAbs; }
2,414
37
jart/cosmopolitan
false
cosmopolitan/libc/str/wcsstr.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Searches for substring. * * @param haystack is the search area, as a NUL-terminated string * @param needle is the desired substring, also NUL-terminated * @return pointer to first substring within haystack, or NULL * @asyncsignalsafe * @see memmem() */ wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle) { size_t i; for (;;) { for (i = 0;;) { if (!needle[i]) return (/*unconst*/ wchar_t *)haystack; if (!haystack[i]) break; if (needle[i] != haystack[i]) break; ++i; } if (!*haystack++) break; } return NULL; }
2,444
43
jart/cosmopolitan
false
cosmopolitan/libc/str/iswctype.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" #include "libc/str/str.h" typedef int (*isw_f)(wint_t); static const isw_f kWcTypeFuncs[] = { iswalnum, // iswalpha, // iswblank, // iswcntrl, // iswdigit, // iswgraph, // iswlower, // iswprint, // iswpunct, // iswspace, // iswupper, // iswxdigit, // }; /** * Returns nonzero if c has property. * * @param t is number returned by wctype */ int iswctype(wint_t c, wctype_t t) { if (1 <= t && t <= ARRAYLEN(kWcTypeFuncs)) { return kWcTypeFuncs[t - 1](c); } else { return 0; } }
2,438
51
jart/cosmopolitan
false
cosmopolitan/libc/str/wcstombs.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" size_t wcstombs(char *s, const wchar_t *ws, size_t n) { return wcsrtombs(s, &(const wchar_t *){ws}, n, 0); }
1,974
24
jart/cosmopolitan
false
cosmopolitan/libc/str/c32rtomb.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" size_t c32rtomb(char *s, char32_t c, mbstate_t *t) { return wcrtomb(s, c, t); }
1,945
24
jart/cosmopolitan
false
cosmopolitan/libc/str/strcasecmp16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Compares NUL-terminated UCS-2 strings case-insensitively. * * @param a is first non-null NUL-terminated char16 string pointer * @param b is second non-null NUL-terminated char16 string pointer * @return is <0, 0, or >0 based on uint16_t comparison * @asyncsignalsafe */ int strcasecmp16(const char16_t *l, const char16_t *r) { int x, y; size_t i = 0; while ((x = towlower(l[i])) == (y = towlower(r[i])) && r[i]) ++i; return x - y; }
2,317
35
jart/cosmopolitan
false
cosmopolitan/libc/str/mbtowc.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╚──────────────────────────────────────────────────────────────────────────────╝ │ │ │ Musl Libc │ │ Copyright © 2005-2014 Rich Felker, et al. │ │ │ │ Permission is hereby granted, free of charge, to any person obtaining │ │ a copy of this software and associated documentation files (the │ │ "Software"), to deal in the Software without restriction, including │ │ without limitation the rights to use, copy, modify, merge, publish, │ │ distribute, sublicense, and/or sell copies of the Software, and to │ │ permit persons to whom the Software is furnished to do so, subject to │ │ the following conditions: │ │ │ │ The above copyright notice and this permission notice shall be │ │ included in all copies or substantial portions of the Software. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ │ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ │ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │ │ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │ │ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/limits.h" #include "libc/str/mb.internal.h" #include "libc/str/str.h" asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n) { unsigned c; const unsigned char *s = (const void *)src; wchar_t dummy; if (!s) return 0; if (!n) goto ilseq; if (!wc) wc = &dummy; if (*s < 0x80) return !!(*wc = *s); if (MB_CUR_MAX == 1) return (*wc = CODEUNIT(*s)), 1; if (*s - SA > SB - SA) goto ilseq; c = kMbBittab[*s++ - SA]; /* Avoid excessive checks against n: If shifting the state n-1 * times does not clear the high bit, then the value of n is * insufficient to read a character */ if (n < 4 && ((c << (6 * n - 6)) & (1U << 31))) goto ilseq; if (OOB(c, *s)) goto ilseq; c = c << 6 | *s++ - 0x80; if (!(c & (1U << 31))) { *wc = c; return 2; } if (*s - 0x80u >= 0x40) goto ilseq; c = c << 6 | *s++ - 0x80; if (!(c & (1U << 31))) { *wc = c; return 3; } if (*s - 0x80u >= 0x40) goto ilseq; *wc = c << 6 | *s++ - 0x80; return 4; ilseq: errno = EILSEQ; return -1; }
3,814
72
jart/cosmopolitan
false
cosmopolitan/libc/str/mbrtoc32.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╚──────────────────────────────────────────────────────────────────────────────╝ │ │ │ Musl Libc │ │ Copyright © 2005-2014 Rich Felker, et al. │ │ │ │ Permission is hereby granted, free of charge, to any person obtaining │ │ a copy of this software and associated documentation files (the │ │ "Software"), to deal in the Software without restriction, including │ │ without limitation the rights to use, copy, modify, merge, publish, │ │ distribute, sublicense, and/or sell copies of the Software, and to │ │ permit persons to whom the Software is furnished to do so, subject to │ │ the following conditions: │ │ │ │ The above copyright notice and this permission notice shall be │ │ included in all copies or substantial portions of the Software. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ │ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ │ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │ │ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │ │ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/str/str.h" asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); size_t mbrtoc32(char32_t *pc32, const char *s, size_t n, mbstate_t *ps) { static unsigned internal_state; if (!ps) ps = (void *)&internal_state; if (!s) return mbrtoc32(0, "", 1, ps); wchar_t wc; size_t ret = mbrtowc(&wc, s, n, ps); if (ret <= 4 && pc32) *pc32 = wc; return ret; }
3,146
47
jart/cosmopolitan
false
cosmopolitan/libc/str/timingsafe_bcmp.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/likely.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/str.h" typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1))); noasan static unsigned timingsafe_bcmp_sse(const char *p, const char *q, size_t n) { uint64_t w; xmm_t a = {0}; while (n > 16 + 16) { a |= *(const xmm_t *)p ^ *(const xmm_t *)q; p += 16; q += 16; n -= 16; } a |= *(const xmm_t *)p ^ *(const xmm_t *)q; a |= *(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16); w = a[0] | a[1]; return w | w >> 32; } #ifdef __x86_64__ noasan static microarchitecture("avx") int timingsafe_bcmp_avx(const char *p, const char *q, size_t n) { uint64_t w; xmm_t a = {0}; if (n > 32) { if (n >= 16 + 64) { xmm_t b = {0}; xmm_t c = {0}; xmm_t d = {0}; do { a |= ((const xmm_t *)p)[0] ^ ((const xmm_t *)q)[0]; b |= ((const xmm_t *)p)[1] ^ ((const xmm_t *)q)[1]; c |= ((const xmm_t *)p)[2] ^ ((const xmm_t *)q)[2]; d |= ((const xmm_t *)p)[3] ^ ((const xmm_t *)q)[3]; p += 64; q += 64; n -= 64; } while (n >= 16 + 64); a = a | b | c | d; } while (n > 32) { a |= *(const xmm_t *)p ^ *(const xmm_t *)q; p += 16; q += 16; n -= 16; } } a |= *(const xmm_t *)p ^ *(const xmm_t *)q; a |= *(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16); w = a[0] | a[1]; return w | w >> 32; } #endif /** * Tests inequality of first 𝑛 bytes of 𝑝 and 𝑞. * * The following expression: * * !!timingsafe_bcmp(p, q, n) * * Is functionally equivalent to: * * !!memcmp(p, q, n) * * This function is faster than memcmp() and bcmp() when byte sequences * are assumed to always be the same; that makes it best for assertions * or hash table lookups, assuming 𝑛 is variable (since no gcc builtin) * * timingsafe_bcmp n=0 992 picoseconds * timingsafe_bcmp n=1 1 ns/byte 738 mb/s * timingsafe_bcmp n=2 826 ps/byte 1,181 mb/s * timingsafe_bcmp n=3 661 ps/byte 1,476 mb/s * timingsafe_bcmp n=4 330 ps/byte 2,952 mb/s * timingsafe_bcmp n=5 264 ps/byte 3,690 mb/s * timingsafe_bcmp n=6 220 ps/byte 4,428 mb/s * timingsafe_bcmp n=7 189 ps/byte 5,166 mb/s * timingsafe_bcmp n=8 124 ps/byte 7,873 mb/s * timingsafe_bcmp n=9 147 ps/byte 6,643 mb/s * timingsafe_bcmp n=15 88 ps/byte 11,072 mb/s * timingsafe_bcmp n=16 62 ps/byte 15,746 mb/s * timingsafe_bcmp n=17 136 ps/byte 7,170 mb/s * timingsafe_bcmp n=31 74 ps/byte 13,075 mb/s * timingsafe_bcmp n=32 72 ps/byte 13,497 mb/s * timingsafe_bcmp n=33 80 ps/byte 12,179 mb/s * timingsafe_bcmp n=80 57 ps/byte 16,871 mb/s * timingsafe_bcmp n=128 49 ps/byte 19,890 mb/s * timingsafe_bcmp n=256 31 ps/byte 31,493 mb/s * timingsafe_bcmp n=16384 14 ps/byte 67,941 mb/s * timingsafe_bcmp n=32768 29 ps/byte 33,121 mb/s * timingsafe_bcmp n=131072 29 ps/byte 32,949 mb/s * * Running time is independent of the byte sequences compared, making * this safe to use for comparing secret values such as cryptographic * MACs. In contrast, memcmp() may short-circuit after finding the first * differing byte. * * @return nonzero if unequal, otherwise zero * @see timingsafe_memcmp() * @asyncsignalsafe */ int timingsafe_bcmp(const void *a, const void *b, size_t n) { const char *p = a, *q = b; uint32_t u, u0, u1, u2, u3; uint64_t w, w0, w1, w2, w3; if (!IsTiny()) { if (n >= 8) { if (n <= 16) { __builtin_memcpy(&w0, p, 8); __builtin_memcpy(&w1, q, 8); __builtin_memcpy(&w2, p + n - 8, 8); __builtin_memcpy(&w3, q + n - 8, 8); w = (w0 ^ w1) | (w2 ^ w3); return w | w >> 32; } else { if (IsAsan()) { __asan_verify(a, n); __asan_verify(b, n); } #ifdef __x86_64__ if (X86_HAVE(AVX)) { return timingsafe_bcmp_avx(p, q, n); } #endif return timingsafe_bcmp_sse(p, q, n); } } else if (n >= 4) { __builtin_memcpy(&u0, p, 4); __builtin_memcpy(&u1, q, 4); __builtin_memcpy(&u2, p + n - 4, 4); __builtin_memcpy(&u3, q + n - 4, 4); return (u0 ^ u1) | (u2 ^ u3); } } for (u = 0; n--;) { u |= p[n] ^ q[n]; } return u; }
6,911
164
jart/cosmopolitan
false
cosmopolitan/libc/str/djbsort.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/runtime/runtime.h" void djbsort_avx2(int32_t *, long); /** * D.J. Bernstein's outrageously fast integer sorting algorithm. */ void djbsort(int32_t *a, size_t n) { size_t m; if (IsAsan()) { if (__builtin_mul_overflow(n, 4, &m)) m = -1; __asan_verify(a, m); } if (n > 1) { #ifdef __x86_64__ if (X86_HAVE(AVX2)) { djbsort_avx2(a, n); } else { _intsort(a, n); } #else _intsort(a, n); #endif /* __x86_64__ */ } }
2,409
47
jart/cosmopolitan
false
cosmopolitan/libc/str/wcwidth.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/likely.h" #include "libc/str/str.h" #include "libc/str/unicode.h" #include "libc/str/wcwidth_osx.internal.h" extern const uint8_t kEastAsianWidth[]; extern const uint32_t kEastAsianWidthBits; extern const uint8_t kCombiningChars[]; extern const uint32_t kCombiningCharsBits; /** * Returns cell width of monospace character. */ int wcwidth(wchar_t c) { #ifdef __x86_64__ if (LIKELY(32 <= c && c < 127)) { return 1; } else if (!c) { return 0; } else if ((uint32_t)c > 0x10FFFD || // (0 < c && c < 32) || // (0x7f <= c && c < 0xA0)) { return -1; } else if ((0 <= c && c < kCombiningCharsBits) && !!(kCombiningChars[c >> 3] & (1 << (c & 7)))) { return 0; } else if (0 <= c && c < kEastAsianWidthBits) { return 1 + !!(kEastAsianWidth[c >> 3] & (1 << (c & 7))); } else { return 1; } #else int res; if (LIKELY(32 <= c && c < 127)) return 1; if (VERY_UNLIKELY((uint32_t)c >= 0x100000)) { if ((uint32_t)c <= 0x10FFFD) return 1; return -1; } res = _wcwidth_osx(c); if (VERY_UNLIKELY(!res)) { if (!c) return 0; if (iswcntrl(c)) return -1; } return res; #endif }
3,029
65
jart/cosmopolitan
false
cosmopolitan/libc/str/getzipcdircomment.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/zip.h" /** * Returns comment of zip central directory. */ void *GetZipCdirComment(const uint8_t *eocd) { if (READ32LE(eocd) == kZipCdir64HdrMagic && ZIP_CDIR64_COMMENTSIZE(eocd)) { return ZIP_CDIR64_COMMENT(eocd); } else { return ZIP_CDIR_COMMENT(eocd); } }
2,126
31
jart/cosmopolitan
false
cosmopolitan/libc/str/strwidth.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/strwidth.h" /** * Returns monospace display width of UTF-8 string. * * - Control codes are discounted * - ANSI escape sequences are discounted * - East asian glyphs, emoji, etc. count as two * * @param s is NUL-terminated string * @param o is string offset for computing tab widths * @return monospace display width */ int strwidth(const char *s, size_t o) { return strnwidth(s, -1, 0); }
2,257
35
jart/cosmopolitan
false
cosmopolitan/libc/str/unicode.h
#ifndef COSMOPOLITAN_LIBC_STR_UNICODE_H_ #define COSMOPOLITAN_LIBC_STR_UNICODE_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ struct lconv { char *decimal_point; char *thousands_sep; char *grouping; char *int_curr_symbol; char *currency_symbol; char *mon_decimal_point; char *mon_thousands_sep; char *mon_grouping; char *positive_sign; char *negative_sign; char int_frac_digits; char frac_digits; char p_cs_precedes; char p_sep_by_space; char n_cs_precedes; char n_sep_by_space; char p_sign_posn; char n_sign_posn; char int_p_cs_precedes; char int_n_cs_precedes; char int_p_sep_by_space; char int_n_sep_by_space; char int_p_sign_posn; char int_n_sign_posn; }; int wcwidth(wchar_t) pureconst; int wcswidth(const wchar_t *, size_t) strlenesque; int wcsnwidth(const wchar_t *, size_t, int) strlenesque; struct lconv *localeconv(void); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_UNICODE_H_ */
1,012
41
jart/cosmopolitan
false
cosmopolitan/libc/str/wcsnlen.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns length of NUL-terminated wide string w/ limit. * * @param s is wide string * @param n is max length (a count of wide characters, not bytes) * @return length in characters * @asyncsignalsafe */ size_t wcsnlen(const wchar_t *s, size_t n) { wchar_t *p; if ((p = wmemchr(s, 0, n))) { return p - s; } else { return n; } }
2,217
37
jart/cosmopolitan
false
cosmopolitan/libc/str/iswxdigit_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int iswxdigit_l(wint_t c, locale_t l) { return iswxdigit(c); }
1,957
25
jart/cosmopolitan
false
cosmopolitan/libc/str/iswprint.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns nonzero if c is printable. */ int iswprint(wint_t c) { return !((0x00 <= c && c <= 0x1F) || (0x7F <= c && c <= 0x9F) || (0xFFF9 <= c && c <= 0xFFFB) || c == 0x2028 || c == 0x2029); }
2,075
28
jart/cosmopolitan
false
cosmopolitan/libc/str/path.h
#ifndef COSMOPOLITAN_LIBC_STR_PATH_H_ #define COSMOPOLITAN_LIBC_STR_PATH_H_ #define _kPathAbs 1 #define _kPathDev 2 #define _kPathRoot 4 #define _kPathDos 8 #define _kPathWin 16 #define _kPathNt 32 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ int _classifypath(const char *) libcesque nosideeffect; bool _isabspath(const char *) libcesque strlenesque; bool _isdirsep(int) libcesque pureconst; char *_joinpaths(char *, size_t, const char *, const char *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_PATH_H_ */
590
22
jart/cosmopolitan
false
cosmopolitan/libc/str/memchr16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns pointer to first instance of character in range. */ void *memchr16(const void *s, int c, size_t n) { size_t i; const char *p = (const char *)s; for (i = 0; i < n; ++i) { if ((p[i] & 65535) == (c & 65535)) { return (void *)(p + i); } } return 0; }
2,150
34
jart/cosmopolitan
false
cosmopolitan/libc/str/kcombiningchars.S
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/macros.internal.h" #include "libc/sysv/consts/nr.h" #include "libc/sysv/consts/madv.h" .rodata.cst4 kCombiningCharsBits: .long 114752 * 8 .endobj kCombiningCharsBits,globl,hidden .previous .initbss 400,_init_kCombiningChars kCombiningChars: .zero 114752 .endobj kCombiningChars,globl,hidden .previous .init.start 400,_init_kCombiningChars push %rsi mov $1203,%edx call lz4cpy mov %rax,%rdi pop %rsi add $1208,%rsi .init.end 400,_init_kCombiningChars // o/tool/build/lz4toasm.com // -o o/libc/str/CombiningChars.s // -s kCombiningChars // o/libc/str/CombiningChars.bin.lz4 .initro 400,_init_kCombiningChars kCombiningCharsLz4: .byte 0x1f,0x00,0x01,0x00,0x4c,0x19,0xff,0x01 #▼ ☺ L↓λ☺ .byte 0x00,0x0f,0x30,0x00,0x0f,0x2f,0xf8,0x03 # ☼0 ☼/°♥ .byte 0x22,0x00,0x0d,0x10,0xfe,0x49,0x00,0x23 #. ♪►■I . .byte 0xbf,0xb6,0x0e,0x00,0x42,0x3f,0x00,0xff #┐╢♫ B⁇ λ .byte 0x17,0x39,0x00,0x00,0x5e,0x00,0x17,0x01 #↨9  ^ ↨☺ .byte 0x28,0x00,0x92,0xc0,0xbf,0x9f,0x3d,0x00 #( Æ└┐ƒ=  .byte 0x00,0x00,0x80,0x02,0x86,0x00,0x17,0x07 #  Ç☻å ↨• .byte 0x1a,0x00,0x13,0xff,0x28,0x00,0x91,0xf8 #→ ‼λ( æ° .byte 0x0f,0x20,0x00,0x00,0xc0,0xfb,0xef,0x3e #☼   └√∩> .byte 0x0e,0x00,0x1b,0x0e,0x8a,0x00,0x26,0xff #♫ ←♫è &λ .byte 0xff,0x37,0x00,0xa2,0x14,0xfe,0x21,0xfe #λ7 ó¶■!■ .byte 0x00,0x0c,0x00,0x00,0x00,0x02,0x10,0x00 # ♀   ☻►  .byte 0x40,0x10,0x1e,0x20,0x00,0x10,0x00,0x23 #@►▲  ► . .byte 0x40,0x06,0x10,0x00,0x20,0x86,0x39,0x1a #@♠►  å9→ .byte 0x00,0x24,0x23,0x00,0x10,0x00,0x21,0xbe # $. ► !╛ .byte 0x21,0x20,0x00,0x13,0xfc,0x30,0x00,0x41 #!  ‼ⁿ0 A .byte 0x90,0x1e,0x20,0x40,0x40,0x00,0x13,0x04 #É▲ @@ ‼♦ .byte 0x5e,0x00,0x22,0x01,0x20,0x08,0x00,0x13 #^ .☺ ◘ ‼ .byte 0x11,0x93,0x00,0x38,0xc1,0x3d,0x60,0x60 #◄ô 8┴=`` .byte 0x00,0x31,0x90,0x40,0x30,0x40,0x00,0x13 # 1É@0@ ‼ .byte 0x00,0x0f,0x01,0x13,0x18,0x70,0x00,0x06 # ☼☺‼↑p ♠ .byte 0x9f,0x00,0x27,0x04,0x5c,0x0d,0x00,0x48 #ƒ ‘♦\♪ H .byte 0xf2,0x07,0x80,0x7f,0x1d,0x00,0x45,0xf2 #≥•Ç⌂↔ E≥ .byte 0x1f,0x00,0x3f,0x0d,0x00,0x43,0x03,0x00 #▼ ⁇♪ C♥  .byte 0x00,0xa0,0x57,0x00,0x50,0xfe,0x7f,0xdf # áW P■⌂▀ .byte 0xe0,0xff,0x41,0x01,0x28,0x1f,0x40,0x2f #αλA☺(▼@/ .byte 0x00,0xff,0x00,0xe0,0xfd,0x66,0x00,0x00 # λ α²f   .byte 0x00,0xc3,0x01,0x00,0x1e,0x00,0x64,0x20 # ├☺ ▲ d .byte 0x00,0x20,0xcc,0x01,0x0b,0x0f,0xd2,0x01 #  ╠☺♂☼╥☺ .byte 0x1d,0x06,0x66,0x00,0x1f,0x00,0x01,0x00 #↔♠f ▼ ☺  .byte 0x62,0x13,0x1c,0x04,0x00,0x26,0x0c,0x00 #b‼∟♦ &♀  .byte 0x42,0x01,0x52,0xb0,0x3f,0x40,0xfe,0x0f #B☺R░⁇@■☼ .byte 0xe8,0x00,0x1a,0x78,0x2e,0x00,0x26,0x60 #Φ →x. &` .byte 0x00,0x85,0x01,0x04,0x14,0x00,0x4f,0x87 # à☺♦¶ Oç .byte 0x01,0x04,0x0e,0x60,0x00,0x07,0x22,0x80 #☺♦♫` •.Ç .byte 0x09,0x08,0x00,0x63,0x40,0x7f,0xe5,0x1f #○◘ c@⌂σ▼ .byte 0xf8,0x9f,0x2a,0x01,0x05,0x8e,0x01,0x11 #°ƒ*☺♣Ä☺◄ .byte 0x0f,0x06,0x00,0x32,0xd0,0x17,0x04,0x70 #☼♠ 2╨↨♦p .byte 0x02,0x01,0xd0,0x01,0x23,0x3c,0x3b,0x32 #☻☺╨☺.<;2 .byte 0x00,0x13,0xa3,0xde,0x01,0x2f,0xf0,0xcf # ‼ú▐☺/≡╧ .byte 0x58,0x00,0x00,0x6f,0xf7,0xff,0xfd,0x21 #X  o≈λ²! .byte 0x10,0x03,0x8c,0x01,0x0c,0x1f,0xfb,0x1f #►♥î☺♀▼√▼ .byte 0x01,0x2e,0x52,0xf8,0x00,0x00,0x00,0x7c #☺.R°   | .byte 0x0b,0x00,0x2c,0xdf,0xff,0x62,0x00,0x2f #♂ ,▀λb / .byte 0x01,0x00,0x01,0x00,0xff,0x6b,0x1d,0x80 #☺ ☺ λk↔Ç .byte 0xff,0x01,0x1c,0x80,0xa2,0x01,0x0f,0x68 #λ☺∟Çó☺☼h .byte 0x00,0x32,0x19,0x3c,0x0e,0x00,0x2f,0x06 # 2↓<♫ /♠ .byte 0x00,0x01,0x00,0xff,0xff,0xff,0xff,0xff # ☺ λλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xb3,0x20,0x80,0xf7,0xf6,0x12,0x28 #λ│ Ç≈÷↕( .byte 0xc0,0x00,0xfb,0x12,0x0f,0x33,0x00,0x0c #└ √↕☼3 ♀ .byte 0x23,0x44,0x08,0xf4,0x11,0x0b,0x18,0x00 #.D◘⌠◄♂↑  .byte 0x11,0x30,0x60,0x0f,0x11,0x03,0x70,0x0f #◄0`☼◄♥p☼ .byte 0x62,0xc0,0x3f,0x00,0x00,0x80,0xff,0x4c #b└⁇  ÇλL .byte 0x00,0x02,0x10,0x14,0x20,0xc8,0x33,0x06 # ☻►¶ ╚3♠ .byte 0x00,0x05,0x29,0x13,0x52,0x7e,0x66,0x00 # ♣)‼R~f  .byte 0x08,0x10,0xf8,0x13,0x02,0x11,0x00,0x21 #◘►°‼☻◄ ! .byte 0x9d,0xc1,0x43,0x12,0x2f,0x30,0x40,0x7c #¥┴C↕/0@| .byte 0x00,0x0a,0x2f,0x20,0x21,0x96,0x0a,0xff # ◙/ !û◙λ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xdb,0x1f,0x40,0x60,0x1f,0x4b,0x2f,0x00 #█▼@`▼K/  .byte 0x00,0x06,0x1a,0x08,0x1f,0x80,0x3f,0x00 # ♠→◘▼Ç⁇  .byte 0x0c,0x1f,0x0e,0x7f,0x00,0x2c,0x1f,0x20 #♀▼♫⌂ ,▼ .byte 0x1d,0x00,0x09,0x0e,0x3e,0x1c,0x2f,0xc0 #↔ ○♫>∟/└ .byte 0x07,0xdd,0x01,0xbd,0x22,0x6e,0xf0,0x23 #•▌☺╜.n≡. .byte 0x1e,0x0f,0x1c,0x00,0x01,0x1f,0x60,0x64 #▲☼∟ ☺▼`d .byte 0x00,0x34,0x1f,0xf0,0x44,0x00,0x30,0x05 # 4▼≡D 0♣ .byte 0xf4,0x20,0x0b,0x18,0x00,0x1a,0x02,0xb1 #⌠ ♂↑ →☻▒ .byte 0x1e,0x03,0x72,0x1c,0x24,0x78,0x26,0xda #▲♥r∟$x&┌ .byte 0x01,0x00,0xf0,0x0c,0x33,0x80,0xef,0x1f #☺ ≡♀3Ç∩▼ .byte 0x2e,0x00,0x13,0x08,0x52,0x0d,0x48,0xc0 #. ‼◘R♪H└ .byte 0x7f,0x00,0x1e,0x66,0x02,0x1f,0xd3,0xe4 #⌂ ▲f☻▼╙Σ .byte 0x02,0x01,0x36,0x80,0xf8,0x07,0xc0,0x20 #☻☺6ǰ•└ .byte 0x00,0x7e,0x00,0x3f,0xc0,0x1f,0x1f,0xc7 # ~ ⁇└▼▼╟ .byte 0x02,0x06,0x19,0x5c,0x28,0x03,0x3f,0xf8 #☻♠↓\(♥⁇° .byte 0x85,0x0d,0xb1,0x1c,0x0b,0x22,0xb0,0x01 #à♪▒∟♂.░☺ .byte 0xa3,0x0d,0x04,0x30,0x00,0x19,0xa7,0xde #ú♪♦0 ↓º▐ .byte 0x00,0x29,0x28,0xbf,0x78,0x20,0x2f,0xbc # )(┐x /╝ .byte 0x0f,0x38,0x0e,0x0d,0x1f,0xff,0xf4,0x1c #☼8♫♪▼λ⌠∟ .byte 0x20,0x20,0xf0,0x0c,0x74,0x00,0x11,0xfe # ≡♀t ◄■ .byte 0xd2,0x02,0x52,0xf8,0x79,0x80,0x00,0x7e #╥☻R°yÇ ~ .byte 0x4c,0x03,0x3f,0xfc,0x7f,0x03,0x4c,0x00 #L♥⁇ⁿ⌂♥L  .byte 0x1f,0x17,0x7f,0xb1,0x00,0x5b,0xfc,0xff #▼↨⌂▒ [ⁿλ .byte 0xff,0xfc,0x6d,0x20,0x00,0x26,0x7e,0xb4 #λⁿm  &~┤ .byte 0x21,0x00,0x1f,0xa3,0x58,0x00,0x18,0x1f #! ▼úX ↑▼ .byte 0x18,0x23,0x07,0xff,0xff,0x96,0x2f,0xff #↑.•λλû/λ .byte 0x01,0xfb,0x0d,0xff,0xff,0xff,0xff,0xff #☺√♪λλλλλ .byte 0xff,0xc9,0x04,0xf0,0x0a,0x1f,0x7f,0x1c #λ╔♦≡◙▼⌂∟ .byte 0x19,0x70,0x04,0x08,0x00,0x1f,0x07,0x30 #↓p♦◘ ▼•0 .byte 0x18,0xff,0xff,0xff,0xff,0xff,0xff,0xff #↑λλλλλλλ .byte 0xff,0xff,0x96,0x2f,0x60,0x0f,0x5f,0x25 #λλû/`☼_% .byte 0xff,0xff,0x87,0x5d,0x03,0xf8,0xff,0xe7 #λλç]♥°λτ .byte 0x0f,0x30,0x34,0x05,0x66,0x37,0x0f,0xba #☼04♣f7☼║ .byte 0x14,0xe2,0x01,0x01,0x00,0x12,0x7f,0x2d #¶Γ☺☺ ↕⌂- .byte 0x3a,0x20,0x1f,0x20,0x01,0x26,0x3f,0xf8 #: ▼ ☺&⁇° .byte 0xfe,0xff,0xc0,0x00,0x97,0x5f,0x7f,0xff #■λ└ ù_⌂λ .byte 0xff,0xf9,0xdb,0x13,0x0e,0x0e,0x1f,0x7f #λ∙█‼♫♫▼⌂ .byte 0xb9,0x1a,0x24,0x0f,0xda,0x01,0xa9,0x0a #╣→$☼┌☺⌐◙ .byte 0xf4,0x00,0x3f,0xf0,0x07,0x00,0x01,0x00 #⌠ ⁇≡• ☺  .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ .byte 0xff,0xff,0xff,0xff,0x46,0x57,0x02,0x00 #λλλλFW☻  .byte 0x00,0x00,0xff,0x01,0x00,0x0c,0x20,0x00 #  λ☺ ♀   .byte 0x1f,0xff,0x01,0x00,0x07,0x50,0xff,0xff #▼λ☺ •Pλλ .byte 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .endobj kCombiningCharsLz4,globl,hidden .previous
12,525
204
jart/cosmopolitan
false
cosmopolitan/libc/str/strncat16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Appends at most 𝑛 shorts from 𝑠 to 𝑑. * * @param 𝑑 is both a NUL-terminated string and a buffer, needing * an ARRAYLEN() of at least strlen16(𝑑)+strnlen16(𝑠,𝑛)+1 * @param 𝑠 is character array which needn't be NUL-terminated * @param 𝑛 is maximum number of characters from s to copy * @return 𝑑 * @note 𝑑 and 𝑠 can't overlap * @asyncsignaslenafe */ char16_t *strncat16(char16_t *d, const char16_t *s, size_t n) { size_t i; char16_t *r = d; d += strlen16(d); for (i = 0; i < n && s[i]; ++i) d[i] = s[i]; d[i] = 0; return r; }
2,455
40
jart/cosmopolitan
false
cosmopolitan/libc/str/strncasecmp_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int strncasecmp_l(const char *a, const char *b, size_t n, locale_t l) { return strncasecmp(a, b, n); }
1,997
25
jart/cosmopolitan
false
cosmopolitan/libc/str/isupper_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int isupper_l(int c, locale_t l) { return isupper(c); }
1,950
25
jart/cosmopolitan
false
cosmopolitan/libc/str/thompike.h
#ifndef COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ #define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ #include "libc/intrin/bsr.h" #define ThomPikeCont(x) (0200 == (0300 & (x))) #define ThomPikeByte(x) ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3)) #define ThomPikeLen(x) (7 - ThomPikeMsb(x)) #define ThomPikeMsb(x) ((255 & (x)) < 252 ? _bsr(255 & ~(x)) : 1) #define ThomPikeMerge(x, y) ((x) << 6 | 077 & (y)) #endif /* COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ */
454
12
jart/cosmopolitan
false
cosmopolitan/libc/str/strncmp16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Compares NUL-terminated UCS-2 strings w/ limit. * * @param a is first non-null NUL-terminated char16 string pointer * @param b is second non-null NUL-terminated char16 string pointer * @return is <0, 0, or >0 based on uint8_t comparison * @asyncsignalsafe */ int strncmp16(const char16_t *a, const char16_t *b, size_t n) { size_t i = 0; if (!n-- || a == b) return 0; while (i < n && a[i] == b[i] && b[i]) ++i; return a[i] - b[i]; }
2,316
35
jart/cosmopolitan
false
cosmopolitan/libc/str/rawmemchr16.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" /** * Returns pointer to first instance of character in range. */ void *rawmemchr16(const void *s, int c) { const char *p = (const char *)s; for (;; ++p) { if ((*p & 65535) == (c & 65535)) { return (void *)p; } } }
2,100
32
jart/cosmopolitan
false
cosmopolitan/libc/str/strcasecmp_l.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/locale.h" #include "libc/str/str.h" int strcasecmp_l(const char *a, const char *b, locale_t l) { return strcasecmp(a, b); }
1,982
25
jart/cosmopolitan
false
cosmopolitan/libc/str/mb.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╚──────────────────────────────────────────────────────────────────────────────╝ │ │ │ Musl Libc │ │ Copyright © 2005-2014 Rich Felker, et al. │ │ │ │ Permission is hereby granted, free of charge, to any person obtaining │ │ a copy of this software and associated documentation files (the │ │ "Software"), to deal in the Software without restriction, including │ │ without limitation the rights to use, copy, modify, merge, publish, │ │ distribute, sublicense, and/or sell copies of the Software, and to │ │ permit persons to whom the Software is furnished to do so, subject to │ │ the following conditions: │ │ │ │ The above copyright notice and this permission notice shall be │ │ included in all copies or substantial portions of the Software. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ │ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ │ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │ │ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │ │ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/mb.internal.h" asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); #define C(x) (x < 2 ? -1 : (R(0x80, 0xc0) | x)) #define D(x) C((x + 16)) #define E(x) \ ((x == 0 ? R(0xa0, 0xc0) \ : x == 0xd ? R(0x80, 0xa0) \ : R(0x80, 0xc0)) | \ (R(0x80, 0xc0) >> 6) | x) #define F(x) \ ((x >= 5 ? 0 \ : x == 0 ? R(0x90, 0xc0) \ : x == 4 ? R(0x80, 0x90) \ : R(0x80, 0xc0)) | \ (R(0x80, 0xc0) >> 6) | (R(0x80, 0xc0) >> 12) | x) const uint32_t kMbBittab[51 /* ?! */] = { C(0x2), C(0x3), C(0x4), C(0x5), C(0x6), C(0x7), C(0x8), C(0x9), C(0xa), C(0xb), C(0xc), C(0xd), C(0xe), C(0xf), D(0x0), D(0x1), D(0x2), D(0x3), D(0x4), D(0x5), D(0x6), D(0x7), D(0x8), D(0x9), D(0xa), D(0xb), D(0xc), D(0xd), D(0xe), D(0xf), E(0x0), E(0x1), E(0x2), E(0x3), E(0x4), E(0x5), E(0x6), E(0x7), E(0x8), E(0x9), E(0xa), E(0xb), E(0xc), E(0xd), E(0xe), E(0xf), F(0x0), F(0x1), F(0x2), F(0x3), F(0x4), };
3,723
57
jart/cosmopolitan
false
cosmopolitan/libc/str/wctob.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╚──────────────────────────────────────────────────────────────────────────────╝ │ │ │ Musl Libc │ │ Copyright © 2005-2014 Rich Felker, et al. │ │ │ │ Permission is hereby granted, free of charge, to any person obtaining │ │ a copy of this software and associated documentation files (the │ │ "Software"), to deal in the Software without restriction, including │ │ without limitation the rights to use, copy, modify, merge, publish, │ │ distribute, sublicense, and/or sell copies of the Software, and to │ │ permit persons to whom the Software is furnished to do so, subject to │ │ the following conditions: │ │ │ │ The above copyright notice and this permission notice shall be │ │ included in all copies or substantial portions of the Software. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ │ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ │ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │ │ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │ │ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/limits.h" #include "libc/str/mb.internal.h" #include "libc/str/str.h" asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); int wctob(wint_t c) { if (c < 128U) return c; if (MB_CUR_MAX == 1 && IS_CODEUNIT(c)) return (unsigned char)c; return EOF; }
2,987
43
jart/cosmopolitan
false