当前位置: 首页>>代码示例>>Golang>>正文


Golang Scanner.Err方法代码示例

本文整理汇总了Golang中bufio.Scanner.Err方法的典型用法代码示例。如果您正苦于以下问题:Golang Scanner.Err方法的具体用法?Golang Scanner.Err怎么用?Golang Scanner.Err使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bufio.Scanner的用法示例。


在下文中一共展示了Scanner.Err方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: toString

func toString(scanner *bufio.Scanner) (string, error) {
	output := ""
	for scanner.Scan() {
		output += scanner.Text() + "\n"
	}
	return output, scanner.Err()
}
开发者ID:jeidsath,项目名称:marginalia,代码行数:7,代码来源:main.go

示例2: readFrontMatter

func readFrontMatter(s *bufio.Scanner) (map[string]string, error) {
	m := make(map[string]string)
	flag := false
	for s.Scan() {
		line := strings.Trim(s.Text(), " ") //Trim space
		if line == "---" {
			if flag {
				return m, nil
			} else {
				flag = true
			}
		} else if flag {
			matter := strings.SplitN(line, ":", 2)
			if len(matter) != 2 {
				//Invalid front matter line
				return nil, ErrInvalidFrontMatter
			}
			m[strings.ToLower(matter[0])] = strings.Trim(matter[1], " ") //Trim space
		} else if line != "" {
			//Empty front matter
			return nil, ErrMissingFrontMatter
		}
	}

	if err := s.Err(); err != nil {
		return nil, err
	}

	return nil, ErrEmptyPost
}
开发者ID:RobinMao,项目名称:agaue,代码行数:30,代码来源:post.go

示例3: fillArr

func fillArr(s *bufio.Scanner) (l []loc) {
	var err error
	for s.Scan() {
		if bytes.Count(s.Bytes(), []byte{','}) != 1 {
			if len(l) == 0 {
				ln, err := strconv.ParseInt(string(bytes.TrimSpace(s.Bytes())), 10, 0)
				check(err)
				l = make([]loc, 0, ln+10)
			}
			continue
		}

		t1 := make([]byte, len(s.Bytes()))
		copy(t1, s.Bytes())
		tmploc := loc{t1, 0, 0}
		tmp := bytes.SplitN(bytes.Trim(tmploc.pts, "() "), []byte{','}, 3)
		tmploc.x, err = strconv.ParseFloat(string(bytes.TrimSpace(tmp[0])), 64)
		check(err)
		tmploc.y, err = strconv.ParseFloat(string(bytes.TrimSpace(tmp[1])), 64)
		check(err)
		l = append(l, tmploc)
	}
	if s.Err() != nil {
		log.Fatal(s.Err())
	}
	sort.Sort(locA(l))
	return
}
开发者ID:Kunde21,项目名称:DailyProgrammer,代码行数:28,代码来源:c232I.go

示例4: bootstrap

// bootstrap sets DatabaseSource and ServerKey from stdin
func (c *Config) bootstrap() {

	var scanner *bufio.Scanner

	tfile, err := os.Open("/tmp/session_test.config.bootstrap.input")
	if err == nil {
		defer tfile.Close()
		scanner = bufio.NewScanner(tfile)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}

	// DatabaseSource
	fmt.Print("Enter the PostgreSQL source string: ")
	scanner.Scan()
	c.DatabaseSource = scanner.Text()
	fmt.Println()

	// ServerKey
	fmt.Print("Enter the secret server key: ")
	scanner.Scan()
	sk := scanner.Text()
	fmt.Println()

	if err = scanner.Err(); err != nil {
		panic(fmt.Sprintf("Error reading input: %s", err))
	}

	c.ServerKey, err = hex.DecodeString(sk)
	if err != nil {
		panic(fmt.Sprintf("Failed to convert SERVERKEY [%s] to bytes: %s", sk, err))
	}

}
开发者ID:Grant-Murray,项目名称:session,代码行数:35,代码来源:config.go

示例5: readHushFile

// read the hushfile line by line
func readHushFile(scanner *bufio.Scanner) map[string]string {
	properties := make(map[string]string)
	lineno := 1

	// read the file and process the lines, splitting them by ':'
	for scanner.Scan() {
		pair := processLine(scanner.Text())
		if len(pair) != 2 {
			log.Fatalf("Hushfile line %d was formatted improperly", lineno)
			panic("Hushfile Error!")
		}

		// add the hushfile properties and their values to the properties map
		properties[pair[0]] = pair[1]
		lineno++
	}

	err := scanner.Err()
	if err != nil {
		log.Fatal(err)
		panic(err)
	}

	return properties
}
开发者ID:caneroj1,项目名称:hush,代码行数:26,代码来源:hush.go

示例6: scanOSGT

func scanOSGT(some *bufio.Scanner) (*OSGT, error) {

	out := NewOSGT()
	for some.Scan() {
		a_line := some.Text()

		if err := some.Err(); err != nil {
			return nil, err // Return whatever we have
		}
		a_line = strings.Trim(a_line, " \n\t")
		if strings.Contains(a_line, "}") {
			return out, nil
		}
		var depth *OSGT = nil
		if strings.Contains(a_line, "{") {
			a_line = strings.Replace(a_line, "{", "", 1)
			a_line = strings.Trim(a_line, " \n\t") // Getting rid of extra space
			inside, err := scanOSGT(some)
			if err != nil {
				return nil, err
			}
			depth = inside
		}
		out.List = append(out.List, OSGTEntry{a_line, depth})
	}
	return out, nil
}
开发者ID:korantu,项目名称:sheercloud,代码行数:27,代码来源:convert.go

示例7: main

func main() {
	var ifile *bufio.Scanner
	if len(os.Args) == 2 {
		ifile = rx.MkScanner("-")
	} else if len(os.Args) == 3 {
		ifile = rx.MkScanner(os.Args[2])
	} else {
		log.Fatal("usage: rxq \"rexpr\" [file]")
	}
	spec := os.Args[1]
	fmt.Printf("regexp: %s\n", spec)
	dfa, err := rx.Compile(spec)
	if err != nil {
		log.Fatal(err)
	}

	// load and process candidate strings
	for i := 0; ifile.Scan(); i++ {
		s := ifile.Text()
		if dfa.Accepts(s) != nil {
			fmt.Println("accept:", s)
		} else {
			fmt.Println("REJECT:", s)
		}
	}
	rx.CkErr(ifile.Err())
}
开发者ID:proebsting,项目名称:re,代码行数:27,代码来源:rxq.go

示例8: pidForTid

func pidForTid(tid int) (pid int, err error) {
	var (
		status  *os.File
		scanner *bufio.Scanner
		splits  []string
	)

	status, err = os.Open(fmt.Sprintf("/proc/%d/status", tid))
	if err != nil {
		return
	}
	defer status.Close()

	scanner = bufio.NewScanner(status)
	for scanner.Scan() {
		splits = strings.Split(scanner.Text(), ":")
		if splits[0] != "Tgid" {
			continue
		}

		pid, err = strconv.Atoi(strings.TrimSpace(splits[1]))
		return
	}

	if err = scanner.Err(); err != nil {
		return
	}

	err = fmt.Errorf("Pid not found for proc %d", tid)
	return
}
开发者ID:dilgerma,项目名称:scope,代码行数:31,代码来源:ptracer.go

示例9: readFrontMatter

// Read the front matter from the post. If there is no front matter, this is
// not a valid post.
func readFrontMatter(s *bufio.Scanner) (map[string]string, error) {
	m := make(map[string]string)
	infm := false
	for s.Scan() {
		l := strings.Trim(s.Text(), " ")
		if l == "---" { // The front matter is delimited by 3 dashes
			if infm {
				// This signals the end of the front matter
				return m, nil
			} else {
				// This is the start of the front matter
				infm = true
			}
		} else if infm {
			sections := strings.SplitN(l, ":", 2)
			if len(sections) != 2 {
				// Invalid front matter line
				return nil, ErrInvalidFrontMatter
			}
			m[sections[0]] = strings.Trim(sections[1], " ")
		} else if l != "" {
			// No front matter, quit
			return nil, ErrMissingFrontMatter
		}
	}
	if err := s.Err(); err != nil {
		return nil, err
	}
	return nil, ErrEmptyPost
}
开发者ID:lynndotconfig,项目名称:trofaf,代码行数:32,代码来源:tpldata.go

示例10: QueryVerify

// QueryVerify writes a question to w and waits for an answer to be read from
// scanner.  It will pass the answer into the verify function.  Verify, if
// non-nil, should check the answer for validity, returning an error that will
// be written out to the user, or nil if answer is valid.
//
// This function takes a scanner rather than an io.Reader to avoid the case
// where the scanner reads past the delimiter and thus might lose data.  It is
// expected that this method will be used repeatedly with the same scanner if
// multiple queries are required.
func QueryVerify(question []byte, scanner *bufio.Scanner, w io.Writer, verify func(string) error) (answer string, err error) {
	defer fmt.Fprint(w, "\n")
	for {
		if _, err = w.Write(question); err != nil {
			return "", err
		}

		if !scanner.Scan() {
			if err := scanner.Err(); err != nil {
				return "", err
			}
			return "", io.EOF
		}
		answer = scanner.Text()
		if verify == nil {
			return answer, nil
		}
		err := verify(answer)
		// valid answer, return it!
		if err == nil {
			return answer, nil
		}
		// invalid answer, inform user of problem and retry.
		_, err = fmt.Fprint(w, err, "\n\n")
		if err != nil {
			return "", err
		}
	}
}
开发者ID:bac,项目名称:juju,代码行数:38,代码来源:query.go

示例11: readFrontMatter

