本文整理匯總了Golang中container/vector.StringVector.Data方法的典型用法代碼示例。如果您正苦於以下問題:Golang StringVector.Data方法的具體用法?Golang StringVector.Data怎麽用?Golang StringVector.Data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類container/vector.StringVector
的用法示例。
在下文中一共展示了StringVector.Data方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GenerateTestMain
// GenerateTestMain returns the source code for a test program that will run
// the specified test functions from the specified package.
func GenerateTestMain(packageName string, funcs *set.StringSet) string {
var funcVec vector.StringVector
for val := range funcs.Iter() {
funcVec.Push(val)
}
result := ""
result += "package main\n\n"
result += "import \"testing\"\n"
if funcVec.Len() > 0 {
result += fmt.Sprintf("import \"./%s\"\n\n", packageName)
}
result += "var tests = []testing.Test {\n"
for _, val := range funcVec.Data() {
result += fmt.Sprintf("\ttesting.Test{\"%s\", %s.%s},\n", val, packageName, val)
}
result += "}\n\n"
result += "func main() {\n"
result += "\ttesting.Main(tests)\n"
result += "}\n"
return result
}
示例2: getSorted
func getSorted(set *StringSet) []string {
var sorted vector.StringVector
for val := range set.Iter() {
sorted.Push(val)
}
sort.SortStrings(sorted)
return sorted.Data()
}
示例3: Matches
func (self *Regex) Matches(s string) []string {
res := new(vector.StringVector)
self.l.StartString(s)
for !self.l.Eof() {
if self.l.Next() == 0 {
res.Push(self.l.String())
}
}
return res.Data()
}
示例4: expectContentsEqual
func expectContentsEqual(t *testing.T, set *set.StringSet, expected []string) {
var contents vector.StringVector
for val := range set.Iter() {
contents.Push(val)
}
sort.SortStrings(contents)
sort.SortStrings(expected)
if !reflect.DeepEqual(contents.Data(), expected) {
t.Errorf("Expected:%v\nGot: %v", expected, contents)
}
}
示例5: _ToString
func (p *MatchRule) _ToString() string {
svec := new(vector.StringVector)
v := reflect.Indirect(reflect.NewValue(p)).(*reflect.StructValue)
t := v.Type().(*reflect.StructType)
for i := 0; i < v.NumField(); i++ {
str, ok := v.Field(i).Interface().(string)
if ok && "" != str {
svec.Push(fmt.Sprintf("%s='%s'", strings.ToLower(t.Field(i).Name), str))
}
}
return strings.Join(svec.Data(), ",")
}
示例6: Replace
func (self *Regex) Replace(s string, f func(string) string) string {
res := new(vector.StringVector)
buf := bytes.Runes([]byte(s))
last := 0
self.l.StartString(s)
for !self.l.Eof() {
if self.l.Next() == 0 {
res.Push(string(buf[last:self.l.Pos()]))
res.Push(f(self.l.String()))
last = self.l.Pos() + self.l.Len()
}
}
res.Push(string(buf[last:]))
return strings.Join(res.Data(), "")
}
示例7: linkBinary
// linkBinary calls 6l to link the binary of the given name, which must have
// already been compiled with compileFiles.
func linkBinary(name string) {
linkerName, ok := linkers[os.Getenv("GOARCH")]
if !ok {
fmt.Println("Could not determine the correct linker to run.")
fmt.Println("Please ensure that $GOARCH is set.")
os.Exit(1)
}
linkerPath := path.Join(os.Getenv("GOBIN"), linkerName)
var linkerArgs vector.StringVector
linkerArgs.Push("-o")
linkerArgs.Push(name)
linkerArgs.Push(name + "." + linkerName[0:1])
if !executeCommand(linkerPath, linkerArgs.Data(), "igo-out/") {
os.Exit(1)
}
}
示例8: compileFiles
// compileFiles invokes 6g with the appropriate arguments for compiling the
// supplied set of .go files, and exits the program if the subprocess fails.
func compileFiles(files *set.StringSet, targetBaseName string) {
compilerName, ok := compilers[os.Getenv("GOARCH")]
if !ok {
fmt.Println("Could not determine the correct compiler to run.")
fmt.Println("Please ensure that $GOARCH is set.")
os.Exit(1)
}
compilerPath := path.Join(os.Getenv("GOBIN"), compilerName)
gopackPath := path.Join(os.Getenv("GOBIN"), "gopack")
targetDir, _ := path.Split(targetBaseName)
if targetDir != "" {
os.MkdirAll(path.Join("igo-out", targetDir), 0700)
}
// Compile
var compilerArgs vector.StringVector
compilerArgs.Push("-o")
compilerArgs.Push(targetBaseName + ".6")
for file := range files.Iter() {
compilerArgs.Push(path.Join("../", file))
}
if !executeCommand(compilerPath, compilerArgs.Data(), "igo-out/") {
os.Exit(1)
}
// Pack
var gopackArgs vector.StringVector
gopackArgs.Push("grc")
gopackArgs.Push(targetBaseName + ".a")
gopackArgs.Push(targetBaseName + ".6")
if !executeCommand(gopackPath, gopackArgs.Data(), "igo-out/") {
os.Exit(1)
}
}
示例9: Parse
func Parse(line string) *Message {
m := &Message{}
matches := re.MatchStrings(line)
if len(matches) != 4 {
return nil
}
prefix, command, params := matches[1], matches[2], matches[3]
if len(prefix) > 2 {
m.Prefix = prefix[1 : len(prefix)-1]
}
m.Command = strings.ToUpper(command)
paramArray := new(vector.StringVector)
param := ""
for i, c := range params {
switch {
case c == ' ':
if param != "" {
paramArray.Push(param)
param = ""
}
case c == ':' && param == "":
paramArray.Push(params[i+1 : len(params)])
goto done
default:
param += string(c)
}
}
if param != "" {
paramArray.Push(param)
param = ""
}
done:
m.Params = paramArray.Data()
return m
}
示例10: executeCommand
// executeCommand runs the specified tool with the supplied arguments (not
// including the path to the tool itself), chdir'ing to the specified directory
// first. It returns true if and only if the child process returns zero.
func executeCommand(tool string, args []string, dir string) bool {
fmt.Printf("%s %s\n", tool, strings.Join(args, " "))
var fullArgs vector.StringVector
fullArgs.Push(tool)
fullArgs.AppendVector(&args)
pid, err := os.ForkExec(
tool,
fullArgs.Data(),
os.Environ(),
dir,
[]*os.File{os.Stdin, os.Stdout, os.Stderr})
if err != nil {
panic(err)
}
waitMsg, err := os.Wait(pid, 0)
if err != nil {
panic(err)
}
return waitMsg.ExitStatus() == 0
}
示例11: join
func join(sv *vector.StringVector, sep string) string {
return strings.Join(sv.Data(), sep)
}
示例12: main
func main() {
sqlite3.Initialize()
defer func() {
log.Stdout("closing sqlite3")
sqlite3.Shutdown()
}()
dbh := new(sqlite3.Handle)
dbh.Open("bbs.db")
defer dbh.Close()
InitTables(dbh)
flag.Parse()
templ := func() *template.Template {
templateStr, err := io.ReadFile("tmpl/top.tmpl")
if err != nil {
log.Exit(err)
}
return template.MustParse(string(templateStr), nil)
}()
http.Handle("/", http.HandlerFunc(func(c *http.Conn, req *http.Request) {
params := new(struct{ msgs []string })
storage := new(vector.StringVector)
func() {
st, err := dbh.Prepare("SELECT * from entry ORDER BY id DESC limit 30;")
func() {
if err != "" {
log.Exit(err)
}
for {
rv := st.Step()
switch {
case rv == sqlite3.SQLITE_DONE:
return
case rv == sqlite3.SQLITE_ROW:
body := st.ColumnText(1)
storage.Push(body)
default:
println(rv)
log.Exit(dbh.ErrMsg())
}
}
}()
if st.Finalize() != sqlite3.SQLITE_OK {
log.Exit(dbh.ErrMsg())
}
}()
params.msgs = storage.Data()
err := templ.Execute(params, c)
if err != nil {
log.Exit("templ.Execute:", err)
}
}))
http.Handle("/post", http.HandlerFunc(func(c *http.Conn, req *http.Request) {
req.ParseForm()
body := req.Form["body"][0]
st, err := dbh.Prepare("INSERT INTO entry (body) VALUES (?)")
if err != "" {
log.Exit(err)
}
if st.BindText(1, body) != sqlite3.SQLITE_OK {
log.Exit("cannot bind: ", dbh.ErrMsg())
}
if st.Step() != sqlite3.SQLITE_DONE {
log.Exit(dbh.ErrMsg())
}
if st.Finalize() != sqlite3.SQLITE_OK {
log.Exit(dbh.ErrMsg())
}
http.Redirect(c, "/", 302)
}))
http.Handle("/css/", http.HandlerFunc(func(c *http.Conn, req *http.Request) {
http.ServeFile(c, req, "."+req.URL.Path)
}))
// run httpd
func() {
fmt.Printf("http://%s/\n", *addr)
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Exit("ListenAndServe:", err)
}
}()
}