當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。