作者:caneroj
项目:cardsDat
func getContinueInput(scanner *bufio.Scanner) bool {
ok := scanner.Scan()
if !ok {
return false
}
return scanner.Text() == "y"
}
作者:gophergala201
项目:fireu
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())
}
}
作者:Kashomo
项目:go-ja
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()
}
作者:pranke
项目:twitchca
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,
})
}
作者:rchunpin
项目:go-gcstat
// 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
}
作者:brownjohn
项目:sudok
// 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++
}
}
作者:vishwesh
项目:alg
func next(in *bufio.Scanner, shouldScan bool) int {
if shouldScan {
in.Scan()
}
n, _ := strconv.Atoi(in.Text())
return n
}
作者:postfi
项目:metric
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
}
作者:unrealor
项目:bitcanno
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")
}
作者:rychipma
项目:m3
func getNextLine(s *bufio.Scanner) string {
more := s.Scan()
if !more {
checkScanError(s)
}
return s.Text()
}
作者:liquid
项目:shelltes
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
}
作者:benjgibb
项目:G
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
}
}
}
作者:N1xx
项目:golang-i18
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
}
作者:zeeb
项目:mebipenny201
func readBoard(scanner *bufio.Scanner) (out board) {
for scanner.Scan() {
parts := strings.Split(scanner.Text(), ",")
out = append(out, parts)
}
return out
}
作者:ikravet
项目:e
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
}
作者:noscripte
项目:rexde
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
}
作者:y0k0ta1
项目:golang_trainin
func cd(commandSc *bufio.Scanner, conn net.Conn) {
if commandSc.Scan() {
path := commandSc.Text()
fmt.Println(path)
cdPath(path, conn)
}
}
作者:warmfusio
项目:cach
// 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()
}
作者:zuBu
项目:crashwal
func mustAdvanceTo(token string, scanner *bufio.Scanner, die func()) {
for scanner.Scan() {
if strings.HasPrefix(scanner.Text(), token) {
return
}
}
die()
}
作者:nicholasjackso
项目:go-microservice-templat
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"
}