
#include <stdbool.h>
#include <stdlib.h>
#include <glib.h>
#include <glib-object.h>

static gchar *
_gtk_builder_resolve_type_lazily (const gchar *name)
{
  GString *symbol_name = g_string_new ("");
  char c;
  int i;
  
  for (i = 0; name[i] != '\0'; i++)
    {
      c = name[i];
      /* skip if uppercase, first or previous is uppercase */
      if ((c == g_ascii_toupper (c) &&
           i > 0 && name[i-1] != g_ascii_toupper (name[i-1])) ||
          (i > 2 && name[i]   == g_ascii_toupper (name[i]) &&
           name[i-1] == g_ascii_toupper (name[i-1]) &&
           name[i-2] == g_ascii_toupper (name[i-2])))
        g_string_append_c (symbol_name, '_');
      g_string_append_c (symbol_name, g_ascii_tolower (c));
    }
  g_string_append (symbol_name, "_get_type");
  
  return g_string_free (symbol_name, FALSE);
}

int
main (int     argc,
      char  **argv)
{
  char *symbol;
  char  type1[] = "E2Shell";
  char  type2[] = "Me2Shell";

  g_type_init ();

  symbol = _gtk_builder_resolve_type_lazily (type1);
  g_debug ("%s for %s", symbol, type1);
  g_free (symbol);

  symbol = _gtk_builder_resolve_type_lazily (type2);
  g_debug ("%s for %s", symbol, type2);
  g_free (symbol);

  return EXIT_SUCCESS;
}
