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


Golang Regexp.String方法代码示例

本文整理汇总了Golang中regexp/syntax.Regexp.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Regexp.String方法的具体用法?Golang Regexp.String怎么用?Golang Regexp.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在regexp/syntax.Regexp的用法示例。


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

示例1: createRepeatingGenerator

// Returns a generator that will run the generator for r's sub-expression [min, max] times.
func createRepeatingGenerator(regexp *syntax.Regexp, genArgs *GeneratorArgs, min, max int) (*internalGenerator, error) {
	if err := enforceSingleSub(regexp); err != nil {
		return nil, err
	}

	generator, err := newGenerator(regexp.Sub[0], genArgs)
	if err != nil {
		return nil, generatorError(err, "failed to create generator for subexpression: /%s/", regexp)
	}

	if min == noBound {
		min = int(genArgs.MinUnboundedRepeatCount)
	}
	if max == noBound {
		max = int(genArgs.MaxUnboundedRepeatCount)
	}

	return &internalGenerator{regexp.String(), func() string {
		n := min + genArgs.rng.Intn(max-min+1)

		var result bytes.Buffer
		for i := 0; i < n; i++ {
			result.WriteString(generator.Generate())
		}
		return result.String()
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:28,代码来源:internal_generator.go

示例2: opConcat

func opConcat(regexp *syntax.Regexp, genArgs *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpConcat)

	generators, err := newGenerators(regexp.Sub, genArgs)
	if err != nil {
		return nil, generatorError(err, "error creating generators for concat pattern /%s/", regexp)
	}

	return &internalGenerator{regexp.String(), func() string {
		return genArgs.Executor.Execute(generators)
	}}, nil
}
开发者ID:Psiphon-Inc,项目名称:goregen,代码行数:12,代码来源:internal_generator.go

示例3: opAlternate

func opAlternate(regexp *syntax.Regexp, genArgs *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpAlternate)

	generators, err := newGenerators(regexp.Sub, genArgs)
	if err != nil {
		return nil, generatorError(err, "error creating generators for alternate pattern /%s/", regexp)
	}

	numGens := len(generators)

	return &internalGenerator{regexp.String(), func() string {
		i := genArgs.rng.Intn(numGens)
		generator := generators[i]
		return generator.Generate()
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:16,代码来源:internal_generator.go

示例4: opConcat

func opConcat(regexp *syntax.Regexp, genArgs *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpConcat)

	generators, err := newGenerators(regexp.Sub, genArgs)
	if err != nil {
		return nil, generatorError(err, "error creating generators for concat pattern /%s/", regexp)
	}

	return &internalGenerator{regexp.String(), func() string {
		var result bytes.Buffer
		for _, generator := range generators {
			result.WriteString(generator.Generate())
		}
		return result.String()
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:16,代码来源:internal_generator.go

示例5: createRepeatingGenerator

// Returns a generator that will run the generator for r's sub-expression [min, max] times.
func createRepeatingGenerator(regexp *syntax.Regexp, genArgs *GeneratorArgs, min int, max int) (*internalGenerator, error) {
	if err := enforceSingleSub(regexp); err != nil {
		return nil, err
	}

	generator, err := newGenerator(regexp.Sub[0], genArgs)
	if err != nil {
		return nil, generatorError(err, "failed to create generator for subexpression: /%s/", regexp)
	}

	if max < 0 {
		max = maxUpperBound
	}

	return &internalGenerator{regexp.String(), func() string {
		n := min + genArgs.rng.Intn(max-min+1)
		return executeGeneratorRepeatedly(genArgs.Executor, generator, n)
	}}, nil
}
开发者ID:Psiphon-Inc,项目名称:goregen,代码行数:20,代码来源:internal_generator.go

示例6: opCapture

func opCapture(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpCapture)

	if err := enforceSingleSub(regexp); err != nil {
		return nil, err
	}

	groupRegexp := regexp.Sub[0]
	generator, err := newGenerator(groupRegexp, args)
	if err != nil {
		return nil, err
	}

	// Group indices are 0-based, but index 0 is the whole expression.
	index := regexp.Cap - 1

	return &internalGenerator{regexp.String(), func() string {
		return args.CaptureGroupHandler(index, regexp.Name, groupRegexp, generator, args)
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:20,代码来源:internal_generator.go

示例7: CompileSyntax

// CompileSyntax is like Compile but takes a syntax tree as input.
func CompileSyntax(ast *syntax.Regexp) (*Regexp, error) {
	return compileSyntax(ast, ast.String(), true)
}
开发者ID:alexflint,项目名称:go-restructure,代码行数:4,代码来源:regexp.go

示例8: noop

// Generator that does nothing.
func noop(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) {
	return &internalGenerator{regexp.String(), func() string {
		return ""
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:6,代码来源:internal_generator.go

示例9: opCharClass

// Handles syntax.ClassNL because the parser uses that flag to generate character
// classes that respect it.
func opCharClass(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpCharClass)
	charClass := parseCharClass(regexp.Rune)
	return createCharClassGenerator(regexp.String(), charClass, args)
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:7,代码来源:internal_generator.go

示例10: opAnyCharNotNl

func opAnyCharNotNl(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpAnyCharNotNL)
	charClass := newCharClass(1, rune(math.MaxInt32))
	return createCharClassGenerator(regexp.String(), charClass, args)
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:5,代码来源:internal_generator.go

示例11: opAnyChar

func opAnyChar(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpAnyChar)
	return &internalGenerator{regexp.String(), func() string {
		return runesToString(rune(args.rng.Int31()))
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:6,代码来源:internal_generator.go

示例12: opLiteral

func opLiteral(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpLiteral)
	return &internalGenerator{regexp.String(), func() string {
		return runesToString(regexp.Rune...)
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:6,代码来源:internal_generator.go

示例13: opEmptyMatch

func opEmptyMatch(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) {
	enforceOp(regexp, syntax.OpEmptyMatch)
	return &internalGenerator{regexp.String(), func() string {
		return ""
	}}, nil
}
开发者ID:zach-klippenstein,项目名称:memebot,代码行数:6,代码来源:internal_generator.go


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