HomeContentsContents
buf_replace() buf_to_str() buf_to_strings()
bufgraft() bufidx() buflen()
str_to_buf() strings_to_buf() subbuf()

buf_replace()

BUFFER buf_replace(BUFFER buf, INTEGER pos, INTEGER char)

This function replaces the character in the buffer at position pos with the character specified by the integer char.


        buf_replace(`[98, 111, 111], 1, 102)
            => `[102, 111, 111]
    

The function bufgraft() performs a similar role.

Top

buf_to_str()

STRING buf_to_str(BUFFER buf)

This function converts the buffer specified by buf to a string.


        buf_to_str(`[72, 101, 108, 108, 111])
            => "Hello"
    
Top

buf_to_strings()

LIST buf_to_strings(BUFFER buf[, BUFFER sep])

This function converts the buffer specified by buf to a list of printable strings, with a final buffer element. Each string is a line in the buffer, terminated by a newline (`[13, 10]). If any characters remain unterminated, they are placed in the last element as a buffer. The last element will always be a buffer, regardless of whether any characters are in it.

This function will alternatively split the strings based off the optional second argument sep. Note: it is not necessary to specify both a carriage return and a newline as the seperator—if both exist—as the newline will be sufficient to break the string, and the carriage return will be discarded as an unprintable character in the string.


        buf_to_strings(`[72, 101, 108, 108, 111, 13, 10, 119, 111, 114, 108, 100, 13, 10, 33])
            => ["Hello", "world", `[33]]
    
Top

bufgraft()

BUFFER bufgraft(BUFFER buf, INTEGER pos, BUFFER what)

This function will graft the buffer what into the buffer buf at pos.


        bufgraft(`[1, 2, 3, 4], 2, `[100, 100])
            => `[1, 100, 100, 2, 3, 4]
    
Top

bufidx()

INTEGER bufidx(BUFFER buf, BUFFER|INTEGER what[, INTEGER origin])

This function returns either the position—starting from origin—in bufwhere what exists or a zero if what does not exist. If origin is not specified it will default to 1. If what is an integer, it is equivalent to `[what]. The origin represents where to start searching in the buffer. If it is a positive number it starts that many elements into the buffer. If it is a negative number it starts that many elements from the end of the buffer, and searches backwards from the end of the buffer to the start.


        bufidx(`[1, 7, 1, 6, 7, 1], 7)
            => 2 

        bufidx(`[1, 7, 1, 6, 7, 1], 7, -1)
            => 5 

        bufidx(`[1, 7, 1, 6, 7, 1], `[6, 7])
            => 4 

        bufidx(`[1, 7, 1, 6, 7, 1], `[6, 8])
            => 0
    
Top

buflen()

INTEGER buflen(BUFFER buf)

This function returns the length of the buffer buf.


        buflen(`[72, 101, 108, 108, 111])
            => 5
    
Top

str_to_buf()

BUFFER str_to_buf(STRING str)

This function converts the string specified by the argument str to a buffer. The character sequence "\n" will be converted to a carriage return and line feed (`[13, 10]).


        str_to_buf("Hello\n")
            => `[72, 101, 108, 108, 111, 13, 10]
    
Top

strings_to_buf()

BUFFER strings_to_buf(LIST strings[, BUFFER sep])

This function builds a buffer from the strings given in the list strings. Each string represents a line which is terminated with a carriage return and a newline (`[13, 10]). If the argument sep is specified, each string is terminated with that value instead.


        strings_to_buf(["a", "b", "c"])
            => `[97, 13, 10, 98, 13, 10, 99, 13, 10]

        strings_to_buf(["a", "b", "c"], `[32])
            => `[97, 32, 98, 32, 99, 32]
    
Top

subbuf()

BUFFER subbuf(BUFFER buf, INTEGER start[, INTEGER length])

This function returns a subrange of the buffer specified by buf. The subrange starts at position start, and continues length characters. If length is unspecified, it will continue to the end of the buffer. If start is outside of the range of the buffer, or length will extend past the end of the buffer, the error ~range is thrown.


        subbuf(`[1, 2, 3, 4], 2, 2)
            => `[2, 3]
    
Top

Contents Previous Next Index

Valid XHTML 1.0 Strict