Merge "version update:0.13.66" into tizen_3.0 accepted/tizen/3.0/ivi/20161228.091419 accepted/tizen/3.0/mobile/20161228.091343 accepted/tizen/3.0/wearable/20161228.091405 submit/tizen_3.0/20161227.110143
authorJongkyu Koo <jk.koo@samsung.com>
Tue, 27 Dec 2016 10:59:53 +0000 (02:59 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 27 Dec 2016 10:59:53 +0000 (02:59 -0800)
server/ctsvc_utils_string.c

index 275c606..2245134 100644 (file)
@@ -484,13 +484,26 @@ static bool _get_modified_number(char *temp, char *keyword, int *out_len_keyword
        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;
 
@@ -499,20 +512,28 @@ static char *_strchr_with_nth(char *s, int c, int nth)
        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;
 
@@ -591,11 +612,13 @@ char *ctsvc_utils_get_modified_str(char *temp, bool is_snippet, const char *keyw
                /* 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;
@@ -606,9 +629,9 @@ char *ctsvc_utils_get_modified_str(char *temp, bool is_snippet, const char *keyw
                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;