mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
26 lines
784 B
TypeScript
26 lines
784 B
TypeScript
/** An Objective-C class symbol leaf, optionally qualified by a provider namespace. */
|
|
export const objcClassSymbol = (
|
|
name: string,
|
|
):
|
|
| {
|
|
readonly name: string;
|
|
readonly symbol: string;
|
|
readonly metaclass: boolean;
|
|
}
|
|
| undefined => {
|
|
const leaf = objcSymbolLeaf(name);
|
|
const match = /^_?(OBJC_(META)?CLASS_\$_([^\s]+))$/u.exec(leaf);
|
|
if (match?.[1] === undefined || match[3] === undefined) return undefined;
|
|
return {
|
|
name: match[3],
|
|
symbol: match[1],
|
|
metaclass: match[2] !== undefined,
|
|
};
|
|
};
|
|
|
|
/** Preserve the exact runtime symbol leaf after a provider namespace. */
|
|
export const objcSymbolLeaf = (name: string): string => {
|
|
const namespace = name.lastIndexOf("::");
|
|
return namespace < 0 ? name : name.slice(namespace + 2);
|
|
};
|