项目作者: trubitsyn

项目描述 :
Zero-width character detection and removal for Go
高级语言: Go
项目地址: git://github.com/trubitsyn/go-zero-width.git
创建时间: 2018-06-18T13:55:09Z
项目社区:https://github.com/trubitsyn/go-zero-width

开源协议:Apache License 2.0

下载


go-zero-width Mentioned in Awesome Go Golang Weekly #241 Golang Weekly #241 Build Status GoDoc Go Report Card

Zero-width character detection and removal for Go. Inspired by @umpox/be-careful-what-you-copy-invisibly-inserting-usernames-into-text-with-zero-width-characters-18b4e6f17b66">this Medium article.

Installation

go get github.com/trubitsyn/go-zero-width

Usage

  1. package main
  2.  
  3. import (
  4. "github.com/trubitsyn/go-zero-width"
  5. "fmt"
  6. )
  7.  
  8. func main() {
  9. login := "abc​def" // zero-width space between "c" and "d"
  10. clean := zerowidth.RemoveZeroWidthCharacters(login) // a b c d e f
  11. fmt.Printf("% x\n", login) // 61 62 63 e2 80 8b 64 65 66
  12. fmt.Printf("% x\n", clean) // 61 62 63 64 65 66
  13. }

Supported characters

  • Zero-width space (U+200B)
  • Zero-width no-break space (U+FEFF)
  • Zero-width joiner (U+200D)
  • Zero-width non-joiner (U+200C)

Testing

  1. go get -t github.com/trubitsyn/go-zero-width
  2. go test github.com/trubitsyn/go-zero-width

LICENSE

  1. Copyright 2018 Nikola Trubitsyn
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.