当前位置: 首页>>代码示例>>Golang>>正文


Golang utf88.Text函数代码示例

本文整理汇总了Golang中github.com/gavingroovygrover/utf88.Text函数的典型用法代码示例。如果您正苦于以下问题:Golang Text函数的具体用法?Golang Text怎么用?Golang Text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ExampleMany

func ExampleMany() {
	var r interface{}
	var ok bool
	prt := func() {
		if ok {
			fmt.Printf("Result: %c\n", r)
		} else {
			fmt.Printf("Error: %v\n", r)
		}
	}

	letter := kern.Regexp(`\pL`)
	p := kern.Many(letter)

	t := utf88.Text("abc78d")
	u := utf88.Text("789def")

	r, ok = kern.ParseText(p, t)
	prt()
	r, ok = kern.ParseText(p, u)
	prt()

	// Output:
	// Result: [[a] [b] [c]]
	// Result: []
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:26,代码来源:example_test.go

示例2: ExampleParseText

func ExampleParseText() {
	var r interface{}
	var ok bool
	prt := func() {
		if ok {
			fmt.Printf("Result: %c\n", r)
		} else {
			fmt.Printf("Error: %v\n", r)
		}
	}

	p := kern.Symbol(utf88.Codepoint('a'))

	t := utf88.Text("abc")
	r, ok = kern.ParseText(p, t)
	prt()

	u := utf88.Text("defg")
	r, ok = kern.ParseText(p, u)
	prt()

	// Output:
	// Result: a
	// Error: Unexpected d input.
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:25,代码来源:example_test.go

示例3: ExampleOption

func ExampleOption() {
	var r interface{}
	var ok bool
	prt := func() {
		if ok {
			fmt.Printf("Result: %s\n", utf88.Surr(r.(utf88.Text)))
		} else {
			fmt.Printf("Error: %v\n", r)
		}
	}

	letter := kern.Regexp(`\pL`)
	p := kern.Option(utf88.Text("None."), letter)

	t := utf88.Text("abc")
	u := utf88.Text("789")

	r, ok = kern.ParseText(p, t)
	prt()
	r, ok = kern.ParseText(p, u)
	prt()

	// Output:
	// Result: a
	// Result: None.
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:26,代码来源:example_test.go

示例4: ExampleSepBy

func ExampleSepBy() {
	var r interface{}
	var ok bool
	prt := func() {
		if ok {
			fmt.Printf("Result: %c\n", r)
		} else {
			fmt.Printf("Error: %v\n", r)
		}
	}

	letter := kern.Regexp(`\pL`)
	punc := kern.Regexp(`\pP`)
	p := kern.SepBy(punc, letter)

	t := utf88.Text("a;b:c789")
	u := utf88.Text(";789")

	r, ok = kern.ParseText(p, t)
	prt()
	r, ok = kern.ParseText(p, u)
	prt()

	// Output:
	// Result: [[a] [b] [c]]
	// Result: []
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:27,代码来源:example_test.go

示例5: ExampleAlt

func ExampleAlt() {
	var r interface{}
	var ok bool
	prt := func() {
		if ok {
			fmt.Printf("Result: %s\n", utf88.Surr(r.(utf88.Text)))
		} else {
			fmt.Printf("Error: %v\n", r)
		}
	}

	lower := kern.Regexp(`\p{Ll}`)
	upper := kern.Regexp(`\p{Lu}`)
	digit := kern.Regexp(`\p{Nd}`)

	p := kern.Alt(lower, digit)
	q := kern.Alt(lower, digit, upper)

	t := utf88.Text("7ef")
	u := utf88.Text(";ef")

	r, ok = kern.ParseText(p, t)
	prt()

	r, ok = kern.ParseText(p, u)
	prt()

	r, ok = kern.ParseText(q, t)
	prt()

	// Output:
	// Result: 7
	// Error: No alternatives selected.
	// Result: 7
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:35,代码来源:example_test.go

示例6: ExampleNoneOf

func ExampleNoneOf() {
	p := kern.NoneOf(utf88.Text("xyz\n\t"))

	t := utf88.Text("abcde")
	r, ok := kern.ParseText(p, t)
	if ok {
		fmt.Printf("Result: %s\n", utf88.Sur(r.(utf88.Codepoint)))
	} else {
		fmt.Printf("Error: %v\n", r)
	}

	// Output:
	// Result: a
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:14,代码来源:example_test.go

示例7: ExampleToken

func ExampleToken() {
	p := kern.Token(utf88.Text("ab"))

	t := utf88.Text("abc")
	r, ok := kern.ParseText(p, t)
	if ok {
		fmt.Printf("Result: %s\n", utf88.Surr(r.(utf88.Text)))
	} else {
		fmt.Printf("Error: %v\n", r)
	}

	// Output:
	// Result: ab
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:14,代码来源:example_test.go

示例8: ExampleFail

func ExampleFail() {
	p := kern.Fail(utf88.Text("Some Failure"))

	t := utf88.Text("anything")
	r, ok := kern.ParseText(p, t)
	if ok {
		fmt.Printf("Result: %v\n", r)
	} else {
		fmt.Printf("Error: %v\n", r)
	}

	// Output:
	// Error: Some Failure
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:14,代码来源:example_test.go

示例9: ExampleTry

func ExampleTry() {
	p := kern.Flatten(kern.Regexp(`\pL`), kern.Regexp(`\pL`))
	q := kern.Flatten(kern.Regexp(`\pL`), kern.Regexp(`\pN`))

	t := utf88.Text("a7bcde")

	var r interface{}
	var ok bool
	prt := func() {
		if ok {
			fmt.Printf("Result: %s\n", utf88.Surr(r.(utf88.Text)))
		} else {
			fmt.Printf("Error: %v\n", r)
		}
	}

	r, ok = kern.ParseText(kern.Alt(p, q), t)
	prt()

	r, ok = kern.ParseText(kern.Alt(kern.Try(p), q), t)
	prt()

	// Output:
	// Error: Unexpected 7 input.
	// Result: a7
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:26,代码来源:example_test.go

示例10: ExampleBind

func ExampleBind() {
	var r interface{}
	var ok bool
	prt := func() {
		if ok {
			fmt.Printf("Result: %s\n", r)
		} else {
			fmt.Printf("Error: %v\n", r)
		}
	}

	lower := kern.Regexp(`\p{Ll}`)
	intNum := kern.Regexp(`\p{Nd}*`)

	p := kern.Bind(lower, func(c interface{}) kern.Parser {
		return kern.Bind(intNum, func(d interface{}) kern.Parser {
			return kern.Bind(lower, func(e interface{}) kern.Parser {
				return kern.Return(utf88.Surr(c.(utf88.Text)) + "," +
					utf88.Surr(d.(utf88.Text)) + "," +
					utf88.Surr(e.(utf88.Text)))
			})
		})
	})

	t := utf88.Text("e789fg")
	r, ok = kern.ParseText(p, t)
	prt()

	// Output:
	// Result: e,789,f
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:31,代码来源:example_test.go

示例11: ExampleAsk

func ExampleAsk() {
	letter := kern.Regexp(`\pL`)
	digit := kern.Regexp(`\p{Nd}`)

	p := kern.Ask(kern.Collect(digit, letter), utf88.Text("digit,letter"))

	t := utf88.Text(";efg")
	r, ok := kern.ParseText(p, t)
	if ok {
		fmt.Printf("Result: %s\n", utf88.Sur(r.(utf88.Codepoint)))
	} else {
		fmt.Printf("Error: %v\n", r)
	}

	// Output:
	// Error: Unexpected ; input. Expecting digit,letter
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:17,代码来源:example_test.go

示例12: ExamplePrint

func ExamplePrint() {
	p := Alt(digit,
		Alt(punct,
			Print(u8.Text("Just before the letter:"), letter)))
	parseStr(p, "defg")

	// Output:
	// Just before the letter: "defg"/0, ok, empty
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:9,代码来源:logger_test.go

示例13: ExamplePrintState

func ExamplePrintState() {
	p := Alt(digit,
		Alt(punct,
			Bind(PrintState(u8.Text("Just before the letter:")),
				func(x interface{}) (p Parser) { return letter })))
	parseStr(p, "defg")

	// Output:
	// Just before the letter: "defg"/0, ok, empty
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:10,代码来源:logger_test.go

示例14: TestInputAndPosition

//================================================================================
func TestInputAndPosition(t *testing.T) {
	ts.LogAsserts("InputAndPosition", t, func(tt *ts.T) {
		letter := Regexp(`\pL`)
		p1 := Flatten(letter, letter, letter)

		tt.AssertEqual(parseStr(SeqRight(SetInput(u8.Desur("Hi!")), GetInput), "abcdefg"),
			PState{input: "Hi!", pos: 0, value: u8.Desur("Hi!"), empty: true, ok: true})
		tt.AssertEqual(parseStr(SeqRight(letter, GetInput), "abcdefg"),
			PState{input: "bcdefg", pos: 1, value: u8.Desur("bcdefg"), ok: true})

		tt.AssertEqual(parseStr(SeqRight(SetPosition(100), GetPosition), "abcdefg"),
			PState{input: "abcdefg", pos: 100, value: uint64(100), empty: true, ok: true})

		tt.AssertEqual(parseStr(SeqRight(SetInputAndPosition(InputAndPosition{u8.Desur("Hi there!"), 5}), GetInputAndPosition), "abcdefg"),
			PState{input: "Hi there!", pos: 5, value: InputAndPosition{u8.Desur("Hi there!"), 5}, empty: true, ok: true})

		tt.AssertEqual(parseStr(Collect(p1, SeqRight(SetInput(u8.Desur("XYZ")), p1)), "ABCDEFG"),
			PState{input: "", pos: 6, value: arrText("ABC", "XYZ"), ok: true}) //TODO: what should pos be?
		tt.AssertEqual(parseStr(Collect(p1, SeqRight(SetInput(u8.Desur("XYZ")), p1)), "ABC"),
			PState{input: "", pos: 6, value: arrText("ABC", "XYZ"), ok: true}) //TODO: ditto

		tt.AssertEqual(parseStr(Collect(p1), "ABC"),
			PState{input: "", pos: 3, value: arrText("ABC"), ok: true})

		p2 := SeqRight(Skip(SetInput(u8.Text("XY0")), SetPosition(0)), p1)
		tt.AssertEqual(parseStr(Collect(p1, p2), "ABC"),
			PState{input: "0", pos: 2, value: nil, error: makeUnexpInp("0")})

		p3 := SeqRight(Skip(SetInput(u8.Text("WXYZ")), SetPosition(0)), GetPosition)
		tt.AssertEqual(parseStr(SeqRight(p1, p3), "ABC"),
			PState{input: "WXYZ", pos: 0, value: uint64(0), ok: true})

		p4 := SeqRight(SetInput(u8.Text("XYZ")), GetInput)
		tt.AssertEqual(parseStr(SeqRight(p1, p4), "ABC"),
			PState{input: "XYZ", pos: 3, value: u8.Text("XYZ"), ok: true})

		tt.AssertEqual(parseStr(Collect(p1, SeqRight(SetInputAndPosition(InputAndPosition{u8.Desur("XYZ"), 2}), p1)), "ABCDEFG"), //posn changed from 3 to 2...
			PState{input: "", pos: 5, value: arrText("ABC", "XYZ"), ok: true}) //...so posn is 5 instead of 6

	})
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:42,代码来源:state_test.go

示例15: ExampleReturn

func ExampleReturn() {
	p := kern.Return(1234567890)

	t := utf88.Text("anything")
	r, ok := kern.ParseText(p, t)
	if ok {
		fmt.Printf("Result: %v\n", r)
	} else {
		fmt.Printf("Error: %v\n", r)
	}

	// Output:
	// Result: 1234567890
}
开发者ID:gavingroovygrover,项目名称:kern,代码行数:14,代码来源:example_test.go


注:本文中的github.com/gavingroovygrover/utf88.Text函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。