summaryrefslogtreecommitdiff
path: root/src/duk-libdom.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-10-08 16:04:56 +0100
committerVincent Sanders <vince@kyllikki.org>2015-10-08 16:04:56 +0100
commite170ee146791061f4fcc9523a901cdc1c6c8525b (patch)
tree658a5b13168d59d68e8493f180d23cb898cb5d90 /src/duk-libdom.c
parentc2c05535f6a758d58fd3d7e995ef320778a9eb01 (diff)
downloadnsgenbind-e170ee146791061f4fcc9523a901cdc1c6c8525b.tar.gz
nsgenbind-e170ee146791061f4fcc9523a901cdc1c6c8525b.tar.bz2
Split out idl to c name conversion
Diffstat (limited to 'src/duk-libdom.c')
-rw-r--r--src/duk-libdom.c65
1 files changed, 1 insertions, 64 deletions
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index fcd55da..a0e8eb5 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -49,70 +49,7 @@ static char *get_prototype_name(const char *interface_name)
}
-/**
- * Generate a C class name for the interface.
- *
- * The IDL interface names are camelcase and not similar to libdom naming so it
- * is necessary to convert them to a libdom compatible class name. This
- * implementation is simple ASCII capable only and cannot cope with multibyte
- * codepoints.
- *
- * The algorithm is:
- * - copy characters to output lowering their case
- * - if the previous character in the input name was uppercase and the current
- * one is lowercase insert an underscore before the *previous* character.
- */
-static char *gen_class_name(struct ir_entry *interfacee)
-{
- const char *inc;
- char *outc;
- char *name;
- int wasupper;
-
- /* enpty strings are a bad idea */
- if ((interfacee->name == NULL) ||
- (interfacee->name[0] == 0)) {
- return NULL;
- }
- /* allocate result buffer as twice the input length as thats the
- * absolute worst case.
- */
- name = calloc(2, strlen(interfacee->name));
-
- outc = name;
- inc = interfacee->name;
- wasupper = 0;
-
- /* first character handled separately as inserting a leading underscore
- * is undesirable
- */
- *outc++ = tolower(*inc++);
- /* copy input to output */
- while (*inc != 0) {
- /* ugly hack as html IDL is always prefixed uppercase and needs
- * an underscore there
- */
- if ((inc == (interfacee->name + 4)) &&
- (interfacee->name[0] == 'H') &&
- (interfacee->name[1] == 'T') &&
- (interfacee->name[2] == 'M') &&
- (interfacee->name[3] == 'L') &&
- (islower(inc[1]) == 0)) {
- *outc++ = '_';
- }
- if ((islower(*inc) != 0) && (wasupper != 0)) {
- *outc = *(outc - 1);
- *(outc - 1) = '_';
- outc++;
- wasupper = 0;
- } else {
- wasupper = isupper(*inc);
- }
- *outc++ = tolower(*inc++);
- }
- return name;
-}
static FILE *open_header(struct ir *ir, const char *name)
@@ -641,7 +578,7 @@ int duk_libdom_output(struct ir *ir)
irentry = ir->entries + idx;
/* compute class name */
- irentry->class_name = gen_class_name(irentry);
+ irentry->class_name = gen_idl2c_name(irentry->name);
if (irentry->class_name != NULL) {
int ifacenamelen;