-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3deeb66
Showing
481 changed files
with
121,715 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.23' | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
# Optional: allow read access to pull request. Use with `only-new-issues` option. | ||
# pull-requests: read | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.23 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Wlynxg | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
<div align=center> | ||
|
||
## chardet: Go character encoding detector | ||
[![Go Reference](https://pkg.go.dev/badge/github.com/wlynxg/chardet.svg)](https://pkg.go.dev/github.com/wlynxg/chardet) | ||
[![License](https://img.shields.io/github/license/wlynxg/chardet.svg?style=flat)](https://github.com/wlynxg/chardet) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/wlynxg/chardet)](https://goreportcard.com/report/github.com/wlynxg/chardet) | ||
|
||
</div> | ||
|
||
# Introduction | ||
|
||
This is a Go port of the python's [chardet](https://github.com/chardet/chardet) library. Much respect and appreciation to the original authors for their excellent work. | ||
|
||
chardet is a character encoding detector library written in Go. It helps you automatically detect the character encoding of text content. | ||
|
||
# Installation | ||
|
||
To install chardet, use `go get`: | ||
|
||
```bash | ||
go get github.com/wlynxg/chardet | ||
``` | ||
|
||
## Supported Encodings & Languages | ||
|
||
**Support Encodings**: | ||
|
||
<details> | ||
<summary>Expand the list of supported encodings</summary> | ||
|
||
- **Ascii** | ||
- **UTF-8** | ||
- **UTF-8-SIG** | ||
- **UTF-16** | ||
- **UTF-16LE** | ||
- **UTF-16BE** | ||
- **UTF-32** | ||
- **UTF-32BE** | ||
- **UTF-32LE** | ||
- **GB2312** | ||
- **HZ-GB-2312** | ||
- **SHIFT_JIS** | ||
- **Big5** | ||
- **Johab** | ||
- **KOI8-R** | ||
- **TIS-620** | ||
- **MacCyrillic** | ||
- **MacRoman** | ||
- **EUC-TW** | ||
- **EUC-KR** | ||
- **EUC-JP** | ||
- **CP932** | ||
- **CP949** | ||
- **Windows-1250** | ||
- **Windows-1251** | ||
- **Windows-1252** | ||
- **Windows-1253** | ||
- **Windows-1254** | ||
- **Windows-1255** | ||
- **Windows-1256** | ||
- **Windows-1257** | ||
- **ISO-8859-1** | ||
- **ISO-8859-2** | ||
- **ISO-8859-5** | ||
- **ISO-8859-6** | ||
- **ISO-8859-7** | ||
- **ISO-8859-8** | ||
- **ISO-8859-9** | ||
- **ISO-8859-13** | ||
- **ISO-2022-CN** | ||
- **ISO-2022-JP** | ||
- **ISO-2022-KR** | ||
- **X-ISO-10646-UCS-4-3412** | ||
- **X-ISO-10646-UCS-4-2143** | ||
- **IBM855** | ||
- **IBM866** | ||
|
||
</details> | ||
|
||
**Support Languages**: | ||
<details> | ||
<summary>Expand the list of supported languages</summary> | ||
- Chinese | ||
- Japanese | ||
- Korean | ||
- Hebrew | ||
- Russian | ||
- Greek | ||
- Bulgarian | ||
- Thai | ||
- Turkish | ||
|
||
</details> | ||
|
||
# Usage | ||
|
||
## Basic Usage | ||
|
||
The simplest way to use chardet is with the `Detect` function: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/wlynxg/chardet" | ||
) | ||
|
||
func main() { | ||
data := []byte("Your text data here...") | ||
result := chardet.Detect(data) | ||
fmt.Printf("Detected result: %+v\n", result) | ||
//Output: Detected result: {Encoding:Ascii Confidence:1 Language:} | ||
} | ||
``` | ||
|
||
## Advanced Usage | ||
|
||
For handling large amounts of text, you can use the detector incrementally. This allows the detector to stop as soon as it reaches sufficient confidence in its result. | ||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/wlynxg/chardet" | ||
) | ||
|
||
func main() { | ||
// Create a detector instance | ||
detector := chardet.NewUniversalDetector(0) | ||
// Process text in chunks | ||
chunk1 := []byte("First chunk of text...") | ||
chunk2 := []byte("Second chunk of text...") | ||
detector.Feed(chunk1) | ||
detector.Feed(chunk2) | ||
// Get the result | ||
result := detector.GetResult() | ||
fmt.Printf("Detected result: %+v\n", result) | ||
// Output: Detected result: {Encoding:Ascii Confidence:1 Language:} | ||
} | ||
``` | ||
|
||
## Processing Multiple Files | ||
|
||
You can reuse the same detector instance for multiple files by using the `Reset()` method: | ||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"github.com/wlynxg/chardet" | ||
) | ||
|
||
func main() { | ||
detector := chardet.NewUniversalDetector(0) | ||
files := []string{"file1.txt", "file2.txt"} | ||
for _, file := range files { | ||
detector.Reset() | ||
data, err := os.ReadFile(file) | ||
if err != nil { | ||
continue | ||
} | ||
detector.Feed(data) | ||
result := detector.GetResult() | ||
fmt.Printf("File %s encoding: %+v\n", file, result) | ||
} | ||
} | ||
``` | ||
|
||
# License | ||
|
||
`chardet` is licensed under the [MIT License](LICENSE), 100% free and open-source, forever. |
Oops, something went wrong.