https://github.com/rvflash/charset
Golang package to limit the number of bytes per character in a string
https://github.com/rvflash/charset
golang mysql utf8 utf8mb4
Last synced: 2 months ago
JSON representation
Golang package to limit the number of bytes per character in a string
- Host: GitHub
- URL: https://github.com/rvflash/charset
- Owner: rvflash
- License: mit
- Created: 2018-01-18T09:25:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-18T14:01:08.000Z (over 7 years ago)
- Last Synced: 2025-01-28T16:16:29.542Z (4 months ago)
- Topics: golang, mysql, utf8, utf8mb4
- Language: Go
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Charset
[](https://godoc.org/github.com/rvflash/charset)
[](https://travis-ci.org/rvflash/charset)
[](http://codecov.io/github/rvflash/charset?branch=master)
[](https://goreportcard.com/report/github.com/rvflash/charset)Golang package to limit the number of bytes per character in a string.
### Why?
Because MySQL has multiple unicode support and behind the utf8 character set, it uses a maximum of three bytes per character.
This charset contains only BMP characters.
An other, named utf8mb4 uses a maximum of four bytes per character and supports supplementary characters.
This package provides method to limit the number of bytes per character in a utf8 string.> https://dev.mysql.com/doc/refman/5.7/en/charset-unicode-utf8mb4.html
### Installation
```bash
$ go get -u github.com/rvflash/charset
```### Usage
```go
import "github.com/rvflash/charset"
// ...
s := charset.FormatUtf8("Warning: ⚠ 1 minute left ⌚ before boom 💥 ➡ click on the button !")
fmt.Println(s)
// Output: Warning: ⚠ 1 minute left ⌚ before boom ➡ click on the button !
```