summaryrefslogtreecommitdiff
path: root/upb/def.c
diff options
context:
space:
mode:
Diffstat (limited to 'upb/def.c')
-rw-r--r--upb/def.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/upb/def.c b/upb/def.c
index 0c694f8..a1dc192 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -1,6 +1,7 @@
#include "upb/def.h"
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "upb/structdefs.int.h"
@@ -721,6 +722,35 @@ const char *upb_fielddef_name(const upb_fielddef *f) {
return upb_def_fullname(upb_fielddef_upcast(f));
}
+bool upb_fielddef_getjsonname(const upb_fielddef *f, char *buf) {
+ const char *name = upb_fielddef_name(f);
+ size_t i, j;
+ bool ucase_next = false;
+
+ if (!name) return false;
+
+ /* Implement the transformation as described in the spec:
+ * 1. upper case all letters after an underscore.
+ * 2. remove all underscores.
+ */
+ for (i = 0, j = 0; name[i]; i++) {
+ if (name[i] == '_') {
+ ucase_next = true;
+ continue;
+ }
+
+ if (ucase_next) {
+ buf[j++] = toupper(name[i]);
+ ucase_next = false;
+ } else {
+ buf[j++] = name[i];
+ }
+ }
+
+ buf[j] = '\0';
+ return true;
+}
+
const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) {
return f->msg_is_symbolic ? NULL : f->msg.def;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback