Skip to content

Commit 1532fcc

Browse files
committed
feat: change the new version files
1 parent 44f8556 commit 1532fcc

11 files changed

Lines changed: 281 additions & 116 deletions

File tree

.github/workflows/test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: test
2+
on:
3+
- push
4+
jobs:
5+
# Task test
6+
test:
7+
strategy:
8+
matrix:
9+
os: [ubuntu-latest, macos-latest, windows-latest]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
# Checkout repo
13+
- name: Checkout repo
14+
uses: actions/checkout@v3
15+
# Install toolchain
16+
- name: Install toolchain
17+
uses: dtolnay/rust-toolchain@stable
18+
# build coverage
19+
- name: Run unit tests
20+
run: cargo test
21+
# Task coverage
22+
coverage:
23+
strategy:
24+
matrix:
25+
os: [ubuntu-latest]
26+
runs-on: ${{ matrix.os }}
27+
steps:
28+
# Checkout repo
29+
- name: Checkout repo
30+
uses: actions/checkout@v3
31+
# Install toolchain
32+
- name: Install toolchain
33+
uses: dtolnay/rust-toolchain@nightly
34+
# Install grcov
35+
- name: Install grcov
36+
run: curl -L https://github.com/mozilla/grcov/releases/download/v0.8.2/grcov-linux-x86_64.tar.bz2 | tar jxf -
37+
# Run coverage
38+
- name: Build coverage
39+
run: |
40+
export CARGO_INCREMENTAL=0
41+
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
42+
export RUSTDOCFLAGS="-Cpanic=abort"
43+
cargo build --features full --verbose $CARGO_OPTIONS
44+
cargo test --features full --verbose $CARGO_OPTIONS
45+
zip -0 ccov.zip `find . \( -name "htmlentity*.gc*" \) -print`;
46+
./grcov ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore "/*" -o lcov.info;
47+
bash <(curl -s https://codecov.io/bash) -f lcov.info;

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ Cargo.lock
1313
# Added by cargo
1414

1515
/target
16+
17+
# Others
18+
/pkg

.travis.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
The API has been redesigned with a focus on ease of use and performance since the version 1.3.0
4+
5+
## [1.3.0] - 2023-04-06
6+
7+
### Changed
8+
9+
- The API has been redesigned, the new way to use please see the document for more details.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
edition = "2018"
33
name = "htmlentity"
4-
version = "1.2.0"
4+
version = "1.3.0"
55
authors = ["ganmin <jxz_211@163.com>"]
66
keywords = ["entity", "html-entity", "html-escape", "html-encode", "html-decode"]
7-
categories = ["encoding", "parsing", "wasm"]
8-
description = "Encode a unicode character to html entity, decode html entity to a unicode character."
7+
categories = ["encoding", "parsing"]
8+
description = "A library for encoding and decoding HTML entities."
99
repository = "https://github.com/fefit/htmlentity"
1010
homepage = "https://github.com/fefit/htmlentity"
11-
exclude = ["node/**/*.*","pkg/**/*.*", "build.sh", "codecov.yml", ".travis.yml"]
11+
exclude = ["node/**/*.*","pkg/**/*.*", "build.sh", "codecov.yml"]
1212
license = "MIT"
1313

1414
[dependencies]
@@ -21,8 +21,8 @@ path = "src/lib.rs"
2121
crate-type = ["cdylib", "rlib"]
2222

2323
[dev-dependencies]
24-
criterion = "0.3"
25-
grcov = "0.6.1"
24+
criterion = "0.4.0"
25+
grcov = "0.8.16"
2626

2727
[[bench]]
2828
name = "benchmark"

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
# htmlentity
22

3-
html entity encode and decode.
3+
A library for encoding and decoding HTML entities.
44

5-
[![Docs](https://docs.rs/htmlentity/badge.svg)](https://docs.rs/htmlentity/badge.svg)
6-
[![Build Status](https://travis-ci.com/fefit/htmlentity.svg?branch=main)](https://travis-ci.com/github/fefit/htmlentity)
5+
[![Docs](https://docs.rs/htmlentity/badge.svg)](https://docs.rs/htmlentity)
6+
[![Build Status](https://github.com/fefit/htmlentity/actions/workflows/test.yml/badge.svg)](https://github.com/fefit/htmlentity/actions)
77
[![codecov](https://codecov.io/gh/fefit/htmlentity/branch/main/graph/badge.svg)](https://codecov.io/gh/fefit/htmlentity)
88

99
## How to use
1010

1111
```rust
12-
use htmlentity::entity::*;
13-
14-
let html = "<div class='header'></div>";
15-
let html_encoded: Vec<char> = encode(html, Entities::SpecialChars, EncodeType::Named);
16-
assert_eq!(html_encoded.iter().collect::<String>(), "&lt;div class=&apos;header&apos;&gt;&lt;/div&gt;");
17-
18-
let html_decoded: Vec<char> = decode_chars(&html_encoded);
19-
assert_eq!(html, html_decoded.iter().collect::<String>());
12+
use htmlentity::entity::{ encode, decode, EncodeType, CharacterSet, ICodedDataTrait };
13+
use htmlentity::types::{ AnyhowResult, Byte };
14+
fn main() -> AnyhowResult<()> {
15+
let html = "<div name='htmlentity'>Hello!世界!</div>";
16+
let html_after_encoded = "&lt;div name='htmlentity'&gt;Hello!&#x4e16;&#x754c;!&lt;/div&gt;";
17+
// encode
18+
let encoded_data = encode(html.as_bytes(), &EncodeType::NamedOrHex, &CharacterSet::HtmlAndNonASCII);
19+
assert_eq!(encoded_data.to_bytes(), html_after_encoded.as_bytes());
20+
assert_eq!(encoded_data.to_string()?, String::from(html_after_encoded));
21+
assert_eq!(encoded_data.to_chars()?, String::from(html_after_encoded).chars().collect::<Vec<char>>());
22+
// decode
23+
let bytes = encoded_data.into_iter().map(|(byte, _)| *byte).collect::<Vec<Byte>>();
24+
let decoded_data = decode(&bytes);
25+
assert_eq!(decoded_data.to_bytes(), html.as_bytes());
26+
assert_eq!(decoded_data.to_string()?, String::from(html));
27+
assert_eq!(decoded_data.to_chars()?, String::from(html).chars().collect::<Vec<char>>());
28+
Ok(())
29+
}
2030
```
2131

2232
For more details, please see the document in [Docs.rs](https://docs.rs/htmlentity)

benches/benchmark.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use criterion::{ criterion_group, criterion_main, Criterion};
1+
use criterion::{criterion_group, criterion_main, Criterion};
22
use htmlentity::entity::{decode, encode};
33
fn criterion_benchmark(c: &mut Criterion) {
44
c.bench_function("encode", |b| {
55
b.iter(|| {
66
encode(
7-
r##"
7+
r##"
88
<div class="s-rank-title">
99
<a href="http://top.baidu.com/?fr=mhd_card" target="_blank">
1010
<div class="title-text c-font-medium c-color-t">
@@ -15,17 +15,18 @@ fn criterion_benchmark(c: &mut Criterion) {
1515
<i class="c-icon">&#xe619;</i><span class="hot-refresh-text">换一换</span>
1616
</a>
1717
</div>
18-
"##,
19-
Default::default(),
20-
Default::default()
18+
"##
19+
.as_bytes(),
20+
&Default::default(),
21+
&Default::default(),
2122
);
2223
})
2324
});
2425
c.bench_function("decode", |b| {
2526
b.iter(|| {
2627
decode(r##"
2728
&lt;&#x64;&#x69;&#x76;&#x20;&#x63;&#x6C;&#x61;&#x73;&#x73;&equals;&quot;&#x73;&#x2D;&#x72;&#x61;&#x6E;&#x6B;&#x2D;&#x74;&#x69;&#x74;&#x6C;&#x65;&quot;&gt;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;&#x61;&#x20;&#x68;&#x72;&#x65;&#x66;&equals;&quot;&#x68;&#x74;&#x74;&#x70;&colon;&sol;&sol;&#x77;&#x77;&#x77;&period;&#x61;&#x62;&#x63;&period;&#x63;&#x6F;&#x6D;&sol;&quest;&#x66;&#x72;&equals;&#x6D;&#x68;&#x64;&lowbar;&#x63;&#x61;&#x72;&#x64;&quot;&#x20;&#x74;&#x61;&#x72;&#x67;&#x65;&#x74;&equals;&quot;&lowbar;&#x62;&#x6C;&#x61;&#x6E;&#x6B;&quot;&gt;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;&#x64;&#x69;&#x76;&#x20;&#x63;&#x6C;&#x61;&#x73;&#x73;&equals;&quot;&#x74;&#x69;&#x74;&#x6C;&#x65;&#x2D;&#x74;&#x65;&#x78;&#x74;&#x20;&#x63;&#x2D;&#x66;&#x6F;&#x6E;&#x74;&#x2D;&#x6D;&#x65;&#x64;&#x69;&#x75;&#x6D;&#x20;&#x63;&#x2D;&#x63;&#x6F;&#x6C;&#x6F;&#x72;&#x2D;&#x74;&quot;&gt;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x70ED;&#x699C;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;&sol;&#x64;&#x69;&#x76;&gt;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;&sol;&#x61;&gt;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;&#x61;&#x20;&#x63;&#x6C;&#x61;&#x73;&#x73;&equals;&quot;&#x68;&#x6F;&#x74;&#x2D;&#x72;&#x65;&#x66;&#x72;&#x65;&#x73;&#x68;&#x20;&#x63;&#x2D;&#x66;&#x6F;&#x6E;&#x74;&#x2D;&#x6E;&#x6F;&#x72;&#x6D;&#x61;&#x6C;&#x20;&#x63;&#x2D;&#x63;&#x6F;&#x6C;&#x6F;&#x72;&#x2D;&#x67;&#x72;&#x61;&#x79;&#x32;&quot;&gt;&#x20;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;&#x69;&#x20;&#x63;&#x6C;&#x61;&#x73;&#x73;&equals;&quot;&#x63;&#x2D;&#x69;&#x63;&#x6F;&#x6E;&quot;&gt;&amp;&num;&#x78;&#x65;&#x36;&#x31;&#x39;&semi;&lt;&sol;&#x69;&gt;&lt;&#x73;&#x70;&#x61;&#x6E;&#x20;&#x63;&#x6C;&#x61;&#x73;&#x73;&equals;&quot;&#x68;&#x6F;&#x74;&#x2D;&#x72;&#x65;&#x66;&#x72;&#x65;&#x73;&#x68;&#x2D;&#x74;&#x65;&#x78;&#x74;&quot;&gt;&#x6362;&#x4E00;&#x6362;&lt;&sol;&#x73;&#x70;&#x61;&#x6E;&gt;&NewLine;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;&sol;&#x61;&gt;&NewLine;&#x20;&#x20;&#x20;&#x20;&lt;&sol;&#x64;&#x69;&#x76;&gt;
28-
"##);
29+
"##.as_bytes());
2930
})
3031
});
3132
}

0 commit comments

Comments
 (0)