4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <glib/gprintf.h>
23 #include "cal_internal.h"
25 char* cal_strdup(const char *src)
32 static gint _sort_cb(gconstpointer a, gconstpointer b)
34 return GPOINTER_TO_INT(a) < GPOINTER_TO_INT(b) ? -1 : 1;
37 char* cal_strdup_with_sort(const char *src)
39 RETV_IF(NULL == src, NULL);
42 t = g_strsplit_set(src, " ,", -1);
45 ERR("g_strsplit_set() Fail");
50 len_t = g_strv_length(t);
60 for (i = 0; i < len_t; i++) {
61 if (NULL == t[i] || '\0' == *t[i])
66 ERR("Invalid parameter[%s]", t[i]);
70 if (g_list_find(l, GINT_TO_POINTER(num))) {
72 ERR("Find same data[%s]", t[i]);
76 l = g_list_append(l, GINT_TO_POINTER(num));
78 l = g_list_sort(l, _sort_cb);
80 int len_src = strlen(src) +1;
81 char *out_str = calloc(len_src, sizeof(char));
82 if (NULL == out_str) {
92 cursor = g_list_first(l);
94 len += snprintf(out_str +len, len_src -len, "%d,", GPOINTER_TO_INT(cursor->data));
95 cursor = g_list_next(cursor);
98 out_str[len -1] = '\0';