diff options
author | Vincent Sanders <vince@kyllikki.org> | 2015-10-08 16:04:56 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-10-08 16:04:56 +0100 |
commit | e170ee146791061f4fcc9523a901cdc1c6c8525b (patch) | |
tree | 658a5b13168d59d68e8493f180d23cb898cb5d90 /src/duk-libdom-common.c | |
parent | c2c05535f6a758d58fd3d7e995ef320778a9eb01 (diff) | |
download | nsgenbind-e170ee146791061f4fcc9523a901cdc1c6c8525b.tar.gz nsgenbind-e170ee146791061f4fcc9523a901cdc1c6c8525b.tar.bz2 |
Split out idl to c name conversion
Diffstat (limited to 'src/duk-libdom-common.c')
-rw-r--r-- | src/duk-libdom-common.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/duk-libdom-common.c b/src/duk-libdom-common.c index fb97fe3..ce3ebe9 100644 --- a/src/duk-libdom-common.c +++ b/src/duk-libdom-common.c @@ -170,3 +170,56 @@ int output_method_cdata(FILE* outf, return 0; } + +/* exported interface documented in duk-libdom.h */ +char *gen_idl2c_name(const char *idlname) +{ + const char *inc; + char *outc; + char *name; + int wasupper; + + /* enpty strings are a bad idea */ + if ((idlname == NULL) || (idlname[0] == 0)) { + return NULL; + } + + /* allocate result buffer as twice the input length as thats the + * absolute worst case. + */ + name = calloc(2, strlen(idlname)); + + outc = name; + inc = idlname; + 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 == (idlname + 4)) && + (idlname[0] == 'H') && + (idlname[1] == 'T') && + (idlname[2] == 'M') && + (idlname[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; +} |