/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import { AttributeType } from "../sinaNexTS/sina/AttributeType"; import { SearchResultSetItemAttribute } from "../sinaNexTS/sina/SearchResultSetItemAttribute"; import { SearchResultSetItemAttributeBase } from "../sinaNexTS/sina/SearchResultSetItemAttributeBase"; import { SearchResultSetItemAttributeGroup } from "../sinaNexTS/sina/SearchResultSetItemAttributeGroup"; import { SearchResultSetItemAttributeGroupMembership } from "../sinaNexTS/sina/SearchResultSetItemAttributeGroupMembership"; export function parseTemplate(template: string): { type: "string" | "placeholder"; value: string }[] { const parts: { type: "string" | "placeholder"; value: string }[] = []; const regex = /\{(\w+)\}/g; let pos = 0; let match; while ((match = regex.exec(template)) !== null) { if (match.index > pos) { parts.push({ type: "string", value: template.substring(pos, match.index) }); } parts.push({ type: "placeholder", value: match[1] }); pos = regex.lastIndex; } if (pos < template.length) { parts.push({ type: "string", value: template.substring(pos) }); } return parts; } export function createSubAttributeMap( attribute: SearchResultSetItemAttributeGroup ): Record { const attributeByNameInGroup = {}; attribute.attributes.map((attributeMembership: SearchResultSetItemAttributeGroupMembership) => { const nameInGroup = attributeMembership.metadata.nameInGroup; const attribute = attributeMembership.attribute; attributeByNameInGroup[nameInGroup] = attribute; }); return attributeByNameInGroup; } export function isIcon(attribute: SearchResultSetItemAttribute): boolean { return typeof attribute.value === "string" && attribute.value.startsWith("sap-icon://"); } export function isText(attribute: SearchResultSetItemAttribute): boolean { const isImageLike = isIcon(attribute) || attribute.metadata.type === AttributeType.ImageUrl; return !isImageLike; }