本文整理汇总了Golang中bufio.Scanner类的典型用法代码### 示例。如果您正苦于以下问题:Golang Scanner类的具体用法?Golang Scanner怎么用?Golang Scanner使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。
在下文中一共展示了Scanner类的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: getContinueInput
func getContinueInput(scanner *bufio.Scanner) bool {
ok := scanner.Scan()
if !ok {
return false
}
return scanner.Text() == "y"
}
开发者ID:caneroj1,项目名称:cardsData,代码行数:7,代码来源:readData.go
示例2: PushFile
func PushFile(host string, port int, fname string) {
var scanner *bufio.Scanner
if len(fname) == 0 {
scanner = bufio.NewScanner(os.Stdin)
} else {
file, err := os.Open(fname)
defer file.Close()
if err != nil {
fmt.Fprintln(os.Stderr, "ERROR", err)
return
}
scanner = bufio.NewScanner(file)
}
addr := fmt.Sprintf("%s:%d", host, port)
conn, err := net.Dial("tcp", addr)
if err != nil {
fmt.Fprintln(os.Stderr, "ERROR:", err)
return
}
for scanner.Scan() {
fmt.Fprintln(conn, scanner.Text())
}
}
开发者ID:gophergala2016,项目名称:fireup,代码行数:29,代码来源:push.go
示例3: GetNextLine
func GetNextLine(i int, s *bufio.Scanner) string {
ok := s.Scan()
if !ok {
panic(fmt.Sprintf("EOF. expected more lines during problem %v", i))
}
return s.Text()
}
开发者ID:Kashomon,项目名称:go-jam,代码行数:7,代码来源:base.go
示例4: media
func (this *M3U) media(scanner *bufio.Scanner) {
line := scanner.Text()
buf := make(map[string]string)
scanner.Scan()
l2 := scanner.Text()
scanner.Scan()
toMap(line[strings.Index(line, ":")+1:]+","+l2[strings.Index(l2, ":")+1:], buf)
rank := 0
switch buf["VIDEO"] {
case "chunked":
rank = 1
case "high":
rank = 2
case "medium":
rank = 3
case "low":
rank = 4
case "mobile":
rank = 5
}
this.PlayLists = append(this.PlayLists, M3UStream{
Video: buf["VIDEO"],
Name: buf["NAME"],
Resolution: buf["RESOLUTION"],
Location: scanner.Text(),
Rank: rank,
})
}
开发者ID:pranked,项目名称:twitchcap,代码行数:28,代码来源:m3u.go
示例5: phasesFromLog14
// phasesFromLog14 parses the phases for a single Go 1.4 GC cycle.
func phasesFromLog14(scanner *bufio.Scanner) (phases []Phase, haveBegin bool) {
sub := gc14Log.FindStringSubmatch(scanner.Text())
n := atoi(sub[1])
stop, sweepTerm, markTerm, shrink := atoi(sub[2]), atoi(sub[3]), atoi(sub[4]), atoi(sub[5])
var begin int64
if sub[6] != "" {
begin = atoi64(sub[6][1:])
haveBegin = true
}
phases = []Phase{
// Go 1.5 includes stoptheworld() in sweep termination.
{0, int64(stop+sweepTerm) * 1000, PhaseSweepTerm, n, 1, 1, true},
// Go 1.5 includes stack shrink in mark termination.
{0, int64(markTerm+shrink) * 1000, PhaseMarkTerm, n, 1, 1, true},
{0, -1, PhaseSweep, n, 1, 0, false},
}
if haveBegin {
for i := range phases {
phases[i].Begin += begin
begin += phases[i].Duration
}
}
return
}
开发者ID:rchunping,项目名称:go-gcstats,代码行数:29,代码来源:parse.go
示例6: buildBoard
// buildBoard builds a "board" (an array) by scanning input, splitting comma-
// separated integers and inserting them into an array.
func buildBoard(input *bufio.Scanner, board *[81]int) {
l := 0
for input.Scan() {
for i, n := range strings.Split(input.Text(), ",") {
var val int
// If i is a dash, val is 0
if n == "-" {
val = 0
} else {
// Convert i to an int
val2, err := strconv.Atoi(n)
if err != nil {
fmt.Println(os.Stderr, err)
os.Exit(2)
}
val = val2
}
board[i+9*l] = val
}
l++
}
}
开发者ID:brownjohnf,项目名称:sudoku,代码行数:28,代码来源:sudoku.go
示例7: next
func next(in *bufio.Scanner, shouldScan bool) int {
if shouldScan {
in.Scan()
}
n, _ := strconv.Atoi(in.Text())
return n
}
开发者ID:vishwesh5,项目名称:algo,代码行数:7,代码来源:1880.go
示例8: run
func run(ruleset *internal.RuleSet, scanner *bufio.Scanner, apiInstance api.API, unmatched *os.File) Statistics {
stat := Statistics{
perMetric: make(map[api.MetricKey]PerMetricStatistics),
}
for scanner.Scan() {
input := scanner.Text()
converted, matched := ruleset.MatchRule(input)
if matched {
stat.matched++
perMetric := stat.perMetric[converted.MetricKey]
perMetric.matched++
reversed, err := ruleset.ToGraphiteName(converted)
if *insertToDatabase {
apiInstance.AddMetric(converted)
}
if err != nil {
perMetric.reverseError++
} else if string(reversed) != input {
perMetric.reverseIncorrect++
} else {
perMetric.reverseSuccess++
}
stat.perMetric[converted.MetricKey] = perMetric
} else {
stat.unmatched++
if unmatched != nil {
unmatched.WriteString(input)
unmatched.WriteString("\n")
}
}
}
return stat
}
开发者ID:postfix,项目名称:metrics,代码行数:33,代码来源:ruletester.go
示例9: importReader
func importReader(reader io.Reader, gzipped bool) {
var scanner *bufio.Scanner
if gzipped {
gReader, err := gzip.NewReader(reader)
if err != nil {
log.Println("[ERR] My bad! I tried to start uncompressing your archive but failed.")
log.Println(" Try checking the file, or send me the file so I can check it out.")
return
}
defer gReader.Close()
log.Println("[OK!] GZip detected, unzipping enabled")
scanner = bufio.NewScanner(gReader)
} else {
scanner = bufio.NewScanner(reader)
}
log.Println("[OK!] Reading initialized")
imported := 0
skipped := 0
// Now we scan ୧༼ಠ益ಠ༽୨
for scanner.Scan() {
status, _ := importLine(scanner.Text())
if status {
imported++
} else {
skipped++
}
}
log.Println("[OK!] Reading completed")
log.Println(" " + strconv.Itoa(imported) + " torrents imported")
log.Println(" " + strconv.Itoa(skipped) + " torrents skipped")
}
开发者ID:unrealord,项目名称:bitcannon,代码行数:31,代码来源:import.go
示例10: getNextLine
func getNextLine(s *bufio.Scanner) string {
more := s.Scan()
if !more {
checkScanError(s)
}
return s.Text()
}
开发者ID:rychipman,项目名称:m3u,代码行数:7,代码来源:m3u.go
示例11: scanLoop
func scanLoop(scanner *bufio.Scanner, outCh chan string, outTermCh chan bool) {
first := true
buf := new(bytes.Buffer)
for scanner.Scan() {
text := scanner.Text()
if DeleteColor(text) == Delimiter {
if first {
first = false
} else {
text := strings.TrimSpace(buf.String())
DebugPrint("shell", "out <- [%v]", text)
outCh <- text
buf = new(bytes.Buffer)
}
} else {
DebugPrint("shell", "read [%v]", text)
buf.WriteString(text + "\n")
}
}
text := strings.TrimSpace(buf.String())
DebugPrint("shell", "out <- [%v]", text)
if text != "" {
outCh <- text
}
outTermCh <- true
}
开发者ID:liquidz,项目名称:shelltest,代码行数:27,代码来源:shell.go
示例12: orderedRemoval
func orderedRemoval(scanner *bufio.Scanner) {
var entries Entries
rows := 0
count := 0
for scanner.Scan() {
line := scanner.Text()
parts := strings.Split(line, " ")
parts = removeSpaces(parts)
for col, str := range parts {
entry := Entry{atoi(str), rows, col}
entries = append(entries, entry)
count++
}
rows++
}
fmt.Printf("Matrix dimensions: rows=%d, cols=%d\n", rows, count/rows)
sort.Sort(entries)
best := 0
for i := 0; i < 1000; i++ {
sum := run(entries, rows, count/rows)
if sum > best {
fmt.Printf("sum=%d, i=%d\n", sum, i)
best = sum
}
}
}
开发者ID:benjgibbs,项目名称:Go,代码行数:27,代码来源:p345.go
示例13: parseFile
func parseFile(scanner *bufio.Scanner) (map[string]string, error) {
translations := make(map[string]string)
definitionRegexp := regexp.MustCompile(`^([\d\w\-_]+)\s*=\s*(".*")\s*(?:\#.*)?$`)
emptyLineRegexp := regexp.MustCompile(`^(|\s*(\#.*)?)$`)
for lineNumber := 1; scanner.Scan(); lineNumber++ {
line := scanner.Text()
if emptyLineRegexp.MatchString(line) {
continue
}
matches := definitionRegexp.FindStringSubmatch(line)
if len(matches) != 3 {
return nil, errors.New(fmt.Sprintf("Malformed line :%d (%q)", lineNumber, line))
}
unquoted, err := strconv.Unquote(matches[2])
if err != nil {
return nil, errors.New(fmt.Sprintf("Malformed string :%d (%q)", lineNumber, line))
}
if _, ok := translations[matches[1]]; ok {
return nil, errors.New(fmt.Sprintf("Multiple definitions of key %q", matches[1]))
}
translations[matches[1]] = unquoted
}
return translations, nil
}
开发者ID:N1xx1,项目名称:golang-i18n,代码行数:29,代码来源:i18n.go
示例14: readBoard
func readBoard(scanner *bufio.Scanner) (out board) {
for scanner.Scan() {
parts := strings.Split(scanner.Text(), ",")
out = append(out, parts)
}
return out
}
开发者ID:zeebo,项目名称:mebipenny2015,代码行数:7,代码来源:main.go
示例15: adhocTextFix
func adhocTextFix(scanner *bufio.Scanner) string {
text := scanner.Text()
r := regexp.MustCompile("(^\\s*Open State.*Alphabetic ) (The allowable values are:)")
text = r.ReplaceAllString(text, "$1$2")
r2 := regexp.MustCompile("^(Number Delta {26})(associated with the new quote)$")
text = r2.ReplaceAllString(text, "$1 $2")
r3 := regexp.MustCompile("^ (Ask|Bid) Reference {41}The (ask|bid) reference number delta$")
if r3.MatchString(text) {
scanner.Scan()
text = superimposeStrings(text, scanner.Text())
}
r4 := regexp.MustCompile("^Total Number of")
if r4.MatchString(text) {
text = "Total Number of Reference 5 2 Integer The number of single side deletes in this"
scanner.Scan()
scanner.Scan()
}
r5 := regexp.MustCompile("^Reference {45}The order/quote side reference number")
if r5.MatchString(text) {
scanner.Scan()
scanner.Scan()
text = ""
}
return text
}
开发者ID:ikravets,项目名称:ev,代码行数:31,代码来源:main.go
示例16: extractCore
func extractCore(module string, scanner *bufio.Scanner, config *Config) *Dependency {
dependency := newDependency()
enable := config.Start == nil
for scanner.Scan() {
line := scanner.Text()
if config.Start != nil && config.Start.MatchString(line) {
enable = true
}
if config.Module != nil {
if matches := config.Module.FindStringSubmatch(line); matches != nil {
module = matches[len(matches)-1]
}
}
if enable {
if matches := config.Pattern.FindStringSubmatch(line); len(matches) >= 1 {
for _, name := range matches[1:] {
if name != "" {
dependency.add(module, name)
}
}
}
}
if enable && config.End != nil && config.End.MatchString(line) {
enable = false
}
}
return dependency
}
开发者ID:noscripter,项目名称:rexdep,代码行数:28,代码来源:extract.go
示例17: cd
func cd(commandSc *bufio.Scanner, conn net.Conn) {
if commandSc.Scan() {
path := commandSc.Text()
fmt.Println(path)
cdPath(path, conn)
}
}
开发者ID:y0k0ta19,项目名称:golang_training,代码行数:7,代码来源:ftpServer.go
示例18: BuildRetentions
// BuildRetentions build cache storage retention matchers
func (cs *CacheStorage) BuildRetentions(retentionScanner *bufio.Scanner) error {
cs.retentions = make([]retentionMatcher, 0, 100)
for retentionScanner.Scan() {
line := retentionScanner.Text()
if strings.HasPrefix(line, "#") || strings.Count(line, "=") != 1 {
continue
}
pattern, err := regexp.Compile(strings.TrimSpace(strings.Split(line, "=")[1]))
if err != nil {
return err
}
retentionScanner.Scan()
line = retentionScanner.Text()
retentions := strings.TrimSpace(strings.Split(line, "=")[1])
retention, err := rawRetentionToSeconds(retentions[0:strings.Index(retentions, ":")])
if err != nil {
return err
}
cs.retentions = append(cs.retentions, retentionMatcher{
pattern: pattern,
retention: retention,
})
}
return retentionScanner.Err()
}
开发者ID:warmfusion,项目名称:cache,代码行数:30,代码来源:cache.go
示例19: mustAdvanceTo
func mustAdvanceTo(token string, scanner *bufio.Scanner, die func()) {
for scanner.Scan() {
if strings.HasPrefix(scanner.Text(), token) {
return
}
}
die()
}
开发者ID:zuBux,项目名称:crashwalk,代码行数:8,代码来源:gdb.go
示例20: confirm
func confirm(serviceName, nameSpace string, scanner *bufio.Scanner) bool {
fmt.Printf("Generating Microservice template: %s/%s in GOPATH\n", nameSpace, serviceName)
fmt.Printf("Is this correct? (y|n)\n")
scanner.Scan()
line := scanner.Text()
return line == "y"
}
开发者ID:nicholasjackson,项目名称:go-microservice-template,代码行数:8,代码来源:generate.go