Skip to main content

Text buffer with a pointer to line number and character number.

Project description

BufferReader

BufferReader is a Python class designed for efficient navigation and reading of a multi-line text buffer. This tool provides the ability to move a pointer through the buffer, read specified ranges of characters, and manage pointer movement without raising exceptions. Instead, it returns status flags (True/False) for pointer movement operations, allowing seamless error handling.

Features

  • Pointer-Based Navigation: Move a pointer through a text buffer, both forward and backward.
  • Range-Based Reading: Read specific ranges of characters between positions, capturing multi-line content.
  • No Exceptions for Pointer Movement: Returns True or False based on success, avoiding pointer movement errors.
  • Custom Step Sizes: Control forward and backward step sizes for movement operations.
  • Stateful Stream: The stream attribute stores the current set of characters read from the buffer.

Installation

Clone the repository:

git clone https://github.com/vladimirjo/bufferreader.git

Navigate to the directory: cd bufferreader

Since this is a standalone Python class, no additional dependencies are required.

Usage

Below is a simple example demonstrating how to use BufferReader:

from bufferreader import BufferReader

buffer = "Hello\nWorld\nThis is BufferReader!"
reader = BufferReader(buffer)

# Read the first 5 characters
reader.read(0, 4)
print(reader.stream)  # Output: Hello

# Move to the next character
reader.next()
print(reader.stream)  # Output: \n (newline character)

# Move back to the previous character
reader.before()
print(reader.stream)  # Output: o

# Set the pointer to a specific position (line 1, character 0)
reader.set_pointer(1, 0)
print(reader.stream)  # Output: W (from "World")

API Reference

Class: BufferReader

The BufferReader class handles reading and pointer navigation within a text buffer.

Attributes:

  • stream (str): Stores the current character(s) from the last read operation.
  • line_pointer (int): The current line index in the buffer (starts at 0).
  • char_pointer (int): The current character index within the current line.
  • steps_forward (int): Tracks how many characters to move forward.
  • steps_back (int): Tracks how many characters to move backward.

Methods:

  • move(steps: int) -> bool Moves the pointer forward or backward by the specified number of steps.

  • read(start: int = 0, end: int = 0) -> bool Reads the buffer between the specified start and end positions. Updates the stream with the result.

  • next() -> bool Moves the pointer forward by the last read operation's length.

  • before() -> bool Moves the pointer backward by the last read operation's length.

  • reset() -> None Resets the stream to the character at the current pointer position and resets step sizes.

  • set_pointer(line_pointer: int, char_pointer: int) -> bool Moves the pointer to a specific line and character position. Returns False if the indices are out of bounds.

Contributing

Contributions are welcome! If you have suggestions for improvements, feel free to open an issue or submit a pull request.

Steps to Contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

For any inquiries or issues, feel free to reach out:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bufferreader-1.0.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

bufferreader-1.0.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file bufferreader-1.0.0.tar.gz.

File metadata

  • Download URL: bufferreader-1.0.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for bufferreader-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3fc7f5c3f3f92866e4d1c0d3c9819c9a03500bd4ea368e3b726fbe69db6fbdcd
MD5 3e78fb9b6734fede9e6d8d33c9c6185c
BLAKE2b-256 6ffeb9624826beb8186d835aee0e06c85352c7f7728e4789fdc54aad7d900700

See more details on using hashes here.

File details

Details for the file bufferreader-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bufferreader-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for bufferreader-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b8ecf55dd4ac09d9c6bbba6a76f6842add94bd602672eeaae7447a41601d175
MD5 3e128cce512b61eca20bc48e202660e4
BLAKE2b-256 284d4dbb5d1014d4df3d7d07815f73e9eb33efdad1e9811aaab2ba3f0cd8971d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page