Makes the sanitazition test pass
This commit is contained in:
32
bd.go
32
bd.go
@@ -1,6 +1,13 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/transform"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
// An AlbumState describe the state of an Album
|
||||
type AlbumState int
|
||||
@@ -35,8 +42,27 @@ type Album struct {
|
||||
PrintDate time.Time
|
||||
}
|
||||
|
||||
func sanitizeTitleString(title string) string {
|
||||
return ""
|
||||
var endDelim = regexp.MustCompile(` \(.*\)\z`)
|
||||
var wordBoundaries = regexp.MustCompile(`[^[:alnum:]]+`)
|
||||
var punctuation = regexp.MustCompile(`[!?\.:;,]`)
|
||||
|
||||
func sanitizeTitleString(title string, removeEndParent bool) string {
|
||||
// first sanitize accuented characters.
|
||||
isOk := func(r rune) bool {
|
||||
return r < 32 || r >= 127
|
||||
}
|
||||
// The isOk filter is such that there is no need to chain to norm.NFC
|
||||
t := transform.Chain(norm.NFKD, transform.RemoveFunc(isOk))
|
||||
// This Transformer could also trivially be applied as an io.Reader
|
||||
// or io.Writer filter to automatically do such filtering when reading
|
||||
// or writing data anywhere.
|
||||
title, _, _ = transform.String(t, title)
|
||||
//Now we remove all punctuation
|
||||
if removeEndParent == true {
|
||||
title = endDelim.ReplaceAllString(title, "")
|
||||
}
|
||||
|
||||
return strings.Trim(wordBoundaries.ReplaceAllString(punctuation.ReplaceAllString(title, ""), "-"), "-")
|
||||
}
|
||||
|
||||
func (*Album) GetBedethequeComURI() string {
|
||||
|
||||
Reference in New Issue
Block a user