-static
-char *remove_underscores_from_field_ref(const char *field_ref)
-{
- const char *in_ch;
- char *out_ch;
- char *ret;
- enum {
- UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE,
- UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE,
- } state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE;
-
- BT_ASSERT(field_ref);
- ret = calloc(strlen(field_ref) + 1, 1);
- if (!ret) {
- BT_LOGE("Failed to allocate a string: size=%zu",
- strlen(field_ref) + 1);
- goto end;
- }
-
- in_ch = field_ref;
- out_ch = ret;
-
- while (*in_ch != '\0') {
- switch (*in_ch) {
- case ' ':
- case '\t':
- /* Remove whitespace */
- in_ch++;
- continue;
- case '_':
- if (state == UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE) {
- in_ch++;
- state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE;
- continue;
- }
-
- goto copy;
- case '.':
- state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE;
- goto copy;
- default:
- state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE;
- goto copy;
- }
-
-copy:
- *out_ch = *in_ch;
- in_ch++;
- out_ch++;
- }
-
-end:
- return ret;
-}
-