本文整理汇总了Golang中strings.Reader.Size方法的典型用法代码示例。如果您正苦于以下问题:Golang Reader.Size方法的具体用法?Golang Reader.Size怎么用?Golang Reader.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strings.Reader
的用法示例。
在下文中一共展示了Reader.Size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initw
// initw read a file .LIF and configure the world with it
func initw(f *os.File) bool {
var r *strings.Reader
var b byte
var x, y, oldy int
input := bufio.NewScanner(f)
input.Scan()
if input.Text() != "#Life 1.05" {
fmt.Fprintf(os.Stderr, "ERROR: The file for initialization the world is not a valid .LIF format\n")
return false
}
header:
// Read header of .LIF
for input.Scan() {
r = strings.NewReader(input.Text())
b, _ = r.ReadByte()
if b != '#' {
fmt.Println(input.Text())
} else {
b, _ = r.ReadByte()
switch b {
case 'D':
{
fmt.Println("Description")
}
case 'N':
{
fmt.Println("Rules Conway R 23/3")
}
case 'R':
{
fmt.Fprintf(os.Stderr, "ERROR: 'R' option not implemented\n")
return false
}
case 'P':
{
s := strings.Split(input.Text(), " ")
x, _ = strconv.Atoi(s[1])
y, _ = strconv.Atoi(s[2])
x += (M / 2)
y += (N / 2)
oldy = y
break header // Exit loop, now only blocks of position and cells
}
default:
{
fmt.Fprintf(os.Stderr, "ERROR: Option in header not implemented\n")
return false
}
}
}
}
var p Point
m := map[Point]int{}
// Read patterns and positions
for input.Scan() {
r = strings.NewReader(input.Text())
b, _ = r.ReadByte()
if b == '#' {
b, _ = r.ReadByte()
if b == 'P' {
s := strings.Split(input.Text(), " ")
x, _ = strconv.Atoi(s[1])
y, _ = strconv.Atoi(s[2])
x += (M / 2)
y += (N / 2)
oldy = y
} else {
fmt.Fprintf(os.Stderr, "ERROR: Expected Position or blocks not config parameters\n")
return false
}
} else {
p.x = x
for cells := int(r.Size()); cells > 0; cells-- {
p.y = y
switch b {
case '.':
{
//m[p] = 0
}
case '*':
{
m[p] = 1
}
default:
{
fmt.Fprintf(os.Stderr, "ERROR: Character not valid, only '.' or '*'\n")
return false
}
}
b, _ = r.ReadByte()
y++
}
}
x++
y = oldy
}
w.Matrix[0] = m
return true
//.........这里部分代码省略.........