/*
* encoding.c - UTF-8 and UTF-16LE codecs and utility functions
*
- * Copyright (C) 2012-2016 Eric Biggers
+ * Copyright 2012-2023 Eric Biggers
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
decode_codepoint_fn decode_codepoint,
encode_codepoint_fn encode_codepoint)
{
- const u8 * const in_end = in + in_nbytes;
- const u8 *p_in;
+ size_t i;
u8 *p_out;
size_t out_nbytes = 0;
u8 *out;
u32 c;
/* Validate the input string and compute the output size. */
- for (p_in = in; p_in != in_end; ) {
- p_in += (*decode_codepoint)(p_in, in_end - p_in, true, &c);
+ for (i = 0; i < in_nbytes; ) {
+ i += (*decode_codepoint)(&in[i], in_nbytes - i, true, &c);
if (unlikely(c == INVALID_CODEPOINT)) {
errno = EILSEQ;
return ilseq_err;
return WIMLIB_ERR_NOMEM;
/* Do the conversion. */
- for (p_in = in, p_out = out; p_in != in_end; ) {
- p_in += (*decode_codepoint)(p_in, in_end - p_in, false, &c);
+ p_out = out;
+ for (i = 0; i < in_nbytes; ) {
+ i += (*decode_codepoint)(&in[i], in_nbytes - i, false, &c);
p_out += (*encode_codepoint)(c, p_out);
}