1.Limit the max length of Network connection profile
[apps/core/preloaded/settings.git] / setting-common / src / setting-common-general-func.c
index 836a068..1d9ec67 100755 (executable)
@@ -446,6 +446,42 @@ bool is_string_belong_to_array(const char *partern, const char **array,
        return FALSE;
 }
 
+//remove sub string from a parent string
+char *remove_first_substring(const char *parent, const char *pat)
+{
+       setting_retvm_if(!parent, NULL, "NULL == parent, Exit %s with return NULL", __FUNCTION__);
+       char *str = strdup(parent); //to process the case parent pointing to const string
+       setting_retvm_if(!pat, str, "NULL == pat, Exit %s with return [%s]", __FUNCTION__, str);
+       
+       int idx = 0;
+       int str_len = safeStrLen(str);
+       int pat_len = safeStrLen(pat);
+       setting_retvm_if(pat_len > str_len, str, 
+                        "patlen[%d] > strlen[%d], Exit %s with return [%s]", 
+                        pat_len, str_len, __FUNCTION__, str);
+       char *p = NULL;
+       char *q = NULL;
+       for (; idx < str_len; idx++) {
+               if (0 == safeStrNCmp(pat, str + idx, pat_len)) {
+                       p = str + idx;
+                       q = str + idx + pat_len;
+                       while('\0' != *q)
+                       {
+                               *p = *q;
+                               p++;
+                               q++;
+                       }
+                       *p = '\0';
+                       break;
+               }
+       }
+
+       //now str keeps the result string
+       SETTING_TRACE("Exit %s with return str:%s", __FUNCTION__, str);
+       return str;
+}
+
+
 //NULL, "", "  ", "     " etc.. are all empty strings
 bool isEmptyStr(const char *str)
 {