src/lib/common.c 1.150

1.150 2010/05/29 22:24:53 kent
Adding some const to string function parameters to better work with C standard library code as callbacks.
Index: src/lib/common.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/common.c,v
retrieving revision 1.149
retrieving revision 1.150
diff -b -B -U 4 -r1.149 -r1.150
--- src/lib/common.c	29 May 2010 20:23:41 -0000	1.149
+++ src/lib/common.c	29 May 2010 22:24:53 -0000	1.150
@@ -19,9 +19,9 @@
 memcpy(newPt, pt, size);
 return newPt;
 }
 
-static char *cloneStringZExt(char *s, int size, int copySize)
+static char *cloneStringZExt(const char *s, int size, int copySize)
 /* Make a zero terminated copy of string in memory */
 {
 char *d = needMem(copySize+1);
 copySize = min(size,copySize);
@@ -29,15 +29,15 @@
 d[copySize] = 0;
 return d;
 }
 
-char *cloneStringZ(char *s, int size)
+char *cloneStringZ(const char *s, int size)
 /* Make a zero terminated copy of string in memory */
 {
 return cloneStringZExt(s, strlen(s), size);
 }
 
-char *cloneString(char *s)
+char *cloneString(const char *s)
 /* Make copy of string in dynamic memory */
 {
 int size = 0;
 if (s == NULL)
@@ -616,8 +616,19 @@
 const struct slName *b = *((struct slName **)vb);
 return strcmp(a->name, b->name);
 }
 
+int slNameCmpStringsWithEmbeddedNumbers(const void *va, const void *vb)
+/* Compare strings such as gene names that may have embedded numbers,
+ * so that bmp4a comes before bmp14a */
+{
+const struct slName *a = *((struct slName **)va);
+const struct slName *b = *((struct slName **)vb);
+return cmpStringsWithEmbeddedNumbers(a->name, b->name);
+}
+
+
+
 void slNameSort(struct slName **pList)
 /* Sort slName list. */
 {
 slSort(pList, slNameCmp);
@@ -1385,9 +1396,9 @@
    ++count;
 return count;
 }
 
-int countLeadingDigits(char *s)
+int countLeadingDigits(const char *s)
 /* Return number of leading digits in s */
 {
 int count = 0;
 while (isdigit(*s))
@@ -1397,9 +1408,9 @@
    }
 return count;
 }
 
-int countLeadingNondigits(char *s)
+int countLeadingNondigits(const char *s)
 /* Count number of leading non-digit characters in s. */
 {
 int count = 0;
 char c;
@@ -1411,9 +1422,9 @@
    }
 return count;
 }
 
-int cmpStringsWithEmbeddedNumbers(char *a, char *b)
+int cmpStringsWithEmbeddedNumbers(const char *a, const char *b)
 /* Compare strings such as gene names that may have embedded numbers,
  * so that bmp4a comes before bmp14a */
 {
 for (;;)
@@ -1452,9 +1463,9 @@
        }
    }
 }
 
-int cmpWordsWithEmbeddedNumbers(char *a, char *b)
+int cmpWordsWithEmbeddedNumbers(const char *a, const char *b)
 /* Case insensitive version of cmpStringsWithEmbeddedNumbers. */
 {
 char *A = cloneString(a);
 char *B = cloneString(b);