1 Star 0 Fork 0

王军 / govaluate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
expressionOutputStream.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
George Lester 提交于 2016-08-15 19:54 . test-failing version of sql ternary
package govaluate
import (
"bytes"
)
/*
Holds a series of "transactions" which represent each token as it is output by an outputter (such as ToSQLQuery()).
Some outputs (such as SQL) require a function call or non-c-like syntax to represent an expression.
To accomplish this, this struct keeps track of each translated token as it is output, and can return and rollback those transactions.
*/
type expressionOutputStream struct {
transactions []string
}
func (this *expressionOutputStream) add(transaction string) {
this.transactions = append(this.transactions, transaction)
}
func (this *expressionOutputStream) rollback() string {
index := len(this.transactions) - 1
ret := this.transactions[index]
this.transactions = this.transactions[:index]
return ret
}
func (this *expressionOutputStream) createString(delimiter string) string {
var retBuffer bytes.Buffer
var transaction string
penultimate := len(this.transactions) - 1
for i := 0; i < penultimate; i++ {
transaction = this.transactions[i]
retBuffer.WriteString(transaction)
retBuffer.WriteString(delimiter)
}
retBuffer.WriteString(this.transactions[penultimate])
return retBuffer.String()
}
Go
1
https://gitee.com/haodreams/govaluate.git
git@gitee.com:haodreams/govaluate.git
haodreams
govaluate
govaluate
v3.0.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891