File: str.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,080 kB
  • sloc: ansic: 127; makefile: 76
file content (49 lines) | stat: -rw-r--r-- 1,185 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sexp

import "bufio"

// Sstring represents an S-Expression symbol.
type Sstring string

// First will fail if called on an Sstring
func (s Sstring) First() Value {
	panic("not valid to call First on an SString")
}

// Second will fail if called on an Sstring
func (s Sstring) Second() Value {
	panic("not valid to call Second on an SString")
}

// String returns the string quoted as a string in an S-Expression
func (s Sstring) String() string {
	return "\"" + string(s) + "\""
}

// Value returns the string as a string
func (s Sstring) Value() interface{} {
	return string(s)
}

// ReadStringStart will read the string start character and return false if it is not encountered
func ReadStringStart(r *bufio.Reader) bool {
	return expect(r, '"')
}

// ReadStringEnd will read the string end character and return false if it is not encountered
func ReadStringEnd(r *bufio.Reader) bool {
	return expect(r, '"')
}

// ReadString will read a string from the reader
func ReadString(r *bufio.Reader) Value {
	ReadWhitespace(r)
	if !ReadStringStart(r) {
		return nil
	}
	result := ReadDataUntil(r, untilFixed('"'))
	if !ReadStringEnd(r) {
		return nil
	}
	return Sstring(result)
}