character-declarations-parser.service.ts 814 B

1234567891011121314151617181920212223242526
  1. import { Injectable } from '@angular/core';
  2. import { parse } from '.';
  3. import { Char, XMLElement } from '../../models/evt-models';
  4. import { CharParser, GlyphParser } from './character-declarations-parser';
  5. import { createParser } from './parser-models';
  6. @Injectable({
  7. providedIn: 'root',
  8. })
  9. export class CharacterDeclarationsParserService {
  10. private charParser = createParser(CharParser, parse);
  11. private glyphParser = createParser(GlyphParser, parse);
  12. parseChars(xml: XMLElement): Char[] {
  13. if (!xml) { return []; }
  14. return Array.from(xml.querySelectorAll<XMLElement>('char')).map(c => this.charParser.parse(c));
  15. }
  16. parseGlyphs(xml: XMLElement): Char[] {
  17. if (!xml) { return []; }
  18. return Array.from(xml.querySelectorAll<XMLElement>('glyph')).map(g => this.glyphParser.parse(g));
  19. }
  20. }