return true;
}
-static char *_strchr_with_nth(char *s, int c, int nth)
+static char *_strchr_with_nth(char *end_pointer, char *s, char *delimiters, int nth)
{
+ RETV_IF(NULL == delimiters, s);
+ RETV_IF('\0' == *delimiters, s);
+
+ int i;
char *cursor = s;
- while (*cursor) {
- if (*cursor == c)
- nth--;
+ int len_delimiters = strlen(delimiters);
+ while (*cursor) {
+ if (end_pointer <= cursor) {
+ ERR("over end");
+ return end_pointer;
+ }
+ for (i = 0; i < len_delimiters; i++) {
+ if (*cursor == delimiters[i]) {
+ nth--;
+ break;
+ }
+ }
if (nth < 0)
break;
return cursor;
}
-static char *_strrchr_with_nth(char *ori, char *s, int c, int nth)
+static char *_strrchr_with_nth(char *start_pointer, char *s, char *delimiters, int nth)
{
+ RETV_IF(NULL == delimiters, s);
+ RETV_IF('\0' == *delimiters, s);
+
+ int i;
char *cursor = s;
+ int len_delimiters = strlen(delimiters);
+
while (*cursor) {
- if (cursor <= ori) {
+ if (cursor <= start_pointer) {
/* LCOV_EXCL_START */
- ERR("over");
- return ori;
+ ERR("over start");
+ return start_pointer;
/* LCOV_EXCL_STOP */
}
-
- if (*cursor == c)
- nth--;
-
+ for (i = 0; i < len_delimiters; i++) {
+ if (*cursor == delimiters[i]) {
+ nth--;
+ break;
+ }
+ }
if (nth < 0)
break;
/* LCOV_EXCL_STOP */
}
+ /* keyword length could be changed when chosung is inserted.
+ * so length could be calculated again manually.
+ */
char *keyword_start = NULL;
snprintf(mod_temp, len_offset + 1, "%s", temp);
len_print = len_offset;
- len_print += snprintf(mod_temp + len_print, len_full - len_print,
- "%s", start_match);
+ len_print += snprintf(mod_temp + len_print, len_full - len_print, "%s", start_match);
keyword_start = mod_temp + len_print;
snprintf(mod_temp + len_print, len_keyword + 1, "%s", temp + len_offset);
len_print += len_keyword;
return mod_temp;
char *cursor = NULL;
- cursor = _strchr_with_nth(keyword_start, ' ', token_number);
+ cursor = _strchr_with_nth(mod_temp + len_full, keyword_start, " \n", token_number);
*cursor = '\0';
- cursor = _strrchr_with_nth(mod_temp, keyword_start, ' ', token_number);
+ cursor = _strrchr_with_nth(mod_temp, keyword_start, " \n", token_number);
memcpy(mod_temp, cursor, len_full);
return mod_temp;