mirror of
https://github.com/labwc/labwc.git
synced 2025-11-05 13:29:58 -05:00
39 lines
669 B
C
39 lines
669 B
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include "common/nodename.h"
|
|
|
|
char *
|
|
nodename(xmlNode *node, char *buf, int len)
|
|
{
|
|
if (!node || !node->name) {
|
|
return NULL;
|
|
}
|
|
|
|
/* Ignore superflous 'text.' in node name */
|
|
if (node->parent && !strcmp((char *)node->name, "text")) {
|
|
node = node->parent;
|
|
}
|
|
|
|
char *p = buf;
|
|
p[--len] = 0;
|
|
for (;;) {
|
|
const char *name = (char *)node->name;
|
|
char c;
|
|
while ((c = *name++) != 0) {
|
|
*p++ = tolower(c);
|
|
if (!--len) {
|
|
return buf;
|
|
}
|
|
}
|
|
*p = 0;
|
|
node = node->parent;
|
|
if (!node || !node->name) {
|
|
return buf;
|
|
}
|
|
*p++ = '.';
|
|
if (!--len) {
|
|
return buf;
|
|
}
|
|
}
|
|
}
|