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


C++ UnicodeSet::none方法代码示例

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


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

示例1: charClass

void NFABuilder::charClass(const ParseNode& n) {
  const UnicodeSet uset(n.Set.CodePoints & Enc->validCodePoints());

  if (uset.none()) {
    if (!n.Set.Breakout.Additive || n.Set.Breakout.Bytes.none()) {
      THROW_RUNTIME_ERROR_WITH_CLEAN_OUTPUT(
        "intersection of character class with " << Enc->name() << " is empty"
      );
    }

    // the breakout bytes are the entire character class
    NFA::VertexDescriptor v = Fsm->addVertex();
    (*Fsm)[v].Trans = Fsm->TransFac->getSmallest(n.Set.Breakout.Bytes);
    TempFrag.initFull(v, n);
  }
  else {
    // convert the code point set into collapsed encoding ranges
    TempEncRanges.clear();
    Enc->write(uset, TempEncRanges);

    // handle the breakout bytes
    if (n.Set.Breakout.Bytes.any()) {
      if (n.Set.Breakout.Additive) {
        // add breakout bytes to encodings
        if (TempEncRanges[0].size() == 1) {
          TempEncRanges[0][0] |= n.Set.Breakout.Bytes;
        }
        else {
          TempEncRanges.emplace_back(1);
          TempEncRanges.back()[0] = n.Set.Breakout.Bytes;
        }
      }
      else {
        // subtract breakout bytes from encodings
        if (TempEncRanges[0].size() == 1) {
          TempEncRanges[0][0] &= ~n.Set.Breakout.Bytes;
          if (TempEncRanges[0][0].none()) {
            TempEncRanges.erase(TempEncRanges.begin());

            // ensure that at least one initial byte remains
            if (TempEncRanges.empty()) {
              THROW_RUNTIME_ERROR_WITH_CLEAN_OUTPUT(
                "intersection of character class with " << Enc->name()
                                                        << " is empty"
              );
            }
          }
        }
      }
    }

    ByteSet bs;
    TempFrag.reset(n);

    // create a graph from the collapsed ranges
    for (const std::vector<ByteSet>& enc : TempEncRanges) {
      NFA::VertexDescriptor head, tail;

      //
      // find a suffix of enc in this fragment
      //

      int32_t b = enc.size()-1;

      // find a match for the last transition
      const auto oi = std::find_if(
        TempFrag.OutList.begin(), TempFrag.OutList.end(),
        [&](const std::pair<NFA::VertexDescriptor,uint32_t>& p) {
          return (*Fsm)[p.first].Trans->getBytes(bs) == enc[b];
        }
      );

      if (oi != TempFrag.OutList.end()) {
        // match, use this tail
        tail = oi->first;

        // walk backwards until a transition mismatch
        for (--b; b >= 0; --b) {
          head = 0;
          for (const NFA::VertexDescriptor h : Fsm->inVertices(tail)) {
            (*Fsm)[h].Trans->getBytes(bs);
            if (bs == enc[b]) {
              tail = head = h;
              break;
            }
            head = 0;
          }

          if (!head) {
            // tail is as far back as we can go
            break;
          }
        }
      }
      else {
        // no match, build a new tail
        tail = Fsm->addVertex();
        (*Fsm)[tail].Trans = Fsm->TransFac->getSmallest(enc[b--]);
        TempFrag.OutList.emplace_back(tail, 0);
      }
//.........这里部分代码省略.........
开发者ID:jonstewart,项目名称:liblightgrep,代码行数:101,代码来源:nfabuilder.cpp


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