blob: 5256b70ecae95cae6eb6cb5fbbacbb321c06cc05 [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package codifier
import "log"
// ReadFileIntoList Reads the given file and store its lines as a list under the
// given name.
func (p *Proc) ReadFileIntoList(filename, listname string) *Proc {
if p == nil {
log.Println(" ReadFileIntoList() error: nil receiver")
return nil
}
lines, err := orderedStringsFromFile(filename)
if err != nil {
log.Printf(" ReadFileIntoList() read err: %v", err)
return nil
}
p.Store[listname] = lines
return p
}
// StopIfInList sets the proc pointer to nil if the given item is in the list
// stored under the listKey. The effect is that the calling chain will stop if
// the item is in the list.
func (p *Proc) StopIfInList(item, listKey string) *Proc {
if p == nil {
log.Println(" StopIfInList() error: nil receiver")
return nil
}
items, ok := p.Store[listKey].(orderedStrings)
if !ok {
log.Printf(" StopIfInList(): list key %q not present in store", listKey)
return nil
}
if items.contains(item) {
log.Printf(" StopIfInList(): stopping changes to %q", item)
return nil
}
return p
}
// ListContains returns whether the given item is present in the list stored
// under the given key. Use this operator when the stored list contains
// orderedStrings.
func (p *Proc) ListContains(listKey, item string) bool {
if p == nil {
log.Println(" ListContains() error: nil receiver")
return false
}
storedList, ok := p.Store[listKey].(orderedStrings)
if !ok {
log.Printf(" ListContains(): list %q not present in store", listKey)
return false
}
return storedList.contains(item)
}