static void     test_string_find_char(void)
{
  const char    *string;

  ASSERT(string_find_char("", '\0') == NULL);
  ASSERT(string_find_char("", 'z') == NULL);
  ASSERT(string_find_char("hello", 'z') == NULL);
  string = "hello";
  ASSERT(string_find_char(string, 'h') == string);
  ASSERT(string_find_char(string, 'o') == string + 4);
}
Example #2
0
void            string_reader_skip(t_string_reader *reader,
                                   const char *chars_to_skip)
{
  t_position    prev;
  char          c;

  while (string_reader_has_more(reader))
    {
      prev = reader->position;
      c = string_reader_next(reader);
      if (!string_find_char(chars_to_skip, c))
        {
          reader->position = prev;
          break;
        }
    }
}
Example #3
0
void do_admin_command(caValue* input, caValue* reply)
{
    // Identify the command
    int first_space = string_find_char(input, 0, ' ');
    if (first_space == -1)
        first_space = string_length(input);

    Value command;
    string_slice(input, 0, first_space, &command);

    set_null(reply);

    if (equals_string(&command, "add_lib_path")) {
        //List args;
        //parse_tokens_as_argument_list(&tokens, &args);

    } else if (equals_string(&command, "file")) {

        List args;
        parse_string_as_argument_list(input, &args);
        do_file_command(&args, reply);

    } else if (equals_string(&command, "echo")) {

        List args;
        parse_string_as_argument_list(input, &args);
        do_echo(&args, reply);

    } else if (equals_string(&command, "write_block")) {

        int nextSpace = string_find_char(input, first_space+1, ' ');
        if (nextSpace == -1) {
            set_string(reply, "Syntax error, not enough arguments");
            return;
        }
        
        Value blockName;
        string_slice(input, first_space+1, nextSpace, &blockName);

        Value contents;
        string_slice(input, nextSpace+1, -1, &contents);

        do_write_block(&blockName, &contents, reply);

    } else if (equals_string(&command, "update_file")) {

        int nextSpace = string_find_char(input, first_space+1, ' ');
        if (nextSpace == -1) {
            set_string(reply, "Syntax error, not enough arguments");
            return;
        }
        
        Value filename;
        string_slice(input, first_space+1, nextSpace, &filename);

        Value contents;
        string_slice(input, nextSpace+1, -1, &contents);

        do_update_file(&filename, &contents, reply);

    } else if (equals_string(&command, "source_repro")) {
        List args;
        parse_string_as_argument_list(input, &args);
        Block block;
        load_script(&block, as_cstring(args[1]));
        std::cout << get_block_source_text(&block);
    } else if (equals_string(&command, "dump_stats")) {

        perf_stats_dump();
        std::cout << ":done" << std::endl;

    } else {

        set_string(reply, "Unrecognized command: ");
        string_append(reply, &command);
    }
}