InfText.Chunk

Fields

None

Methods

class

new (encoding)

copy ()

equal (other)

erase (begin, length)

free ()

get_encoding ()

get_length ()

get_text ()

insert_chunk (offset, text)

insert_text (offset, text, bytes, length, author)

iter_init_begin ()

iter_init_end ()

substring (begin, length)

Details

class InfText.Chunk

InfText.Chunk is an opaque data type. You should only access it via the public API functions.

classmethod new(encoding)
Parameters:

encoding (str) – A content encoding, such as “UTF-8” or “LATIN1”.

Returns:

A new InfText.Chunk.

Return type:

InfText.Chunk

Creates a new InfText.Chunk with no initial content that holds text in the given encoding. TODO: Allow binary data with None encoding.

copy()
Returns:

A new InfText.Chunk.

Return type:

InfText.Chunk

Returns a copy of self.

equal(other)
Parameters:

other (InfText.Chunk) – Another InfText.Chunk.

Returns:

Whether the two chunks are equal.

Return type:

bool

Returns whether the two text chunks contain the same text and the same segments were written by the same authors.

erase(begin, length)
Parameters:
  • begin (int) – A character offset into self.

  • length (int) – Number of characters to erase.

Removes length characters of self, starting from character offset begin.

free()

Frees a InfText.Chunk allocated with InfText.Chunk.new(), InfText.Chunk.copy() or InfText.Chunk.substring().

get_encoding()
Returns:

The encoding of self.

Return type:

str

Returns the character encoding in which the content of self is encoded.

get_length()
Returns:

The number of characters of self.

Return type:

int

Returns the number of characters contained in self.

get_text()
Returns:

Content of self. Free with GLib.free() if no longer in use.

Return type:

bytes

Returns the content of self as an array. The text is encoded in self's encoding. length is set to the number of bytes in the returned buffer, if non-None. The result is _not_ zero-terminated.

insert_chunk(offset, text)
Parameters:
  • offset (int) – Character offset at which to insert text.

  • text (InfText.Chunk) – Chunk to insert into self.

Inserts text into self at position offset. text and self must have the same encoding.

insert_text(offset, text, bytes, length, author)
Parameters:
  • offset (int) – Character offset at which to insert text text (type const guint8*) (array length=bytes) (transfer none): Text to insert.

  • text (object or None) –

  • bytes (int) – Number of bytes of text.

  • length (int) – Number of characters contained in text.

  • author (int) – User that wrote text.

Inserts text written by author into self. text is expected to be in the chunk’s encoding.

iter_init_begin()
Returns:

Whether iter was set.

iter:

A InfText.ChunkIter.

Return type:

(bool, iter: InfText.ChunkIter)

Sets iter to point to the first segment of self. If there are no segments (i.e. self is empty), iter is left untouched and the function returns False.

iter_init_end()
Returns:

Whether iter was set.

iter:

A InfText.ChunkIter.

Return type:

(bool, iter: InfText.ChunkIter)

Sets iter to point to the last segment of self. If there are no segments (i.e. self is empty), iter is left untouched and the function returns False.

substring(begin, length)
Parameters:
  • begin (int) – A character offset into self.

  • length (int) – The length of the text to extract.

Returns:

A new InfText.Chunk.

Return type:

InfText.Chunk

Returns a new InfText.Chunk containing a substring of self, beginning at character offset begin and length characters long.