Skip to content

Commit 57b4a90

Browse files
committed
Version 1.0.0
1 parent 3abdf58 commit 57b4a90

3 files changed

Lines changed: 49 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,80 @@
1-
0.11.0
2-
------
1+
## 1.0.0
2+
3+
- `Format`, `FormatHTML`, `Unformat`, `UnformatHTML` support custom option for addition processes.
4+
5+
Example:
6+
7+
```go
8+
type myFormatter struct {}
9+
func (my myFormatter) Format(text string) string {
10+
return strings.ReplaceAll(text, "ios", "iOS")
11+
}
12+
13+
autocorrect.Format("新版本ios即将发布", myFormatter{})
14+
// "新版本 iOS 即将发布"
15+
```
16+
17+
## 0.11.0
318

419
- Fix fullwidth to remove `;` for fix invalid convert with HTML Entity case.
520

6-
0.10.0
7-
--------
21+
## 0.10.0
822

923
- Auto correct punctuation into fullwidth.
1024

11-
0.9.0
12-
--------
25+
## 0.9.0
1326

1427
- Change rule for ignore spacing between `#`, `$` chars.
1528

16-
0.8.2
17-
--------
29+
## 0.8.2
1830

1931
- Fix some break line miss bug.
2032

21-
0.8.0
22-
--------
33+
## 0.8.0
2334

2435
- Add `Unformat` / `UnformatHTML` method for remove spacings.
2536

26-
0.7.0
27-
--------
37+
## 0.7.0
2838

2939
- Use new HTML parser to format HTML for performance up.
3040
- Avoid format text with script/style/textarea/pre tags.
3141

32-
0.6.1
33-
--------
42+
## 0.6.1
3443

3544
- Fix halfwidth to correct fullwidth spaces.
3645

37-
0.6.0
38-
--------
46+
## 0.6.0
3947

4048
- Auto correct FullWidth -> halfwidth for Letters, Numbers, and Colon in time.
4149

42-
0.4.1
43-
--------
50+
## 0.4.1
4451

4552
- Avoid create regex on format method call for performance up (~40%).
4653

47-
0.4.0
48-
--------
54+
## 0.4.0
4955

5056
- Add Full CJK (Chinese, Japanese, Korean) support.
5157

52-
0.3.3
53-
--------
58+
## 0.3.3
5459

5560
- Fix space around `-`;
5661

57-
0.3.2
58-
--------
62+
## 0.3.2
5963

6064
- Fix add space round `*`;
6165

62-
0.3.1
63-
--------
66+
## 0.3.1
6467

6568
- Fix HTML replace when content has escapeable `&`, ` ` chars.
6669

67-
0.3.0
68-
--------
70+
## 0.3.0
6971

7072
- Rename package from `autospace` to `autocorrect`.
7173

72-
0.2.0
73-
--------
74+
## 0.2.0
7475

7576
- Add `FormatHTML` method for process HTML contents.
7677

77-
0.1.0
78-
--------
78+
## 0.1.0
7979

8080
- First release.
81-

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-wi
1717
- Fullwidth -> halfwidth (only for [a-zA-Z0-9], and `` in time).
1818
- Correct punctuations into Fullwidth near the CJK.
1919
- Cleanup spacings.
20+
- Support options for custom format, unformat.
2021

2122
## Usage
2223

@@ -60,6 +61,20 @@ func main() {
6061
}
6162
```
6263

64+
With custom formatter:
65+
66+
```go
67+
type myFormatter struct {}
68+
func (my myFormatter) Format(text string) string {
69+
return strings.ReplaceAll(text, "ios", "iOS")
70+
}
71+
72+
autocorrect.Format("新版本ios即将发布", myFormatter{})
73+
// "新版本 iOS 即将发布"
74+
autocorrect.FormatHTML("<p>新版本ios即将发布</p>", myFormatter{})
75+
// "<p>新版本 iOS 即将发布</p>"
76+
```
77+
6378
Use `autocorrect.Unformat` to cleanup spacings in plain text.
6479

6580
```go

halfwidth_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ func Test_halfwidth(t *testing.T) {
1212
assertEqual(t, "他说:我们将在16:32分出发去CBD中心。", halfwidth("他说:我们将在16:32分出发去CBD中心。"))
1313
// Fullwidth space
1414
assert.Equal(t, "ジョイフル-後場売り気配 200 店舗を閉鎖へ 7 月以降、不採算店中心に", halfwidth("ジョイフル-後場売り気配 200 店舗を閉鎖へ 7 月以降、不採算店中心に"))
15+
// Fullwidth Numbers
16+
assert.Equal(t, "0 1 2 3 4 5 6 7 8 9", halfwidth("0 1 2 3 4 5 6 7 8 9"))
1517
}
1618

1719
func Benchmark_halfwidth(b *testing.B) {

0 commit comments

Comments
 (0)