static Char32 buffer[128]; size_t inBytesLeft = strlen(s); size_t outBytesLeft = sizeof(buffer);  #ifdef ICONV_CONST const char* inbuf = s; #else char* inbuf = strdup(s); char* inbuf0 = inbuf; #endif char* outbuf = reinterpret_cast<char*>(buffer); char* outbuf0 = outbuf; size_t nConv = 0; unsigned n;  String* res = NULL;  if (isPlain(s)) res = new StringU<Char8>(s); else { do { String* chunk = NULL; n = 0; nConv = iconv(cd, &inbuf, &inBytesLeft, &outbuf, &outBytesLeft); if (nConv != (size_t) -1) { unsigned n = (outbuf - outbuf0) / sizeof(Char32); if (n > 0) chunk = new StringU<Char32>(buffer, n); } else {   perror("iconv: "); }  if (chunk != NULL) { if (sValue == NULL) sValue = chunk; else { sValue->Append(*chunk);  } } } while (inBytesLeft > 0 && n > 0);  if (sValue != NULL) { Char big = sValue->GetBiggestChar(); if (isPlain(big)) { res = new StringU<Char8>(*sValue); delete sValue; } else if (isUnicode16(big)) { res = new StringU<Char16>(*sValue); delete sValue; } else res = sValue; } }  if (res == NULL) res = new StringC("?");   #ifndef ICONV_CONST free(inbuf0); #endif  return res;
return sValue;
String* allocString(mDOMConstStringRef str){  assert(str != NULL);  static bool first = true;  static iconv_t cd;  if (first) {    cd = iconv_open(ICONV_UCS4, ICONV_UTF8);    assert(cd != (iconv_t) -1);    first = false;  }  assert(str != NULL);  String* sValue = NULL;  const char* s = reinterpret_cast<const char*>(str);  static Char32 buffer[128];  size_t inBytesLeft = strlen(s);  size_t outBytesLeft = sizeof(buffer);  /* LUCA: iconv changed and now the 2 argument of iconv is not a const   * pointer any more, so we have to make a duplicate of the string since   * it can be modified. What's going on?   */#ifdef ICONV_CONST  const char* inbuf = s;#else // !ICONV_CONST  char* inbuf = strdup(s);  char* inbuf0 = inbuf;#endif // ICONV_CONST  char* outbuf = reinterpret_cast<char*>(buffer);  char* outbuf0 = outbuf;  size_t nConv = 0;  unsigned n;  String* res = NULL;  if (isPlain(s)) res = new StringU<Char8>(s);  else {    do {      String* chunk = NULL;      n = 0;      nConv = iconv(cd, &inbuf, &inBytesLeft, &outbuf, &outBytesLeft);      if (nConv != (size_t) -1) {	unsigned n = (outbuf - outbuf0) / sizeof(Char32);	if (n > 0) chunk = new StringU<Char32>(buffer, n);      } else {	// the error "invalid argument" is probably due to an old version	// of libxml (1.x.y)	perror("iconv: ");      }      if (chunk != NULL) {	if (sValue == NULL) sValue = chunk;	else {	  sValue->Append(*chunk);	  // FIXME: chunk is to be freed???	}      }    } while (inBytesLeft > 0 && n > 0);    if (sValue != NULL) {      Char big = sValue->GetBiggestChar();      if (isPlain(big)) {	res = new StringU<Char8>(*sValue);	delete sValue;      } else if (isUnicode16(big)) {	res = new StringU<Char16>(*sValue);	delete sValue;      } else res = sValue;    }  }  if (res == NULL) res = new StringC("?");  /* see the note above */#ifndef ICONV_CONST  free(inbuf0);#endif // !ICONV_CONST  return res;}