Beispiel #1
0
// 返回一个qwordBuilder的描述信息
func (qb *QWBuilder) String() string {
	sb := z.StringBuilder()
	kwidth := 15
	sb.Append("QWorldBuilder Setup").EOL()
	sb.Append(z.AlignLeft("gOr", kwidth, ' ')).Append(": ").Append(qb.GOr).EOL()
	sb.Append(z.AlignLeft("gAnd", kwidth, ' ')).Append(": ").Append(qb.GAnd).EOL()
	sb.Append(z.AlignLeft("sepOr", kwidth, ' ')).Append(": ").Append(qb.SepOr).EOL()
	sb.Append(z.AlignLeft("sepAnd", kwidth, ' ')).Append(": ").Append(qb.SepAnd).EOL()
	sb.Append(z.AlignLeft("quoteBegin", kwidth, ' ')).Append(": ").Append(qb.QuoteBegin).EOL()
	sb.Append(z.AlignLeft("quoteEnd", kwidth, ' ')).Append(": ").Append(qb.QuoteEnd).EOL()
	sb.Append(z.AlignLeft("bracketBegin", kwidth, ' ')).Append(": ").Append(qb.BracketBegin).EOL()
	sb.Append(z.AlignLeft("bracketEnd", kwidth, ' ')).Append(": ").Append(qb.BracketEnd).EOL()
	// QWordRule
	if len(qb.Rules) > 0 {
		sb.Append(z.AlignLeft("rules", kwidth, ' ')).Append(": ").EOL()
		for i := 0; i < len(qb.Rules); i++ {
			rule := qb.Rules[i]
			sb.Append(z.DupChar(' ', kwidth)).Append(fmt.Sprintf(" %2d. {", i))
			sb.Append(z.DupChar(' ', kwidth)).Append(z.DupChar(' ', kwidth)).Append(fmt.Sprint("{")).EOL()
			sb.Append(z.DupChar(' ', kwidth+9)).Append(fmt.Sprintf("key    : %s", rule.Key)).EOL()
			sb.Append(z.DupChar(' ', kwidth+9)).Append(fmt.Sprintf("regex  : %s", rule.Regex.String())).EOL()
			sb.Append(z.DupChar(' ', kwidth+9)).Append(fmt.Sprintf("seg    : %s", rule.Seg)).EOL()
			sb.Append(z.DupChar(' ', kwidth+9)).Append(fmt.Sprintf("type   : %v", rule.Type)).EOL()
			sb.Append(z.DupChar(' ', kwidth+5)).Append(fmt.Sprint("}")).EOL()
		}
	}
	return sb.String()
}
Beispiel #2
0
func Test_Dup_Char(t *testing.T) {
	if z.DupChar('a', 5) != "aaaaa" {
		t.Error("DupChar 'a' 5 times != 'aaaaa'")
	}
}