std::vector<std::string> split(const std::string &str, const std::string ®) { //@todo replace with regex once we switch to gcc 4.9 std_parsed_string_t parsed=nullptr; std_parse_string(&parsed,str.c_str(),reg.c_str()); size_t ix = 0; std::vector<std::string> _lst; const char * head = nullptr; while ((head=std_parse_string_next(parsed,&ix))!=nullptr) { _lst.push_back(head); } std_parse_string_free(parsed); return std::move(_lst); }
/** * Create gpio pin group, parse pins from pin group and populate gpio pin group * object * param[in] gpio_group - pointer to gpio pin group object * param[in] pin_group_str - pin group string with gpio pins seperated by comma * for ex: 1,2 * @todo take range of gpio pins ex: 1-4 * return none */ static void create_gpio_group(sdi_gpio_group_t *gpio_group, const char *pin_group_str) { char delimiter = ','; size_t count = 0; const char *token = NULL; std_parsed_string_t handle; if (std_parse_string(&handle, pin_group_str, &delimiter)) { count = std_parse_string_num_tokens(handle); STD_ASSERT(count >= MIN_NUMBER_OF_PINS_IN_GROUP); gpio_group->gpio_count = (uint_t)count; gpio_group->gpio_group = (uint_t *) calloc(sizeof(uint_t), gpio_group->gpio_count); STD_ASSERT(gpio_group != NULL); gpio_group->gpio_file_tbl = (sdi_gpio_file_fd_tbl_t **) calloc(sizeof(sdi_gpio_file_fd_tbl_t *), gpio_group->gpio_count); STD_ASSERT(gpio_group->gpio_file_tbl != NULL); count = 0; while((token = std_parse_string_next(handle,&count))) { gpio_group->gpio_group[count-1] = (uint_t) strtoul(token, NULL, 0); gpio_group->gpio_file_tbl[count-1] = (sdi_gpio_file_fd_tbl_t *) calloc(sizeof(sdi_gpio_file_fd_tbl_t), 1); STD_ASSERT(gpio_group->gpio_file_tbl[count-1] != NULL); } std_parse_string_free(handle); } }