]> mj.ucw.cz Git - libucw.git/commitdiff
Added consts to functions for matching of prefixes and suffixes.
authorPavel Charvat <pchar@ucw.cz>
Wed, 8 Feb 2012 13:58:46 +0000 (14:58 +0100)
committerPavel Charvat <pchar@ucw.cz>
Wed, 8 Feb 2012 13:58:46 +0000 (14:58 +0100)
ucw/str-fix.c
ucw/string.h

index deb128e89d623f7e35ac1a1ccb816de55fc73fa7..a220f6217eaa197a5ab9e89353ea7e7e60dee6ff 100644 (file)
 #include <string.h>
 
 int
-str_has_prefix(char *str, char *prefix)
+str_has_prefix(const char *str, const char *prefix)
 {
   size_t pxlen = strlen(prefix);
   return !strncmp(str, prefix, pxlen);
 }
 
 int
-str_has_suffix(char *str, char *suffix)
+str_has_suffix(const char *str, const char *suffix)
 {
   size_t sxlen = strlen(suffix);
   size_t len = strlen(str);
@@ -32,7 +32,7 @@ str_has_suffix(char *str, char *suffix)
 }
 
 int
-str_hier_prefix(char *str, char *prefix, uns sep)
+str_hier_prefix(const char *str, const char *prefix, uns sep)
 {
   while (*str && *prefix)
     {
@@ -54,10 +54,10 @@ str_hier_prefix(char *str, char *prefix, uns sep)
 }
 
 int
-str_hier_suffix(char *str, char *suffix, uns sep)
+str_hier_suffix(const char *str, const char *suffix, uns sep)
 {
-  char *st = str + strlen(str);
-  char *sx = suffix + strlen(suffix);
+  const char *st = str + strlen(str);
+  const char *sx = suffix + strlen(suffix);
   while (st > str && sx > suffix)
     {
       size_t sl=0, pl=0;
index 2583a3574434ec7222c7caf0fc970f8bd7e1b04a..b5faa9ac2afcd7cec12ea155f803d656cebd691f 100644 (file)
@@ -92,8 +92,8 @@ const char *hex_to_mem(byte *dest, const char *src, uns max_bytes, uns flags);
 
 /* str-fix.c */
 
-int str_has_prefix(char *str, char *prefix);           /** Tests if @str starts with @prefix. **/
-int str_has_suffix(char *str, char *suffix);           /** Tests if @str ends with @suffix. **/
+int str_has_prefix(const char *str, const char *prefix); /** Tests if @str starts with @prefix. **/
+int str_has_suffix(const char *str, const char *suffix); /** Tests if @str ends with @suffix. **/
 
 /**
  * Let @str and @prefix be hierarchical names with components separated by
@@ -110,7 +110,7 @@ int str_has_suffix(char *str, char *suffix);                /** Tests if @str ends with @suffi
  * - "/" is a prefix,
  * - "" is a prefix.
  **/
-int str_hier_prefix(char *str, char *prefix, uns sep);
-int str_hier_suffix(char *str, char *suffix, uns sep); /** Like @str_hier_prefix(), but for suffixes. **/
+int str_hier_prefix(const char *str, const char *prefix, uns sep);
+int str_hier_suffix(const char *str, const char *suffix, uns sep); /** Like @str_hier_prefix(), but for suffixes. **/
 
 #endif