jsonconfig: remove use of container/vector (not part of Go 1)

Change-Id: I55e9595f351ca16589287a8729243a2fe456d2c4
This commit is contained in:
Brad Fitzpatrick 2011-11-26 16:10:56 -05:00
parent d12b671c4c
commit fff17c762b
2 changed files with 20 additions and 5 deletions

View File

@ -17,7 +17,6 @@ limitations under the License.
package jsonconfig
import (
"container/vector"
"fmt"
"json"
"log"
@ -30,19 +29,35 @@ import (
"camli/osutil"
)
type stringVector struct {
v []string
}
func (v *stringVector) Push(s string) {
v.v = append(v.v, s)
}
func (v *stringVector) Pop() {
v.v = v.v[:len(v.v)-1]
}
func (v *stringVector) Last() string {
return v.v[len(v.v)-1]
}
// State for config parsing and expression evalutaion
type configParser struct {
RootJson Obj
touchedFiles map[string]bool
includeStack vector.StringVector
includeStack stringVector
}
// Validates variable names for config _env expresssions
var envPattern = regexp.MustCompile(`\$\{[A-Za-z0-9_]+\}`)
// Decodes and evaluates a json config file, watching for include cycles.
func (c *configParser) recursiveReadJson(configPath string) (decodedObject map[string]interface{}, err os.Error) {
func (c *configParser) recursiveReadJSON(configPath string) (decodedObject map[string]interface{}, err os.Error) {
configPath, err = filepath.Abs(configPath)
if err != nil {
@ -207,7 +222,7 @@ func (c *configParser) expandFile(v []interface{}) (exp interface{}, err os.Erro
if incPath, err = osutil.FindCamliInclude(v[0].(string)); err != nil {
return "", fmt.Errorf("Included config does not exist: %v", v[0])
}
if exp, err = c.recursiveReadJson(incPath); err != nil {
if exp, err = c.recursiveReadJSON(incPath); err != nil {
return "", fmt.Errorf("In file included from %s:\n%v",
c.includeStack.Last(), err)
}

View File

@ -33,7 +33,7 @@ func ReadFile(configPath string) (Obj, os.Error) {
var c configParser
var err os.Error
c.touchedFiles = make(map[string]bool)
c.RootJson, err = c.recursiveReadJson(configPath)
c.RootJson, err = c.recursiveReadJSON(configPath)
return c.RootJson, err
}