func readFrontMatter(s *bufio.Scanner) map[string]string {
	m := make(map[string]string)
	infm := false
	for s.Scan() {
		l := strings.Trim(s.Text(), " ")
		if l == "/*---" || l == "---*/" { // The front matter is delimited by 3 dashes and in a block comment
			if infm {
				// This signals the end of the front matter
				return m
			} else {
				// This is the start of the front matter
				infm = true
			}
		} else if infm {
			sections := strings.SplitN(l, ":", 2)
			if len(sections) != 2 {
				// Invalid front matter line
				return nil
			}
			m[sections[0]] = strings.Trim(sections[1], " ")
		} else if l != "" {
			// No front matter, quit
			return nil
		}
	}
	if err := s.Err(); err != nil {
		// The scanner stopped because of an error
		return nil
	}
	return nil
}
开发者ID:jmptrader,项目名称:agora,代码行数:31,代码来源:agora_test.go

示例12: readNames

func readNames(names []string) ([]string, error) {
	if len(inputFile) == 0 {
		return names, nil
	}

	var scanner *bufio.Scanner
	if inputFile != "-" {
		in, err := os.Open(inputFile)
		if err != nil {
			return nil, err
		}

		defer in.Close()
		scanner = bufio.NewScanner(in)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}

	for scanner.Scan() {
		names = append(names, scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return names, nil
}
开发者ID:ericcapricorn,项目名称:gotags,代码行数:27,代码来源:main.go

示例13: parseHeader

// parseHeader parses the first two lines of a block described in
// ParseFilelist docs. So it returns a data kind (files, symlinks or
// dirs) and a count of elements in the following list. If the
// returned kind is empty then it means that there is no more entries
// (provided that there is no error either).
func parseHeader(scanner *bufio.Scanner) (string, int, error) {
	if !scanner.Scan() {
		if err := scanner.Err(); err != nil {
			return "", 0, err
		}
		// no more entries in the file, just return empty kind
		return "", 0, nil
	}
	kind := scanner.Text()
	if kind == "" {
		return "", 0, fmt.Errorf("got an empty kind, expected 'files', 'symlinks' or 'dirs'")
	}
	if !scanner.Scan() {
		if err := scanner.Err(); err != nil {
			return "", 0, err
		} else {
			return "", 0, fmt.Errorf("expected a line with a count, unexpected EOF?")
		}
	}
	countReader := strings.NewReader(scanner.Text())
	count := 0
	n, err := fmt.Fscanf(countReader, "(%d)", &count)
	if err != nil {
		return "", 0, err
	}
	if n != 1 {
		return "", 0, fmt.Errorf("incorrectly formatted line with number of %s", kind)
	}
	return kind, count, nil
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:35,代码来源:filelist.go

示例14: parseList

// parseList parses the list part of a block. It makes sure that there
// is an exactly expected count of items.
func parseList(scanner *bufio.Scanner, count int) ([]string, error) {
	got := 0
	items := make([]string, 0, count)
	for {
		if !scanner.Scan() {
			if err := scanner.Err(); err != nil {
				return nil, err
			}
			return nil, fmt.Errorf("expected either an empty line or a line with an item, unexpected EOF?")
		}
		line := scanner.Text()
		if line == "" {
			if got < count {
				return nil, fmt.Errorf("too few items (declared %d, got %d)", count, got)
			}
			break
		}
		got++
		if got > count {
			return nil, fmt.Errorf("too many items (declared %d)", count)
		}
		items = append(items, line)
	}
	return items, nil
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:27,代码来源:filelist.go

示例15: LoadFromScanner

//  LoadFromScanner reads and parses expressions from a bufio.Scanner.
//
//  Empty lines and lines beginning with '#' are treated as comments.
//  If non-nil, the function f is called for each non-metadata line read.
//  The returned array contains only successfully parsed expressions.
//
//  Metadata from comments matching the pattern "^#\w+:" is accumulated and
//  returned with the next non-metadata line (whether comment or expr).
//
//  The globals InputRegExCount and InputExprErrors are set by this function.
func LoadFromScanner(efile *bufio.Scanner, f func(*RegExParsed)) []*RegExParsed {
	mpat := regexp.MustCompile(`^#(\w+): *(.*)`)
	elist := make([]*RegExParsed, 0)
	meta := make(map[string]string)
	InputRegExCount = 0
	InputErrorCount = 0
	for efile.Scan() {
		line := efile.Text()
		e := &RegExParsed{Expr: line}
		if IsComment(line) {
			r := mpat.FindStringSubmatch(line)
			if r != nil { // if recognized metadata format
				addMeta(meta, r[1], r[2]) // accumulate metadata
				continue                  // and don't call
			} else {
				e.Meta = meta // return accumulation
			}
		} else {
			e.Tree, e.Err = Parse(line) // parse input
			if e.Tree != nil {          // if okay
				elist = append(elist, e) // save parse tree
				InputRegExCount++        // count success
			} else {
				InputErrorCount++ // else count error
			}
			e.Meta = meta // accumulated metadata
		}
		if f != nil {
			f(e)
		}
		meta = make(map[string]string) // reset meta collection
	}
	CkErr(efile.Err())
	return elist
}
开发者ID:proebsting,项目名称:re,代码行数:45,代码来源:input.go


注:本文中的bufio.Scanner.Err方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。