コード例 #1
0
  void StringBuffer::growBuffer(const int32_t minLength) {
  //Func - Has the buffer grown to a minimum length of minLength or bigger
  //Pre  - minLength >= len + 1
  //Post - The buffer has been grown to a minimum length of minLength or bigger

      growBuffer(minLength, 0);
  }
コード例 #2
0
	void SegmentTermEnum::seek(const int64_t pointer, const int32_t p, Term* t, TermInfo* ti) {
	//Func - Repositions term and termInfo within the enumeration
	//Pre  - pointer >= 0
	//       p >= 0 and contains the new position within the enumeration
	//       t is a valid reference to a Term and is the new current term in the enumeration
	//       ti is a valid reference to a TermInfo and is corresponding TermInfo form the new
	//       current Term
	//Post - term and terminfo have been repositioned within the enumeration

		//Reset the IndexInput input to pointer
		input->seek(pointer);
		//Assign the new position
		position = p;

		//finalize the current term
		if ( _term == NULL || _LUCENE_ATOMIC_INT_GET(_term->__cl_refcount) > 1 ){
			_CLDECDELETE(_term);
			//Get a pointer from t and increase the reference counter of t
			_term = _CLNEW Term; //cannot use reference, because TermInfosReader uses non ref-counted array
		}
		_term->set(t,t->text());

		//finalize prev
		_CLDECDELETE(prev);

		//Change the current termInfo so it matches the new current term
		termInfo->set(ti);

		//Have the buffer grown if needed
		if ( bufferLength <= _term->textLength() )
			growBuffer(_term->textLength(), true );		  // copy term text into buffer
		else
			_tcsncpy(buffer,_term->text(),bufferLength); //just copy the buffer
	}
コード例 #3
0
	Term* SegmentTermEnum::readTerm(Term* reuse) {
	//Func - Reads the next term in the enumeration
	//Pre  - true
	//Post - The next Term in the enumeration has been read and returned

		//Read the start position from the inputStream input
		int32_t start = input->readVInt();
		//Read the length of term in the inputStream input
		int32_t length = input->readVInt();

		//Calculated the total lenght of bytes that buffer must be to contain the current
		//chars in buffer and the new ones yet to be read
		uint32_t totalLength = start + length;

		if (static_cast<uint32_t>(bufferLength) < totalLength+1)
			growBuffer(totalLength, false); //dont copy the buffer over.

		//Read a length number of characters into the buffer from position start in the inputStream input
		input->readChars(buffer, start, length);
		//Null terminate the string
		buffer[totalLength] = 0;

		//Return a new Term	
		int32_t field = input->readVInt();
		const TCHAR* fieldname = fieldInfos->fieldName(field);
		if ( reuse == NULL )
			reuse = _CLNEW Term;

		reuse->set(fieldname, buffer, false);
		return reuse;
	}
コード例 #4
0
ファイル: EncodeBuffer.C プロジェクト: aywq2008/omniplay
void EncodeBuffer::encodeIndex(unsigned index, int isEscape)
{

    if (index > 1 && !isEscape)
        index++;

    DBG("EncodeBuffer::encodeIndex: writing %d\n", index);

    // Write n leading zeros followed by a 1.
    while (index)
    {
        if (freeBitsInDest <= index)
        {
            if (++nextDest == end)
            {
                growBuffer();
            }
            *nextDest = 0;
            index -= freeBitsInDest;
            freeBitsInDest = 8;
        }
        else
        {
            freeBitsInDest -= index;
            index = 0;
        }
    }
    // Now write the trailing one.
    encodeDirect(1,1);
}
コード例 #5
0
ファイル: conv_vertex_buffer.cpp プロジェクト: Zaela/ZEQ-API
void ConvVertexBuffer::push_back(Vertex& v)
{
    uint32_t index = m_count++;
    
    if (!m_vertices)
        initBuffer();
    else if (index >= m_capacity)
        growBuffer();
    
    m_vertices[index] = v;
}
コード例 #6
0
ファイル: buffer.c プロジェクト: OpenXT-Extras/xc-vusb-daemon
/* Append the given string to the end of the specified buffer
 * param    buffer               buffer to add string to
 * param    string               string to add to end of buffer
 */
static void appendToBuffer(Buffer *buffer, const char *string)
{
    int len;  /* Required length */

    assert(buffer != NULL);
    assert(string != NULL);

    /* +1 for terminator, +1 cause we'll often need it for separator character */
    len = strlen(buffer->data) + strlen(string) + 2;
    growBuffer(buffer, len);
    strcpy(buffer->data + strlen(buffer->data), string);
}    
コード例 #7
0
ファイル: EncodeBuffer.C プロジェクト: aywq2008/omniplay
void EncodeBuffer::forceBufferToByteBoundary()
{
    if (freeBitsInDest != 8)
    {
        freeBitsInDest = 8;

        if (++nextDest == end)
        {
            growBuffer();
        }
        *nextDest = 0;
    }
}
コード例 #8
0
ファイル: pl-termhash.c プロジェクト: lamby/pkg-swi-prolog
static void *
allocBuffer(Buffer b, size_t size)
{ void *ptr;

  if ( b->top + size > b->max )
  { if ( !growBuffer(b, size) )
      return NULL;
  }
  ptr = b->top;
  b->top += size;

  return ptr;
}
コード例 #9
0
ファイル: EncodeBuffer.C プロジェクト: aywq2008/omniplay
void EncodeBuffer::encodeRawMem(const unsigned char *buffer, unsigned int len)
{
    forceBufferToByteBoundary();

    if (end - nextDest < (ptrdiff_t) len)
    {
        growBuffer(len);
    }

    memcpy(nextDest, buffer, len);
    nextDest += len;

    if (nextDest == end)
    {
        growBuffer();
    }
    else if (nextDest > end)
    {
        CERR << "EncodeBuffer::encodeRawMem overrun" << ENDL;
        abort();
    }
    *nextDest = 0;
}
コード例 #10
0
  TCHAR* StringBuffer::getBuffer() {
  //Func - '\0' terminates the buffer and returns its pointer
  //Pre  - true
  //Post - buffer has been '\0' terminated and returned
    
      // Check if the current buffer is '\0' terminated
	  if (len == bufferLength){
          //Make space for terminator, if necessary.
          growBuffer(len + 1);
	  }
      //'\0' buffer so it can be returned properly
      buffer[len] = '\0';

     return buffer;
  }
コード例 #11
0
ファイル: gkDebugger.cpp プロジェクト: Draion/Gamekit
gkDebugger::gkDebugger(gkScene* parent)
	:   m_node(0),
	    m_parent(parent),
	    m_radius(0.f),
	    m_bbmin(GK_INFINITY, GK_INFINITY, GK_INFINITY),
	    m_bbmax(-GK_INFINITY, -GK_INFINITY, -GK_INFINITY),
	    m_bufSize(0),
	    m_flags(0),
		m_d3dColor(false)
{
	growBuffer(128);
	m_lineBuf.reserve(128);

	m_d3dColor = gkEngine::getSingleton().getUserDefs().isD3DRenderSystem();
}
コード例 #12
0
void Token::setText(const TCHAR* text){
	_termTextLen = _tcslen(text);
	
#ifndef LUCENE_TOKEN_WORD_LENGTH
	growBuffer(_termTextLen+1);
	_tcsncpy(_termText,text,_termTextLen+1);
#else
	if ( _termTextLen > LUCENE_TOKEN_WORD_LENGTH ){
    	//in the case where this occurs, we will leave the endOffset as it is
    	//since the actual word still occupies that space.
		_termTextLen=LUCENE_TOKEN_WORD_LENGTH;
	}
	_tcsncpy(_termText,text,_termTextLen+1);
#endif
	_termText[_termTextLen] = 0; //make sure null terminated
}
コード例 #13
0
  void StringBuffer::appendChar(const TCHAR character) {
  //Func - Appends a single character 
  //Pre  - true
  //Post - The character has been appended to the string in the buffer

	  //Check if the current buffer length is sufficient to have the string value appended
      if (len + 1 > bufferLength){
		   //Have the size of the current string buffer increased because it is too small	
          growBuffer(len + 1);
      }
	  //Put character at position len which is the end of the string in the buffer
	  //Note that this action might overwrite the terminator of the string '\0', which
	  //is kind of tricky
      buffer[len] = character;
	  //Increase the len by to represent the correct length of the string in the buffer
      len++;
  }
コード例 #14
0
void MachineThreads::gatherConservativeRoots(ConservativeRoots& conservativeRoots, JITStubRoutineSet& jitStubRoutines, CodeBlockSet& codeBlocks, void* stackOrigin, void* stackTop, RegisterState& calleeSavedRegisters)
{
    gatherFromCurrentThread(conservativeRoots, jitStubRoutines, codeBlocks, stackOrigin, stackTop, calleeSavedRegisters);

    size_t size;
    size_t capacity = 0;
    void* buffer = nullptr;
    MutexLocker lock(m_registeredThreadsMutex);
    while (!tryCopyOtherThreadStacks(lock, buffer, capacity, &size))
        growBuffer(size, &buffer, &capacity);

    if (!buffer)
        return;

    conservativeRoots.add(buffer, static_cast<char*>(buffer) + size, jitStubRoutines, codeBlocks);
    fastFree(buffer);
}
コード例 #15
0
  void StringBuffer::append(const TCHAR* value, size_t appendedLength) {
  //Func - Appends a copy of the string value
  //Pre  - value != NULL
  //       appendedLength contains the length of the string value which is to be appended
  //Post - value has been copied and appended to the string in buffer 
  
      //Check if the current buffer length is sufficient to have the string value appended
      if (len + appendedLength + 1 > bufferLength){
          //Have the size of the current string buffer increased because it is too small	
          growBuffer(len + appendedLength + 1);
      }

      //Copy the string value into the buffer at postion len
      _tcsncpy(buffer + len, value, appendedLength);
    
      //Add the length of the copied string to len to reflect the new length of the string in
      //the buffer (Note: len is not the bufferlength!)
      len += appendedLength;
  }
コード例 #16
0
ファイル: EncodeBuffer.C プロジェクト: aywq2008/omniplay
void EncodeBuffer::encodeDirect(unsigned int value,
                               unsigned int numBits)
{
    unsigned remainingBits = numBits;

    assert(numBits <= (sizeof(unsigned) * 8));
    assert(numBits != 0);

    if (end - nextDest < 8)
    {
        growBuffer(8);
    }

    DBG("EncodeBuffer::encodeDirect: bits %d, freeBitsInDest = %d, value = 0x%08x\n",
         numBits, freeBitsInDest, value);

    // Copy a byte at a time, least significant bits first.
    while (remainingBits)
    {
        if (freeBitsInDest > remainingBits)
        {
            // We must left shift the value into place.
            value = value & PARTIAL_INT_MASK[remainingBits];
            value <<= (freeBitsInDest - remainingBits);
            *nextDest |= value;
            freeBitsInDest -= remainingBits;
            remainingBits = 0;
        }
        else
        {
            // We're using all available bits in nextDest, no shift needed.
            *nextDest |= value & PARTIAL_INT_MASK[freeBitsInDest];
            value >>= freeBitsInDest;

            remainingBits -= freeBitsInDest;

            *(++nextDest) = 0;
            freeBitsInDest = 8;
        }
    }
}
コード例 #17
0
  void StringBuffer::prepend(const TCHAR* value, const size_t prependedLength) {
  //Func - Puts a copy of the string value in front of the string in the StringBuffer
  //Pre  - value != NULL
  //       prependedLength contains the length of the string value which is to be prepended
  //Post - A copy of the string value is has been in front of the string in buffer
   //todo: something is wrong with this code, i'm sure... it only grows (and therefore moves if the buffer is to small)
	  //Check if the current buffer length is sufficient to have the string value prepended
	  if (prependedLength + len + 1 > bufferLength){
		  //Have the size of the current string buffer increased because it is too small	
		  //Because prependedLength is passed as the second argument to growBuffer,
          //growBuffer will have left the first prependedLength characters empty
          //when it recopied buffer during reallocation.  
          growBuffer(prependedLength + len + 1, prependedLength);
	  }

      //Copy the string value into the buffer at postion 0
      _tcsncpy(buffer, value, prependedLength);
      //Add the length of the copied string to len to reflect the new length of the string in
      //the buffer (Note: len is not the bufferlength!)
      len += prependedLength;
  }
