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


Golang Iter.Discard方法代码示例

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


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

示例1: searchOnce

// searchOnce tries to match the pattern s.p at the text position i. s.buf needs
// to be filled with collation elements of the first segment, where n is the
// number of source bytes consumed for this segment. It will return the end
// position of the match or -1.
func (p *Pattern) searchOnce(it *colltab.Iter) (end int) {
	var pLevel [4]int

	m := p.m
	for {
		k := 0
		for ; k < it.N; k++ {
			if v := it.Elems[k].Primary(); v > 0 {
				if w, ok := p.next(&pLevel[0], colltab.Elem.Primary); !ok || v != w {
					return -1
				}
			}

			if !m.ignoreDiacritics {
				if v := it.Elems[k].Secondary(); v > 0 {
					if w, ok := p.next(&pLevel[1], colltab.Elem.Secondary); !ok || v != w {
						return -1
					}
				}
			} else if it.Elems[k].Primary() == 0 {
				// We ignore tertiary values of collation elements of the
				// secondary level.
				continue
			}

			// TODO: distinguish between case and width. This will be easier to
			// implement after we moved to the new collation implementation.
			if !m.ignoreWidth && !m.ignoreCase {
				if v := it.Elems[k].Tertiary(); v > 0 {
					if w, ok := p.next(&pLevel[2], tertiary); !ok || int(v) != w {
						return -1
					}
				}
			}
			// TODO: check quaternary weight
		}
		it.Discard() // Remove the current segment from the buffer.

		// Check for completion.
		switch {
		// If any of these cases match, we are not at the end.
		case pLevel[0] < len(p.ce):
		case !m.ignoreDiacritics && pLevel[1] < len(p.ce):
		case !(m.ignoreWidth || m.ignoreCase) && pLevel[2] < len(p.ce):
		default:
			// At this point, both the segment and pattern has matched fully.
			// However, the segment may still be have trailing modifiers.
			// This can be verified by another call to next.
			end = it.End()
			if it.Next() && it.Elems[0].Primary() == 0 {
				if !m.ignoreDiacritics {
					return -1
				}
				end = it.End()
			}
			return end
		}

		// Fill the buffer with the next batch of collation elements.
		if !it.Next() {
			return -1
		}
	}
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:68,代码来源:pattern.go


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