zerowidth

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2020 License: Apache-2.0 Imports: 1 Imported by: 6

README

go-zero-width Mentioned in Awesome Go Build Status GoDoc Go Report Card

Zero-width character detection and removal for Go. Inspired by this Medium article.

Installation

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

Usage

package main

import (
	"github.com/trubitsyn/go-zero-width"
	"fmt"
)

func main() {
	login := "abc​def"					// zero-width space between "c" and "d"
	clean := zerowidth.RemoveZeroWidthCharacters(login)	// a  b  c           d  e  f
	fmt.Printf("% x\n", login)				// 61 62 63 e2 80 8b 64 65 66
	fmt.Printf("% x\n", clean)				// 61 62 63          64 65 66
}

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

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

LICENSE

Copyright 2018 Nikola Trubitsyn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package zerowidth implements functions to remove zero-width characters from strings.

Index

Constants

View Source
const (
	// ZWSP represents zero-width space.
	ZWSP = '\u200B'

	// ZWNBSP represents zero-width no-break space.
	ZWNBSP = '\uFEFF'

	// ZWJ represents zero-width joiner.
	ZWJ = '\u200D'

	// ZWNJ represents zero-width non-joiner.
	ZWNJ = '\u200C'
)

Variables

This section is empty.

Functions

func HasZeroWidthCharacters

func HasZeroWidthCharacters(s string) bool

HasZeroWidthCharacters reports whether string s contains zero-width characters.

func RemoveZeroWidthCharacters

func RemoveZeroWidthCharacters(s string) string

RemoveZeroWidthCharacters removes all zero-width characters from string s.

func RemoveZeroWidthJoiner

func RemoveZeroWidthJoiner(s string) string

RemoveZeroWidthJoiner removes zero-width joiner characters from string s.

func RemoveZeroWidthNoBreakSpace

func RemoveZeroWidthNoBreakSpace(s string) string

RemoveZeroWidthNoBreakSpace removes zero-width no-break space characters from string s.

func RemoveZeroWidthNonJoiner

func RemoveZeroWidthNonJoiner(s string) string

RemoveZeroWidthNonJoiner removes zero-width non-joiner characters from string s.

func RemoveZeroWidthSpace

func RemoveZeroWidthSpace(s string) string

RemoveZeroWidthSpace removes zero-width space characters from string s.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL