Skip to content

Commit

Permalink
Add helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
deliahu committed Jun 26, 2019
1 parent 7f31702 commit 202ab3a
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,22 +469,59 @@ const atSymbolEscapeSeq = "🌝🌝🌝🌝🌝"

var atSymbolEscapeSeqBytes = []byte(atSymbolEscapeSeq)

func ExtractAtSymbolText(input interface{}) (string, bool) {
func StartsWithEscapedAtSymbol(str string) bool {
return strings.HasPrefix(str, atSymbolEscapeSeq)
}

func HasEscapedAtSymbol(str string) bool {
return strings.Contains(str, atSymbolEscapeSeq)
}

func ExtractAtSymbolText(str string) (string, bool) {
if strings.HasPrefix(str, atSymbolEscapeSeq) {
return str[len(atSymbolEscapeSeq):], true
}
return "", false
}

func ExtractAtSymbolTextInter(input interface{}) (string, bool) {
if str, ok := input.(string); ok {
if strings.HasPrefix(str, atSymbolEscapeSeq) {
return str[len(atSymbolEscapeSeq):], true
}
return ExtractAtSymbolText(str)
}
if strPtr, ok := input.(*string); ok {
return ExtractAtSymbolText(*strPtr)
}
return "", false
}

func EscapeAtSymbol(str string) (string, bool) {
func EscapeAtSymbol(str string) string {
if strings.HasPrefix(str, "@") {
return atSymbolEscapeSeq + str[1:]
}
return str
}

func EscapeAtSymbolOk(str string) (string, bool) {
if strings.HasPrefix(str, "@") {
return atSymbolEscapeSeq + str[1:], true
}
return str, false
}

func EscapeAllAtSymbols(str string) string {
if strings.Contains(str, "@") {
return strings.ReplaceAll(str, "@", atSymbolEscapeSeq)
}
return str
}

func EscapeAllAtSymbolsOk(str string) (string, bool) {
if strings.Contains(str, "@") {
return strings.ReplaceAll(str, "@", atSymbolEscapeSeq), true
}
return str, false
}

func UnescapeAtSymbol(str string) string {
if strings.HasPrefix(str, atSymbolEscapeSeq) {
return "@" + str[len(atSymbolEscapeSeq):]
Expand Down

0 comments on commit 202ab3a

Please sign in to comment.