pike.git / src / modules / _Stdio / buffer.cmod

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:1775:    }       /*! @decl string(8bit) read_cstring( )    *!    *! Reads a \0 terminated C-string and returns the    *! string excluding the terminating \0.    *!    *! If there is not enough data available return UNDEFINED.    *!    *! Note that pike string can not be longer than 0x7fffffff bytes (~2Gb). +  *! +  *! @seealso +  *! @[_search()]    */    PIKEFUN string(0..255) read_cstring()    {    Buffer *io = THIS;       do    if ( LIKELY(io_len(THIS)) )    {    const unsigned char * start = io_read_pointer(io);    const unsigned char * end = memchr(start, 0, io_len(io));
pike.git/src/modules/_Stdio/buffer.cmod:1797:    push_string(io_read_string(io, end - start));    io_read_byte_uc(io); /* consume the terminating \0 byte */    return;    }    }    while ( UNLIKELY(io_range_error(THIS, 0)) );       push_undefined();    }    +  /*! @decl protected int(-1..) _search(int(8bit) character, int|void start) +  *! +  *! Search forward from the indicated @[start] position for the specified +  *! @[character]. +  *! +  *! @param character +  *! Character to search for. +  *! +  *! @param start +  *! Start position relative to the current read position of the buffer. +  *! +  *! Negative @[start] values are supported and indicate positions +  *! prior to the current read position. +  *! +  *! @returns +  *! Returns the first found position of @[character] relative to the +  *! current read position of the buffer on success, and @[UNDEFINED] +  *! on not found. The read position is not advanced. +  *! +  *! @seealso +  *! @[read_cstring()], @[search()], @[lfun::_search()] +  */ +  PIKEFUN int _search(int(8bit) character, int|void start) +  flags ID_PROTECTED; +  { +  Buffer *io = THIS; +  unsigned char *buf = io_read_pointer(io); +  unsigned char *buf_start = buf; +  unsigned char *buf_end = buf + io_len(io); +  +  if (start) { +  INT_TYPE bytes = start->u.integer; +  buf_start += bytes; +  +  if (bytes >= 0) { +  if (((size_t)bytes) >= io_len(io)) { +  push_int(-1); +  return; +  } +  } else if (((size_t)(-bytes)) > io->offset) { +  bytes = -(ptrdiff_t)io->offset; +  } +  buf += bytes; +  } +  +  while (buf < buf_end) { +  if (UNLIKELY(*buf == character)) { +  push_int64(buf - io_read_pointer(io)); +  return; +  } +  buf++; +  } +  +  push_int(-1); +  } +     /*! @decl Buffer read_hbuffer( int n )    *! @decl Buffer read_hbuffer( int n, bool copy )    *!    *! Same as @[read_hstring], but returns the result as an Buffer.    *!    *! No data is copied unless @[copy] is specified and true, the new    *! buffer points into the old one.    *!    *! @note    *! As long as the subbuffer exists no data can be added to the