Skip to content

Commit

Permalink
new: first implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Mar 10, 2024
1 parent 273c35f commit 23edf77
Show file tree
Hide file tree
Showing 15 changed files with 2,142 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
38 changes: 38 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Rust CI

on:
push:
branches: [ '*', '*/*' ]

jobs:
test:
name: Test for Rust ${{ matrix.rustver }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
rustver: ['1.67.1', '1.70.0', stable]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rustver }}
- run: cargo test

cover:
name: Coverage for Rust ${{ matrix.rustver }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
rustver: [stable]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rustver }}
components: llvm-tools-preview
- run: cargo install cargo-llvm-cov
- run: cargo llvm-cov
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# OS generating files
.DS_Store
Thumbs.db

# Generated by cargo
Cargo.lock
/target/
/benches/*
!/benches/*.rs
!/benches/*.md
19 changes: 19 additions & 0 deletions .gitmessage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


####### 50 characters ###########################
## Prefix examples:
#
# new: a new feature
# fix: a bug fix
# update: a slight change
# merge: merge pull request
# style: only code style changes
# comment: only comment changes
# refactor: code changes that do not affect the behavior
# perf: a code change that improves performance
# deps: bump deps used on compiling or runtime
# test: update test files
# cicd: update CI/CD configuration files.
# doc: documentation only changes
# wip: work in progress
# chore: bump test deps, modify build files, etc
18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "linebreak"
version = "0.1.0"
authors = ["Takayuki Sato <sttk.xslet@gmail.com>"]
edition = "2021"
rust-version = "1.67.1"
description = "A library for breaking a given text into lines within a specified width."
documentation = "https://docs.rs/linebreak"
readme = "README.md"
repository = "https://github.com/sttk/linebreak-rust"
license = "MIT"
keywords = ["line", "break", "wrap"]
categories = ["text-processing"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
icu = "1.4.0"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Takayuki Sato

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# [linebreak-rust][repo-url] [![crate.io][crateio-img]][crateio-url] [![doc.rs][docrs-img]][docrs-url] [![CI Status][ci-img]][ci-url] [![MIT License][mit-img]][mit-url]

A library for breaking a given text into lines within a specified width. This library also supports per-line indentation.

## Install

In `Cargo.toml`, write this crate as a dependency.

```toml
[dependencies]
linebreak = "0.1.0"
```

## Usage

The usage example of `LineIter` struct in this crate is as follows:

```rust
use linebreak::LineIter;

fn main() {
let text = "Welcome to The Rust Programming Language, an introductory \
book about Rust. The Rust programming language helps you write faster, \
more reliable software. High-level ergonomics and low-level control are \
often at odds in programming language design; Rust challenges that \
conflict. Through balancing powerful technical capacity and a great \
developer experience, Rust gives you the option to control low-level \
details (such as memory usage) without all the hassle traditionally \
associated with such control.";

let mut iter = LineIter::new(&text, 80);
iter.set_indent("_______");

println!("....:....1....:....2....:....3....:....4....:....5....:....6\
....:....7....:....8");
while let Some(line) = iter.next() {
println!("{}", line);
}
}
```

The output of the above code is as follows:

```
....:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8
_______Welcome to The Rust Programming Language, an introductory book about
_______Rust. The Rust programming language helps you write faster, more reliable
_______software. High-level ergonomics and low-level control are often at odds
_______in programming language design; Rust challenges that conflict. Through
_______balancing powerful technical capacity and a great developer experience,
_______Rust gives you the option to control low-level details (such as memory
_______usage) without all the hassle traditionally associated with such control.
```

## Supporting Rust versions

This crate supports Rust 1.67.1 or later.

```
% cargo msrv
Fetching index
Determining the Minimum Supported Rust Version (MSRV) for toolchain x86_64-apple-darwin
Using check command cargo check
Check for toolchain '1.66.1-x86_64-apple-darwin' failed with:
┌───────────────────────────────────────────────────────────────────────────────────────┐
│ error: package `icu_locid v1.4.0` cannot be built because it requires rustc 1.67 or │
│ newer, while the currently active rustc version is 1.66.1 │
│ Either upgrade to rustc 1.67 or newer, or use │
│ cargo update -p icu_locid@1.4.0 --precise ver │
│ where `ver` is the latest version of `icu_locid` supporting rustc 1.66.1 │
└───────────────────────────────────────────────────────────────────────────────────────┘
Check for toolchain '1.71.1-x86_64-apple-darwin' succeeded
Check for toolchain '1.68.2-x86_64-apple-darwin' succeeded
Check for toolchain '1.67.1-x86_64-apple-darwin' succeeded
Finished The MSRV is: 1.67.1 ██████████████████████████████████████████████ 00:02:18
```

## License

Copyright (C) 2024 Takayuki Sato

This program is free software under MIT License.<br>
See the file LICENSE in this distribution for more details.


[repo-url]: https://github.com/sttk/linebreak-rust
[crateio-img]: https://img.shields.io/badge/crate.io-ver.0.1.0-fc8d62?logo=rust
[crateio-url]: https://crates.io/crates/linebreak
[docrs-img]: https://img.shields.io/badge/doc.rs-linebreak-66c2a5?logo=docs.rs
[docrs-url]: https://docs.rs/linebreak
[ci-img]: https://github.com/sttk/linebreak-rust/actions/workflows/rust.yml/badge.svg?branch=main
[ci-url]: https://github.com/sttk/linebreak-rust/actions
[mit-img]: https://img.shields.io/badge/license-MIT-green.svg
[mit-url]: https://opensource.org/licenses/MIT
98 changes: 98 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

errcheck() {
exitcd=$1
if [[ "$exitcd" != "0" ]]; then
exit $exitcd
fi
}

clean() {
cargo clean
errcheck $?
}

format() {
cargo fmt
errcheck $?
}

compile() {
cargo build
errcheck $?
}

test() {
cargo test -- --show-output
errcheck $?
}

unit() {
cargo test -- --show-output $1
errcheck $?
}

cover() {
cargo llvm-cov clean
errcheck $?
cargo llvm-cov --html --quiet
errcheck $?
cargo llvm-cov report
errcheck $?
}

bench() {
cargo +nightly bench --quiet -- $1
errcheck $?
}

doc() {
cargo doc
errcheck $?
}

if [[ "$#" == "0" ]]; then
clean
format
compile
test
doc
cover

elif [[ "$1" == "unit" ]]; then
unit $2

else
for a in "$@"; do
case "$a" in
clean)
clean
;;
format)
format
;;
compile)
compile
;;
test)
test
;;
doc)
doc
;;
cover)
cover
;;
bench)
bench
;;
'')
compile
;;
*)
echo "Bad task: $a"
exit 1
;;
esac
done
fi

0 comments on commit 23edf77

Please sign in to comment.