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


TypeScript util.escapeRegExp函数代码示例

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


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

示例1: buildMatcher

/*
 * Builds a regexp that matches the given `pieces`
 *
 * It returns:
 * - the `regexp` to be used to match the generated code,
 * - the `groups` which maps `$...$` identifier to their position in the regexp matches.
 */
function buildMatcher(pieces: (string | RegExp)[]): {regexp: RegExp, groups: Map<string, number>} {
  const results: string[] = [];
  let first = true;
  let group = 0;

  const groups = new Map<string, number>();
  for (const piece of pieces) {
    if (!first)
      results.push(`\\s${typeof piece === 'string' && IDENT_LIKE.test(piece) ? '+' : '*'}`);
    first = false;
    if (typeof piece === 'string') {
      if (MATCHING_IDENT.test(piece)) {
        const matchGroup = groups.get(piece);
        if (!matchGroup) {
          results.push('(' + IDENTIFIER.source + ')');
          const newGroup = ++group;
          groups.set(piece, newGroup);
        } else {
          results.push(`\\${matchGroup}`);
        }
      } else {
        results.push(escapeRegExp(piece));
      }
    } else {
      results.push('(?:' + piece.source + ')');
    }
  }
  return {
    regexp: new RegExp(results.join('')),
    groups,
  };
}
开发者ID:hulkike,项目名称:angular,代码行数:39,代码来源:mock_compile.ts

示例2: it

      it('should throw on unknown xtb tags', () => {
        const XTB = `<what></what>`;

        expect(() => {
          loadAsMap(XTB);
        }).toThrowError(new RegExp(escapeRegExp(`Unexpected tag ("[ERROR ->]<what></what>")`)));
      });
开发者ID:JohnnyQQQQ,项目名称:angular,代码行数:7,代码来源:xtb_spec.ts

示例3: it

        it('should throw when a placeholder misses an id attribute', () => {
          const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file source-language="en" datatype="plaintext" original="ng2.template">
    <body>
      <trans-unit id="deadbeef" datatype="html">
        <source/>
        <target><x/></target>
      </trans-unit>
    </body>
  </file>
</xliff>`;

          expect(() => {
            loadAsMap(XLIFF);
          }).toThrowError(new RegExp(escapeRegExp(`<x> misses the "id" attribute`)));
        });
开发者ID:cooperka,项目名称:angular,代码行数:17,代码来源:xliff_spec.ts

示例4: it

      it('should throw when a placeholder misses an id attribute', () => {
        const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
  <file original="ng.template" id="ngi18n">
    <unit id="deadbeef">
      <segment>
        <source/>
        <target><ph/></target>
      </segment>
    </unit>
  </file>
</xliff>`;

        expect(() => {
          loadAsMap(XLIFF);
        }).toThrowError(new RegExp(escapeRegExp(`<ph> misses the "equiv" attribute`)));
      });
开发者ID:cooperka,项目名称:angular,代码行数:17,代码来源:xliff2_spec.ts


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