Skip to content

Commit 2edc636

Browse files
committed
Parse @
1 parent 7b8349a commit 2edc636

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module "gopkg.in/yaml.v2"
1+
module "github.com/cortexlabs/yaml"
22

33
require (
44
"gopkg.in/check.v1" v0.0.0-20161208181325-20d25e280405

scannerc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,16 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool {
794794
return yaml_parser_fetch_flow_scalar(parser, false)
795795
}
796796

797+
// Is it an @?
798+
if parser.buffer[parser.buffer_pos] == '@' {
799+
newBuf := make([]byte, len(parser.buffer)+len(atSymbolEscapeSeqBytes)-1, cap(parser.buffer)+len(atSymbolEscapeSeqBytes)-1)
800+
copy(newBuf, parser.buffer[:parser.buffer_pos])
801+
copy(newBuf[parser.buffer_pos:], atSymbolEscapeSeqBytes)
802+
copy(newBuf[parser.buffer_pos+len(atSymbolEscapeSeqBytes):], parser.buffer[parser.buffer_pos+1:])
803+
parser.buffer = newBuf
804+
return yaml_parser_fetch_plain_scalar(parser)
805+
}
806+
797807
// Is it a plain scalar?
798808
//
799809
// A plain scalar may start with any non-blank characters except

yaml.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,30 @@ func isZero(v reflect.Value) bool {
464464
}
465465
return false
466466
}
467+
468+
const atSymbolEscapeSeq = "🌝🌝🌝🌝🌝"
469+
470+
var atSymbolEscapeSeqBytes = []byte(atSymbolEscapeSeq)
471+
472+
func ExtractAtSymbolText(input interface{}) (string, bool) {
473+
if str, ok := input.(string); ok {
474+
if strings.HasPrefix(str, atSymbolEscapeSeq) {
475+
return str[len(atSymbolEscapeSeq):], true
476+
}
477+
}
478+
return "", false
479+
}
480+
481+
func EscapeAtSymbol(str string) (string, bool) {
482+
if strings.HasPrefix(str, "@") {
483+
return atSymbolEscapeSeq + str[1:], true
484+
}
485+
return str, false
486+
}
487+
488+
func UnescapeAtSymbol(str string) (string, bool) {
489+
if strings.HasPrefix(str, atSymbolEscapeSeq) {
490+
return "@" + str[len(atSymbolEscapeSeq):], true
491+
}
492+
return str, false
493+
}

0 commit comments

Comments
 (0)