Ejemplo n.º 1
0
static void test_str_replace(void)
{
    char *value;

    value = util_str_replace("a", "uu", "foo bar baz");
    g_assert_cmpstr(value, ==, "foo buur buuz");
    g_free(value);

    value = util_str_replace("$1", "placeholder", "string with $1");
    g_assert_cmpstr(value, ==, "string with placeholder");
    g_free(value);
}
Ejemplo n.º 2
0
void seqfeat_write_header(FILE *fh, char **attrib_names, const int n_attrib) {
  int i;
  char *hdr;

  fprintf(fh, "CHR\tSTART\tEND\tSTRAND\tSCORE\tNAME");

  for(i = 0; i < n_attrib; i++) {
    hdr = g_strdup(attrib_names[i]);
    util_str_replace(hdr, '_', '.');
    util_str_uc(hdr);
    fprintf(fh, "\t%s", hdr);
    g_free(hdr);
  }
  
  fprintf(fh, "\n");
}
Ejemplo n.º 3
0
Archivo: input.c Proyecto: ckolos/vimb
static void resume_editor(GPid pid, int status, EditorData *data)
{
    char *text, *tmp;
    char *jscode;

    g_assert(pid);
    g_assert(data);
    g_assert(data->c);
    g_assert(data->file);

    if (status == 0) {
        /* get the text the editor stored */
        text = util_get_file_contents(data->file, NULL);

        if (text) {
            /* escape the text to form a valid JS string */
            /* TODO: could go into util.c maybe */
            struct search_replace {
                const char* search;
                const char* replace;
            } escapes[] = {
                {"\x01", ""},
                {"\x02", ""},
                {"\x03", ""},
                {"\x04", ""},
                {"\x05", ""},
                {"\x06", ""},
                {"\a", ""},
                {"\b", ""},
                {"\t", "\\t"},
                {"\n", "\\n"},
                {"\v", ""},
                {"\f", ""},
                {"\r", ""},
                {"\x0E", ""},
                {"\x0F", ""},
                {"\x10", ""},
                {"\x11", ""},
                {"\x12", ""},
                {"\x13", ""},
                {"\x14", ""},
                {"\x15", ""},
                {"\x16", ""},
                {"\x17", ""},
                {"\x18", ""},
                {"\x19", ""},
                {"\x1A", ""},
                {"\x1B", ""},
                {"\x1C", ""},
                {"\x1D", ""},
                {"\x1E", ""},
                {"\x1F", ""},
                {"\"", "\\\""},
                {"\x7F", ""},
                {NULL, NULL},
            };

            for(struct search_replace *i = escapes; i->search; i++) {
                tmp = util_str_replace(i->search, i->replace, text);
                g_free(text);
                text = tmp;
            }

            /* put the text back into the element */
            jscode = g_strdup_printf("vimb_input_mode_element.value=\"%s\"", text);
            ext_proxy_eval_script(data->c, jscode, NULL);

            g_free(jscode);
            g_free(text);
        }
    }

    ext_proxy_eval_script(data->c,
            "vimb_input_mode_element.disabled=false;"
            "vimb_input_mode_element.focus()", NULL);

    g_unlink(data->file);
    g_free(data->file);
    g_slice_free(EditorData, data);
    g_spawn_close_pid(pid);
}