コード例 #18
0
ファイル: gkDebugger.cpp プロジェクト: Draion/Gamekit
void gkDebugger::drawLine(const gkVector3& from, const gkVector3& to, const gkVector3& color)
{
	verifyNode();

	if (!m_node) return;

	DebugVertex v0, v1;
	Ogre::PixelUtil::packColour(color.x, color.y, color.z, 1.f, m_d3dColor ? Ogre::PF_A8R8G8B8 : Ogre::PF_A8B8G8R8, &v0.color);

	v0.v = from;
	v1.v = to;
	v1.color = v0.color;


	m_lineBuf.push_back(v0);
	m_lineBuf.push_back(v1);

	m_bbmin.makeFloor(v0.v);  m_bbmin.makeFloor(v1.v);
	m_bbmax.makeCeil(v0.v);   m_bbmax.makeCeil(v1.v);

	if (m_lineBuf.size() > m_bufSize)
		growBuffer(m_lineBuf.size() * 4);
}
コード例 #19
0
ファイル: graphics_shader.c プロジェクト: ezhangle/motor
static void sendFloatMatrices(lua_State *state, l_graphics_Shader* shader, graphics_ShaderUniformInfo const* info) {
  int components = graphics_shader_toMotorComponents(info->type);
  int count = min(lua_gettop(state) - 2, info->elements);
  growBuffer(sizeof(float) * components * components * count);

  float* numbers = (float*)moduleData.sendValueBuffer;

  for(int i = 0; i < count; ++i) {
    for(int j = 0; j < components; ++j) {
      // Get j-th inner table (== matrix column) of i-th outer table (== matrix)
      lua_rawgeti(state, i + 3, j + 1);
      for(int k = 0; k < components; ++k) {
        // Get k-th entry (== matrix row) of j-th inner table (== matrix column)
        lua_rawgeti(state, -1, k + 1);
        numbers[i*components*components+j*components+k] = l_tools_toNumberOrError(state, -1);
        lua_pop(state, 1);
      }
      lua_settop(state, count + 2);
    }
  }

  graphics_Shader_sendFloatMatrices(&shader->shader, info, count, numbers);
}
コード例 #20
0
ファイル: pl-gmp.c プロジェクト: SWI-Prolog/swipl
void
addMPZToBuffer(Buffer b, mpz_t mpz)
{ size_t size = (mpz_sizeinbase(mpz, 2)+7)/8;
  ssize_t hdrsize;
  size_t count;

  if ( !growBuffer(b, size+4) )
    outOfCore();
  if ( mpz_sgn(mpz) < 0 )
    hdrsize = -(ssize_t)size;
  else
    hdrsize = (ssize_t)size;
  DEBUG(1, Sdprintf("addMPZToBuffer(): Added %d bytes\n", size));

  *b->top++ = (char)((hdrsize>>24)&0xff);
  *b->top++ = (char)((hdrsize>>16)&0xff);
  *b->top++ = (char)((hdrsize>> 8)&0xff);
  *b->top++ = (char)((hdrsize    )&0xff);

  mpz_export(b->top, &count, 1, 1, 1, 0, mpz);
  assert(count == size);
  b->top = b->top + size;
}
コード例 #21
0
ファイル: omrfiletext.c プロジェクト: LinHu2016/omr
static intptr_t
file_write_using_iconv(struct OMRPortLibrary *portLibrary, intptr_t fd, const char *buf, intptr_t nbytes)
{
	intptr_t result = 0;
	char stackBuf[512];
	char *bufStart = NULL;
	uintptr_t outBufLen = sizeof(stackBuf);

	iconv_t converter = J9VM_INVALID_ICONV_DESCRIPTOR;
	size_t inbytesleft = 0;
	size_t outbytesleft = 0;
	char *inbuf = NULL;
	char *outbuf = NULL;
	intptr_t bytesToWrite = 0;

#ifdef J9ZOS390
	/* LIR 1280 (z/OS only) - every failed call to iconv_open() is recorded on the operator console, so don't retry */
	if (FALSE == PPG_file_text_iconv_open_failed) {
		/* iconv_get is not an a2e function, so we need to pass it honest-to-goodness EBCDIC strings */
#pragma convlit(suspend)
#endif

#ifndef OMRZTPF
		converter = iconv_get(portLibrary, J9FILETEXT_ICONV_DESCRIPTOR, nl_langinfo(CODESET), "UTF-8");
#else
		converter = iconv_get(portLibrary, J9FILETEXT_ICONV_DESCRIPTOR, "IBM1047", "ISO8859-1" );
#endif

#ifdef J9ZOS390
#pragma convlit(resume)
		if (J9VM_INVALID_ICONV_DESCRIPTOR == converter) {
			PPG_file_text_iconv_open_failed = TRUE;
		}
	}
#endif

	if (J9VM_INVALID_ICONV_DESCRIPTOR == converter) {
		/* no converter available for this code set. Just dump the UTF-8 chars */
		result = portLibrary->file_write(portLibrary, fd, (void *)buf, nbytes);
		return (result == nbytes) ? 0 : result;
	}

	inbuf = (char *)buf; /* for some reason this argument isn't const */
	outbuf = bufStart = stackBuf;
	inbytesleft = nbytes;
	outbytesleft = sizeof(stackBuf);

	while ((size_t)-1 == iconv(converter, &inbuf, &inbytesleft, &outbuf, &outbytesleft)) {
		int tmp_errno = errno;

		if (inbytesleft == 0) {
			break;
		}

		if ((outbytesleft == 0) || (tmp_errno == E2BIG)) {
			/* input conversion stopped due to lack of space in the output buffer */

			if (growBuffer(portLibrary, stackBuf, &bufStart, &outbuf, &outbytesleft, &outBufLen) < 0) {
				/* failed to grow buffer, just output what we've got so far */
				break;
			}

		} else if (tmp_errno == EILSEQ) {
			/* input conversion stopped due to an input byte that does not belong to the input code set */

			const char *unicodeFormat = "\\u%04x";
#define J9FILETEXT_ESCAPE_STR_SIZE 6 /* max size of unicode format */
			char escapedStr[J9FILETEXT_ESCAPE_STR_SIZE];
			char *escapedStrStart = escapedStr;

			uint16_t unicodeC = 0;
			size_t escapedLength = 0;
			size_t utf8Length = decodeUTF8CharN((const uint8_t *)inbuf, &unicodeC, inbytesleft);

			if (utf8Length == 0) {
				/* invalid encoding, including 4-byte UTF-8 */
				utf8Length = 1;
				escapedLength = 1;
				escapedStr[0] = '?';
			} else {
				escapedLength = portLibrary->str_printf(portLibrary, escapedStr, J9FILETEXT_ESCAPE_STR_SIZE, unicodeFormat, (uintptr_t)unicodeC);
			}

			inbytesleft -= utf8Length;
			inbuf += utf8Length;

			if ((size_t)-1 == iconv(converter, &escapedStrStart, &escapedLength, &outbuf, &outbytesleft)) {
				/* not handling EILSEQ here because:
				 *  1. we can't do much if iconv() fails to convert ascii.
				 *  2. inbuf and inbytesleft have been explicitly updated so the while loop will get terminated after converting the rest of the characters.
				 */

				tmp_errno = errno;

				/* if the remaining outbuf is too small, then grow it before storing Unicode string representation */
				if (tmp_errno == E2BIG) {
					if (growBuffer(portLibrary, stackBuf, &bufStart, &outbuf, &outbytesleft, &outBufLen) < 0) {
						/* failed to grow buffer, just output what we've got so far */
						break;
					}
				}
			}
		} else {
			/* input conversion stopped due to an incomplete character or shift sequence at the end of the input buffer */
			break;
		}
	}

	iconv_free(portLibrary, J9FILETEXT_ICONV_DESCRIPTOR, converter);

	/* CMVC 152575 - the converted string is not necessarily the same length in bytes as the original string */
	bytesToWrite = outbuf - bufStart;
	result = portLibrary->file_write(portLibrary, fd, (void *)bufStart, bytesToWrite);

	if (bufStart != stackBuf) {
		portLibrary->mem_free_memory(portLibrary, bufStart);
	}

	return (result == bytesToWrite) ? 0 : result;
}
コード例 #22
0
am_status_t Connection::waitForReply(char *&buffer,
					std::size_t bufferLen,
					std::size_t totalBytesRead,
					std::size_t& receivedLen)
{
    am_status_t status = AM_SUCCESS;

    if (static_cast<char *>(NULL) == buffer || 0 == bufferLen) {
	if (0 == bufferLen) {
	    bufferLen = DEFAULT_BUFFER_LEN;
	}
	totalBytesRead = 0;	// Ignore any value that was passed in.
	buffer = new (std::nothrow) char[bufferLen];
    }

    if (static_cast<char *>(NULL) != buffer) {
	std::size_t bytesToRead = bufferLen - totalBytesRead;

	status = read(&buffer[totalBytesRead], bytesToRead);
	while (status == AM_SUCCESS && bytesToRead > 0) {
	    totalBytesRead += bytesToRead;
	    bytesToRead = bufferLen - totalBytesRead;
	    if (bytesToRead <= MIN_BYTES_TO_READ) {
		// If the new buffer size is smaller than the INCREMENT_LEN
		// we grow the buffer by doubling the size.  If the current
		// size is less than the INCREMENT_LEN, but the new size is
		// greater than we use INCREMENT_LEN as the new buffer size,
		// otherwise add INCREMENT_LEN.  The order of the tests is
		// rearranged from the prose to reflect the expected
		// probability of each situation occurring.
		if ((2 * bufferLen) <= INCREMENT_LEN) {
		    bufferLen *= 2;
		} else if (bufferLen >= INCREMENT_LEN) {
		    bufferLen += INCREMENT_LEN;
		} else {
		    bufferLen = INCREMENT_LEN;
		}

		buffer = growBuffer(buffer, totalBytesRead, bufferLen);
		if (static_cast<char *>(NULL) == buffer) {
		    status = AM_NO_MEMORY;
		    break;
		}

		bytesToRead = bufferLen - totalBytesRead;
	    }

	    status = read(&buffer[totalBytesRead], bytesToRead);
	}

	if (AM_SUCCESS == status) {
	    if (totalBytesRead == bufferLen) {
		buffer = growBuffer(buffer, totalBytesRead,
				    totalBytesRead + 1);
		if (static_cast<char *>(NULL) == buffer) {
		    status = AM_NO_MEMORY;
		}
	    }

	    if (AM_SUCCESS == status) {
		buffer[totalBytesRead] = '\0';
		receivedLen = totalBytesRead;
	    }
	} 
    } else {
	status = AM_NO_MEMORY;
    }

    Log::log(Log::ALL_MODULES, Log::LOG_MAX_DEBUG,
	     "Connection::waitForReply(): returns with status %s.",
	     am_status_to_string(status));

    return status;
}
コード例 #23
0
ファイル: entities.c プロジェクト: KB3NZQ/hydrairc
/**
 * xmlEncodeEntities:
 * @doc:  the document containing the string
 * @input:  A string to convert to XML.
 *
 * Do a global encoding of a string, replacing the predefined entities
 * and non ASCII values with their entities and CharRef counterparts.
 *
 * TODO: remove xmlEncodeEntities, once we are not afraid of breaking binary
 *       compatibility
 *
 * People must migrate their code to xmlEncodeEntitiesReentrant !
 * This routine will issue a warning when encountered.
 * 
 * Returns A newly allocated string with the substitution done.
 */
const xmlChar *
xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) {
    const xmlChar *cur = input;
    xmlChar *out = static_buffer;
    static int warning = 1;
    int html = 0;


    if (warning) {
    xmlGenericError(xmlGenericErrorContext,
	    "Deprecated API xmlEncodeEntities() used\n");
    xmlGenericError(xmlGenericErrorContext,
	    "   change code to use xmlEncodeEntitiesReentrant()\n");
    warning = 0;
    }

    if (input == NULL) return(NULL);
    if (doc != NULL)
        html = (doc->type == XML_HTML_DOCUMENT_NODE);

    if (static_buffer == NULL) {
        static_buffer_size = 1000;
        static_buffer = (xmlChar *) xmlMalloc(static_buffer_size * sizeof(xmlChar));
	if (static_buffer == NULL) {
	    perror("malloc failed");
            return(NULL);
	}
	out = static_buffer;
    }
    while (*cur != '\0') {
        if (out - static_buffer > static_buffer_size - 100) {
	    int indx = out - static_buffer;

	    growBuffer();
	    out = &static_buffer[indx];
	}

	/*
	 * By default one have to encode at least '<', '>', '"' and '&' !
	 */
	if (*cur == '<') {
	    *out++ = '&';
	    *out++ = 'l';
	    *out++ = 't';
	    *out++ = ';';
	} else if (*cur == '>') {
	    *out++ = '&';
	    *out++ = 'g';
	    *out++ = 't';
	    *out++ = ';';
	} else if (*cur == '&') {
	    *out++ = '&';
	    *out++ = 'a';
	    *out++ = 'm';
	    *out++ = 'p';
	    *out++ = ';';
	} else if (*cur == '"') {
	    *out++ = '&';
	    *out++ = 'q';
	    *out++ = 'u';
	    *out++ = 'o';
	    *out++ = 't';
	    *out++ = ';';
	} else if ((*cur == '\'') && (!html)) {
	    *out++ = '&';
	    *out++ = 'a';
	    *out++ = 'p';
	    *out++ = 'o';
	    *out++ = 's';
	    *out++ = ';';
	} else if (((*cur >= 0x20) && (*cur < 0x80)) ||
	    (*cur == '\n') || (*cur == '\r') || (*cur == '\t')) {
	    /*
	     * default case, just copy !
	     */
	    *out++ = *cur;
#ifndef USE_UTF_8
	} else if ((sizeof(xmlChar) == 1) && (*cur >= 0x80)) {
	    char buf[10], *ptr;

	    snprintf(buf, sizeof(buf), "&#%d;", *cur);
            buf[sizeof(buf) - 1] = 0;
            ptr = buf;
	    while (*ptr != 0) *out++ = *ptr++;
#endif
	} else if (IS_CHAR(*cur)) {
	    char buf[10], *ptr;

	    snprintf(buf, sizeof(buf), "&#%d;", *cur);
            buf[sizeof(buf) - 1] = 0;
            ptr = buf;
	    while (*ptr != 0) *out++ = *ptr++;
	}
#if 0
	else {
	    /*
	     * default case, this is not a valid char !
	     * Skip it...
	     */
	    xmlGenericError(xmlGenericErrorContext,
		    "xmlEncodeEntities: invalid char %d\n", (int) *cur);
	}
#endif
	cur++;
    }
    *out++ = 0;
    return(static_buffer);
}