bufferreader


Namebufferreader JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryText buffer with a pointer to line number and character number.
upload_time2024-10-15 10:16:29
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords buffer text string parse
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
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`:

```python
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](LICENSE) file for more details.

## Contact

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

-   GitHub: [@vladimirjo](https://github.com/vladimirjo)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bufferreader",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "buffer, text, string, parse",
    "author": null,
    "author_email": "Vladimir Jovanovic <vladimirjo@protonmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6f/fe/b9624826beb8186d835aee0e06c85352c7f7728e4789fdc54aad7d900700/bufferreader-1.0.0.tar.gz",
    "platform": null,
    "description": "# BufferReader\n\n`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.\n\n## Features\n\n-   **Pointer-Based Navigation**: Move a pointer through a text buffer, both forward and backward.\n-   **Range-Based Reading**: Read specific ranges of characters between positions, capturing multi-line content.\n-   **No Exceptions for Pointer Movement**: Returns `True` or `False` based on success, avoiding pointer movement errors.\n-   **Custom Step Sizes**: Control forward and backward step sizes for movement operations.\n-   **Stateful Stream**: The `stream` attribute stores the current set of characters read from the buffer.\n\n## Installation\n\nClone the repository:\n\n```bash\ngit clone https://github.com/vladimirjo/bufferreader.git\n```\n\nNavigate to the directory:\ncd bufferreader\n\nSince this is a standalone Python class, no additional dependencies are required.\n\n## Usage\n\nBelow is a simple example demonstrating how to use `BufferReader`:\n\n```python\nfrom bufferreader import BufferReader\n\nbuffer = \"Hello\\nWorld\\nThis is BufferReader!\"\nreader = BufferReader(buffer)\n\n# Read the first 5 characters\nreader.read(0, 4)\nprint(reader.stream)  # Output: Hello\n\n# Move to the next character\nreader.next()\nprint(reader.stream)  # Output: \\n (newline character)\n\n# Move back to the previous character\nreader.before()\nprint(reader.stream)  # Output: o\n\n# Set the pointer to a specific position (line 1, character 0)\nreader.set_pointer(1, 0)\nprint(reader.stream)  # Output: W (from \"World\")\n```\n\n## API Reference\n\n### Class: `BufferReader`\n\nThe `BufferReader` class handles reading and pointer navigation within a text buffer.\n\n#### Attributes:\n\n-   `stream (str)`: Stores the current character(s) from the last read operation.\n-   `line_pointer (int)`: The current line index in the buffer (starts at 0).\n-   `char_pointer (int)`: The current character index within the current line.\n-   `steps_forward (int)`: Tracks how many characters to move forward.\n-   `steps_back (int)`: Tracks how many characters to move backward.\n\n#### Methods:\n\n-   **`move(steps: int) -> bool`**\n    Moves the pointer forward or backward by the specified number of steps.\n\n-   **`read(start: int = 0, end: int = 0) -> bool`**\n    Reads the buffer between the specified start and end positions. Updates the `stream` with the result.\n\n-   **`next() -> bool`**\n    Moves the pointer forward by the last read operation's length.\n\n-   **`before() -> bool`**\n    Moves the pointer backward by the last read operation's length.\n\n-   **`reset() -> None`**\n    Resets the stream to the character at the current pointer position and resets step sizes.\n\n-   **`set_pointer(line_pointer: int, char_pointer: int) -> bool`**\n    Moves the pointer to a specific line and character position. Returns `False` if the indices are out of bounds.\n\n## Contributing\n\nContributions are welcome! If you have suggestions for improvements, feel free to open an issue or submit a pull request.\n\n### Steps to Contribute:\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature-branch`).\n3. Make your changes.\n4. Submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Contact\n\nFor any inquiries or issues, feel free to reach out:\n\n-   GitHub: [@vladimirjo](https://github.com/vladimirjo)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Text buffer with a pointer to line number and character number.",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [
        "buffer",
        " text",
        " string",
        " parse"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "284d4dbb5d1014d4df3d7d07815f73e9eb33efdad1e9811aaab2ba3f0cd8971d",
                "md5": "3e128cce512b61eca20bc48e202660e4",
                "sha256": "6b8ecf55dd4ac09d9c6bbba6a76f6842add94bd602672eeaae7447a41601d175"
            },
            "downloads": -1,
            "filename": "bufferreader-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e128cce512b61eca20bc48e202660e4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6592,
            "upload_time": "2024-10-15T10:16:27",
            "upload_time_iso_8601": "2024-10-15T10:16:27.554399Z",
            "url": "https://files.pythonhosted.org/packages/28/4d/4dbb5d1014d4df3d7d07815f73e9eb33efdad1e9811aaab2ba3f0cd8971d/bufferreader-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ffeb9624826beb8186d835aee0e06c85352c7f7728e4789fdc54aad7d900700",
                "md5": "3e78fb9b6734fede9e6d8d33c9c6185c",
                "sha256": "3fc7f5c3f3f92866e4d1c0d3c9819c9a03500bd4ea368e3b726fbe69db6fbdcd"
            },
            "downloads": -1,
            "filename": "bufferreader-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3e78fb9b6734fede9e6d8d33c9c6185c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 6880,
            "upload_time": "2024-10-15T10:16:29",
            "upload_time_iso_8601": "2024-10-15T10:16:29.410443Z",
            "url": "https://files.pythonhosted.org/packages/6f/fe/b9624826beb8186d835aee0e06c85352c7f7728e4789fdc54aad7d900700/bufferreader-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-15 10:16:29",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "bufferreader"
}
        
Elapsed time: 3.09166s