mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 00:22:51 -06:00
added function abstractName from the API
This commit is contained in:
@@ -65,3 +65,9 @@ void pgf_free(PgfPGF *pgf)
|
||||
{
|
||||
delete pgf;
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfText *pgf_abstract_name(PgfPGF* pgf)
|
||||
{
|
||||
return textdup(&(*pgf->abstract.name));
|
||||
}
|
||||
|
||||
@@ -37,6 +37,12 @@
|
||||
|
||||
#endif
|
||||
|
||||
/* A generic structure to store text. The last field is variable length */
|
||||
typedef struct {
|
||||
size_t size;
|
||||
char text[];
|
||||
} PgfText;
|
||||
|
||||
typedef struct PgfPGF PgfPGF;
|
||||
|
||||
/* All functions that may fail take a reference to a PgfExn structure.
|
||||
|
||||
@@ -17,3 +17,39 @@ int textcmp(PgfText &t1, PgfText &t2)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
PGF_INTERNAL
|
||||
PgfText* textdup(PgfText *t1)
|
||||
{
|
||||
PgfText *t2 = (PgfText *) malloc(sizeof(PgfText) + t1->size + 1);
|
||||
t2->size = t1->size;
|
||||
memcpy(t2->text, t1->text, t1->size+1);
|
||||
return t2;
|
||||
}
|
||||
|
||||
PGF_API uint32_t
|
||||
pgf_utf8_decode(const uint8_t** src_inout)
|
||||
{
|
||||
const uint8_t* src = *src_inout;
|
||||
uint8_t c = src[0];
|
||||
if (c < 0x80) {
|
||||
*src_inout = src + 1;
|
||||
return c;
|
||||
}
|
||||
size_t len = (c < 0xe0 ? 1 :
|
||||
c < 0xf0 ? 2 :
|
||||
c < 0xf8 ? 3 :
|
||||
c < 0xfc ? 4 :
|
||||
5
|
||||
);
|
||||
uint64_t mask = 0x0103070F1f7f;
|
||||
uint32_t u = c & (mask >> (len * 8));
|
||||
for (size_t i = 1; i <= len; i++) {
|
||||
c = src[i];
|
||||
u = u << 6 | (c & 0x3f);
|
||||
}
|
||||
*src_inout = &src[len + 1];
|
||||
return u;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#ifndef TEXT_H
|
||||
#define TEXT_H
|
||||
|
||||
typedef struct {
|
||||
size_t size;
|
||||
char text[];
|
||||
} PgfText;
|
||||
|
||||
PGF_INTERNAL_DECL
|
||||
int textcmp(PgfText &t1, PgfText &t2);
|
||||
|
||||
PGF_INTERNAL_DECL
|
||||
PgfText* textdup(PgfText *t1);
|
||||
|
||||
PGF_API uint32_t
|
||||
pgf_utf8_decode(const uint8_t** src_inout);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user