Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package string2sql
- import (
- "regexp"
- "strings"
- )
- //______________________________________________________________________________
- type Str2Sql struct {
- text string
- }
- //______________________________________________________________________________
- func NewString2Sql(text string) *Str2Sql {
- p := new(Str2Sql)
- p.text = text
- return p
- }
- //______________________________________________________________________________
- func (p *Str2Sql) ZapBlanks() *Str2Sql {
- borders := regexp.MustCompile(`^[\s\p{Zs}]+|[\s\p{Zs}]+$`)
- inner := regexp.MustCompile(`[\s\p{Zs}]{2,}`)
- f := borders.ReplaceAllString(p.text, "")
- f = inner.ReplaceAllString(f, " ")
- p.text = f
- return p
- }
- //______________________________________________________________________________
- func (p *Str2Sql) NormalizeApostrophesAndQuotes() *Str2Sql {
- s := p.text
- s = strings.ReplaceAll(s, "\"", "''")
- s = strings.ReplaceAll(s, "'", "''")
- p.text = s
- return p
- }
- //______________________________________________________________________________
- func (p *Str2Sql) NormalizeAccents() *Str2Sql {
- s := p.text
- s = strings.ReplaceAll(s, "A'", "À")
- s = strings.ReplaceAll(s, "E'", "È")
- s = strings.ReplaceAll(s, "I'", "Ì")
- s = strings.ReplaceAll(s, "O'", "Ò")
- s = strings.ReplaceAll(s, "U'", "Ù")
- s = strings.ReplaceAll(s, "a'", "à")
- s = strings.ReplaceAll(s, "e'", "è")
- s = strings.ReplaceAll(s, "i'", "ì")
- s = strings.ReplaceAll(s, "o'", "ò")
- s = strings.ReplaceAll(s, "u'", "ù")
- p.text = s
- return p
- }
- //______________________________________________________________________________
- func (p *Str2Sql) RemoveAll(str string) *Str2Sql {
- s := p.text
- s = strings.ReplaceAll(s, str, "")
- p.text = s
- return p
- }
- //______________________________________________________________________________
- func (p *Str2Sql) Text() string {
- return p.text
- }
- // IN MAIN:
- // func str2sql(str string) string {
- // s := s2s.NewString2Sql(str)
- // s.ZapBlanks().NormalizeAccents().NormalizeApostrophesAndQuotes().RemoveAll("NULL")
- // return s.Text()
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement