diff options
Diffstat (limited to 'vendor/librune/lib/utf8')
-rw-r--r-- | vendor/librune/lib/utf8/rtou8.c | 2 | ||||
-rw-r--r-- | vendor/librune/lib/utf8/u8chk.c | 5 | ||||
-rw-r--r-- | vendor/librune/lib/utf8/u8chr.c | 24 | ||||
-rw-r--r-- | vendor/librune/lib/utf8/u8next.c | 18 | ||||
-rw-r--r-- | vendor/librune/lib/utf8/u8prev.c | 15 | ||||
-rw-r--r-- | vendor/librune/lib/utf8/u8rchr.c | 36 | ||||
-rw-r--r-- | vendor/librune/lib/utf8/u8set.c | 6 | ||||
-rw-r--r-- | vendor/librune/lib/utf8/u8tor_uc.c | 2 |
8 files changed, 59 insertions, 49 deletions
diff --git a/vendor/librune/lib/utf8/rtou8.c b/vendor/librune/lib/utf8/rtou8.c index 1823f08..94cce34 100644 --- a/vendor/librune/lib/utf8/rtou8.c +++ b/vendor/librune/lib/utf8/rtou8.c @@ -1,3 +1,5 @@ +#include <stddef.h> + #include "utf8.h" #include "internal/common.h" diff --git a/vendor/librune/lib/utf8/u8chk.c b/vendor/librune/lib/utf8/u8chk.c index 422bbd8..4fd1afc 100644 --- a/vendor/librune/lib/utf8/u8chk.c +++ b/vendor/librune/lib/utf8/u8chk.c @@ -1,9 +1,10 @@ #include "rune.h" +#define _RUNE_NO_MACRO_WRAPPER 1 #include "utf8.h" #include "internal/common.h" -const char8_t * +char8_t * u8chk(const char8_t *s, size_t n) { while (n) { @@ -11,7 +12,7 @@ u8chk(const char8_t *s, size_t n) int m = u8tor(&ch, s); if (ch == RUNE_ERROR) - return s; + return (char8_t *)s; n -= m; } diff --git a/vendor/librune/lib/utf8/u8chr.c b/vendor/librune/lib/utf8/u8chr.c index 4ecbd10..c387300 100644 --- a/vendor/librune/lib/utf8/u8chr.c +++ b/vendor/librune/lib/utf8/u8chr.c @@ -1,10 +1,10 @@ +#include <stddef.h> #include <stdint.h> #include <string.h> +#define _RUNE_NO_MACRO_WRAPPER 1 #include "utf8.h" -#include "internal/common.h" - /* NOTE: The memmem*() functions were taken directly from the memmem() implementation on OpenBSD. As a result, these functions are licensed under OpenBSDs 2-Clause BSD License instead of this libraries 0-Clause BSD License. @@ -32,7 +32,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char8_t * +static char8_t * memmem2(const char8_t *h, size_t k, const char8_t *n) { uint16_t hw, nw; @@ -41,12 +41,12 @@ memmem2(const char8_t *h, size_t k, const char8_t *n) for (h += 2, k -= 2; k; k--, hw = hw << 8 | *h++) { if (hw == nw) - return h - 2; + return (char8_t *)h - 2; } - return hw == nw ? h - 2 : nullptr; + return hw == nw ? (char8_t *)h - 2 : nullptr; } -static const char8_t * +static char8_t * memmem3(const char8_t *h, size_t k, const char8_t *n) { uint32_t hw, nw; @@ -55,12 +55,12 @@ memmem3(const char8_t *h, size_t k, const char8_t *n) for (h += 3, k -= 3; k; k--, hw = (hw | *h++) << 8) { if (hw == nw) - return h - 3; + return (char8_t *)h - 3; } - return hw == nw ? h - 3 : nullptr; + return hw == nw ? (char8_t *)h - 3 : nullptr; } -static const char8_t * +static char8_t * memmem4(const char8_t *h, size_t k, const char8_t *n) { uint32_t hw, nw; @@ -69,12 +69,12 @@ memmem4(const char8_t *h, size_t k, const char8_t *n) for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++) { if (hw == nw) - return h - 4; + return (char8_t *)h - 4; } - return hw == nw ? h - 4 : nullptr; + return hw == nw ? (char8_t *)h - 4 : nullptr; } -const char8_t * +char8_t * u8chr(const char8_t *s, rune ch, size_t n) { char8_t buf[U8_LEN_MAX]; diff --git a/vendor/librune/lib/utf8/u8next.c b/vendor/librune/lib/utf8/u8next.c index 8edc084..12c521d 100644 --- a/vendor/librune/lib/utf8/u8next.c +++ b/vendor/librune/lib/utf8/u8next.c @@ -1,14 +1,16 @@ +#define _RUNE_NO_MACRO_WRAPPER 1 #include "utf8.h" -#include "internal/common.h" - -const char8_t * +int u8next(rune *ch, const char8_t **s, size_t *n) { - int m; + int m = 0; + + if (*n) { + m = u8tor_uc(ch, *s); + *n -= m; + *s += m; + } - if (*n == 0) - return nullptr; - *n -= m = u8tor_uc(ch, *s); - return *s += m; + return m; } diff --git a/vendor/librune/lib/utf8/u8prev.c b/vendor/librune/lib/utf8/u8prev.c index fac0fc7..a219ae9 100644 --- a/vendor/librune/lib/utf8/u8prev.c +++ b/vendor/librune/lib/utf8/u8prev.c @@ -1,9 +1,10 @@ +#define _RUNE_NO_MACRO_WRAPPER 1 #include "rune.h" #include "utf8.h" #include "internal/common.h" -const char8_t * +int u8prev(rune *ch, const char8_t **p, const char8_t *start) { int off; @@ -12,7 +13,7 @@ u8prev(rune *ch, const char8_t **p, const char8_t *start) ptrdiff_t d = s - start; if (d <= 0) { - return nullptr; + return 0; } else if (U1(s[-1])) { *ch = s[-1]; off = 1; @@ -29,9 +30,11 @@ u8prev(rune *ch, const char8_t **p, const char8_t *start) } else match = false; - if (match && u8chkr(*ch)) - return *p -= off; + if (!(match && u8chkr(*ch))) { + *ch = RUNE_ERROR; + off = 1; + } - *ch = RUNE_ERROR; - return *p--; + *p -= off; + return off; } diff --git a/vendor/librune/lib/utf8/u8rchr.c b/vendor/librune/lib/utf8/u8rchr.c index 15fff51..b2668e4 100644 --- a/vendor/librune/lib/utf8/u8rchr.c +++ b/vendor/librune/lib/utf8/u8rchr.c @@ -1,20 +1,20 @@ +#include <stddef.h> #include <stdint.h> +#define _RUNE_NO_MACRO_WRAPPER 1 #include "utf8.h" -#include "internal/common.h" - -static const char8_t * +static char8_t * memrchr1(const char8_t *s, size_t k, const char8_t *n) { for (const char8_t *p = s + k - 1; k-- > 0; p--) { if (*p == *n) - return p; + return (char8_t *)p; } return nullptr; } -static const char8_t * +static char8_t * memrchr2(const char8_t *h, size_t k, const char8_t *n) { uint16_t hw, nw; @@ -24,13 +24,13 @@ memrchr2(const char8_t *h, size_t k, const char8_t *n) for (H -= 2, k -= 2; k; k--, hw = hw >> 8 | (*H-- << 8)) { if (hw == nw) - return H + 1; + return (char8_t *)H + 1; } - return hw == nw ? H + 1 : nullptr; + return hw == nw ? (char8_t *)H + 1 : nullptr; } -static const char8_t * +static char8_t * memrchr3(const char8_t *h, size_t k, const char8_t *n) { uint32_t hw, nw; @@ -42,13 +42,13 @@ memrchr3(const char8_t *h, size_t k, const char8_t *n) k--, hw = (hw >> 8 | (*H-- << 24)) & UINT32_C(0xFFFFFF00)) { if (hw == nw) - return H + 1; + return (char8_t *)H + 1; } - return hw == nw ? H + 1 : nullptr; + return hw == nw ? (char8_t *)H + 1 : nullptr; } -static const char8_t * +static char8_t * memrchr4(const char8_t *h, size_t k, const char8_t *n) { uint32_t hw, nw; @@ -58,13 +58,13 @@ memrchr4(const char8_t *h, size_t k, const char8_t *n) for (H -= 4, k -= 4; k; k--, hw = hw >> 8 | (*H-- << 24)) { if (hw == nw) - return H + 1; + return (char8_t *)H + 1; } - return hw == nw ? H + 1 : nullptr; + return hw == nw ? (char8_t *)H + 1 : nullptr; } -const char8_t * +char8_t * u8rchr(const char8_t *s, rune ch, size_t n) { char8_t buf[U8_LEN_MAX]; @@ -74,13 +74,13 @@ u8rchr(const char8_t *s, rune ch, size_t n) return nullptr; switch (m) { case 1: - return memrchr1(s, n, buf); + return (char8_t *)memrchr1(s, n, buf); case 2: - return memrchr2(s, n, buf); + return (char8_t *)memrchr2(s, n, buf); case 3: - return memrchr3(s, n, buf); + return (char8_t *)memrchr3(s, n, buf); case 4: - return memrchr4(s, n, buf); + return (char8_t *)memrchr4(s, n, buf); } unreachable(); diff --git a/vendor/librune/lib/utf8/u8set.c b/vendor/librune/lib/utf8/u8set.c index 0dfba2c..6c57991 100644 --- a/vendor/librune/lib/utf8/u8set.c +++ b/vendor/librune/lib/utf8/u8set.c @@ -5,7 +5,7 @@ #include "internal/common.h" size_t -u8set(const char8_t *s, rune ch, size_t n) +u8set(char8_t *s, rune ch, size_t n) { int m; char8_t buf[U8_LEN_MAX]; @@ -13,12 +13,12 @@ u8set(const char8_t *s, rune ch, size_t n) if (n == 0) return 0; if (ch <= _1B_MAX) { - memset((char *)s, ch, n); + memset(s, ch, n); return n; } m = rtou8(buf, ch, sizeof(buf)); for (size_t i = 0; i < n; i += m) - memcpy((char *)s + i, buf, m); + memcpy(s + i, buf, m); return n - n % m; } diff --git a/vendor/librune/lib/utf8/u8tor_uc.c b/vendor/librune/lib/utf8/u8tor_uc.c index ea57332..3448b59 100644 --- a/vendor/librune/lib/utf8/u8tor_uc.c +++ b/vendor/librune/lib/utf8/u8tor_uc.c @@ -1,3 +1,5 @@ +#include <stddef.h> + #include "utf8.h" #include "internal/common.h" |