Iterate Text

Library of helper functions and structures for iterating over text and files

Byte size of Iterate Text Open Issues Open Pull Requests Latest commits Build Status



Requirements

This repository requires Rust language/compiler to build from source

As of last update to this ReadMe file, the recommended method of installing Rust is via the installer script...

bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh


Quick Start

This repository is a Rust library, define it as a dependency within a project Cargo.toml file...

Cargo.toml (snip)

toml [dependencies] iterate-text = "0.0.1"

Check Rust -- Doc -- Specifying Dependencies for details about defining dependencies.

Then include within a source file via use statement...

src/main.rs (snip)

```rust extern crate iterate_text;

use iteratetext::file::characters::IterateFileCharacters; use iteratetext::file::lines::IterateFileLines;

use iteratetext::string::characters::IterateStringCharacters; use iteratetext::string::lines::IterateStringLines; ```


Usage

Check the examples/ directory of this project for detailed usage examples.

src/main.rs

```rust

!/usr/bin/env rust

use std::env;

extern crate iteratetext; use iteratetext::file::lines::IterateFileLines;

fn main() { let args: Vec = env::args().collect();

let path = &args[1];
let iter = IterateFileLines::new(path.into());

let mut count = 0;
for line in iter {
    count += 1;
    print!("{}: {}", count, line);
}

} ```


API

Documentation for classes, methods, parameters, and custom types/data-structures


file::characters::IterateFileCharacters

Reads from path, buffer, or descriptor and iterates over characters until EOF is reached

Example

```rust use iterate_text::file::characters::IterateFileCharacters;

let p = "tests/file/characters/file.txt"; let mut c = IterateFileCharacters::new(p);

asserteq!(c.next(), Some('T')); asserteq!(c.next(), Some('h')); asserteq!(c.next(), Some('i')); asserteq!(c.next(), Some('s')); ```


file::lines::IterateFileLines

Reads from file path, buffer, or descriptor and iterates over lines until EOF is reached

```rust use iterate_text::file::lines::IterateFileLines;

let p = "tests/file/lines/file.txt"; let mut l = IterateFileLines::new(p);

asserteq!(l.next(), Some("First line\n".tostring())); asserteq!(l.next(), Some("Second line\n".tostring())); asserteq!(l.next(), Some("Third line\n".tostring())); assert_eq!(l.next(), None); ```


string::characters::IterateStringCharacters

Iterates over characters within string

Example

```rust use iterate_text::string::characters::IterateStringCharacters;

let s = String::from("test!"); let mut c = IterateStringCharacters::new(s);

asserteq!(c.next(), Some('t')); asserteq!(c.next(), Some('e')); asserteq!(c.next(), Some('s')); asserteq!(c.next(), Some('t')); asserteq!(c.next(), Some('!')); asserteq!(c.next(), None); ```


string::lines::IterateStringLines

Iterates over lines within string and includes new-line separator

Example

```rust use iterate_text::string::lines::IterateStringLines;

let s = String::from("This is\na \n test string\n"); let mut l = IterateStringLines::new(s);

asserteq!(l.next(), Some("This is\n".tostring())); asserteq!(l.next(), Some("a \n test string\n".tostring())); assert_eq!(l.next(), None); ```


Notes

The characters iterators currently use String.char_indices() which may split certain Unicode characters in unexpected ways.

This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.


Contributing

Options for contributing to iterate-text and rust-utilities


Forking

Start making a Fork of this repository to an account that you have write permissions for.

```bash mkdir -p ~/git/hub/rust-utilities

cd ~/git/hub/rust-utilities/iterate-text

git remote add fork git@github.com:/iterate-text.git ```

bash cargo test

bash cargo run --example file-reader -- --file .github/README.md -c 10

```bash cd ~/git/hub/rust-utilities/iterate-text

git commit -F- <<'EOF' :bug: Fixes #42 Issue

Edits

git push fork main ```

Note, the -u option may be used to set fork as the default remote, eg. git push -u fork main however, this will also default the fork remote for pulling from too! Meaning that pulling updates from origin must be done explicitly, eg. git pull origin main

Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.


Sponsor

Thanks for even considering it!

Via Liberapay you may ![sponsorshields_ioliberapay] on a repeating basis.

Regardless of if you're able to financially support projects such as iterate-text that rust-utilities maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.


Attribution


License

``` Library of helper functions and structures for iterating over text and files Copyright (C) 2021 S0AndS0

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/. ```

For further details review full length version of AGPL-3.0 License.