MCPcopy Create free account
hub / github.com/fontsource/fontsource / parseSlicingStrategy

Function parseSlicingStrategy

packages/core/src/subsets.ts:36–59  ·  view source on GitHub ↗
(fileContent: string)

Source from the content-addressed store, hash-verified

34 * Parses the text protobuf format for slicing strategies.
35 */
36const parseSlicingStrategy = (fileContent: string): number[][] => {
37 const slices: number[][] = [];
38 let currentSlice: number[] | null = null;
39
40 for (const line of fileContent.split('\n')) {
41 const trimmedLine = line.trim();
42 if (trimmedLine === 'subsets {') {
43 if (currentSlice) slices.push(currentSlice);
44 currentSlice = [];
45 } else if (trimmedLine.startsWith('codepoints:')) {
46 const codepointMatch = trimmedLine.match(/codepoints: (\d+)/);
47 if (codepointMatch && currentSlice) {
48 currentSlice.push(parseInt(codepointMatch[1] ?? '0', 10));
49 }
50 } else if (trimmedLine === '}') {
51 if (currentSlice && currentSlice.length > 0) {
52 slices.push(currentSlice);
53 currentSlice = null;
54 }
55 }
56 }
57 // The files list subsets in reverse priority order. We want to process them in priority order.
58 return slices.reverse();
59};
60
61/**
62 * Generates the complete subset data map from raw file contents provided in the config.

Callers 1

generateSubsetDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected