tiny-utf8 icon indicating copy to clipboard operation
tiny-utf8 copied to clipboard

compiling error

Open jalcazo opened this issue 11 months ago • 2 comments

error now in tinyutf-8: include\libs\tinyutf8\tinyutf8.h|2360|error: cannot increment value of type 'const value_type[LITLEN]' (aka 'const ValueType[LITLEN]')|

here:

...

	while( it != end && str_len ){
			if( *it != *str )
				return false;

----> HERE ---> ++it, ++str, --str_len; } return !str_len; }

jalcazo avatar Dec 15 '24 18:12 jalcazo

Hey,

thanks for your message, this is most likely due to very strict warnings and warnings that are converted into errors (perhabys by -Werror) by your compiler. The code could be adapted however, in case this information still doesn't help you solve your problem.

Thanks, Jakob

DuffsDevice avatar Dec 19 '24 23:12 DuffsDevice

Because of this, tiny-utf8 won't compile with Emscripten for Wasm.

It looks like we can just change it to a normal for-loop with an index, correct?

template<size_type LITLEN>
bool starts_with( const value_type (&str)[LITLEN] ) const noexcept {
  size_type str_len = str[LITLEN-1] ? LITLEN : LITLEN-1;
  const_iterator it = cbegin(), end = cend();
  while( it != end && str_len ){
    if( *it != *str )
      return false;
    ++it, ++str, --str_len;
  }
  return !str_len;
}

So just change to this, I think?

template<size_type LITLEN>
bool starts_with( const value_type (&str)[LITLEN] ) const noexcept {
  size_type str_len = str[LITLEN-1] ? LITLEN : LITLEN-1;
  const_iterator it = cbegin(), end = cend();

  for(int i = 0; i < str_len && it != end; ++i,++it) {
    if( *it != str[i] )
      return false;
  }

  return !str_len;
}

esotericpig avatar Feb 28 '25 22:02 esotericpig

Or change to this:

template<size_type LITLEN>
bool starts_with( const value_type (&str)[LITLEN] ) const noexcept {
    size_type		str_len = str[LITLEN-1] ? LITLEN : LITLEN-1;
    const_iterator	it = cbegin(), end = cend();
    const value_type*   s = str;
    while( it != end && str_len ){
        if( *it != *s )
            return false;
        ++it, ++s, --str_len;
    }
    return !str_len;
}

yurablok avatar Jul 02 '25 16:07 yurablok