You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
#include <config.h>
#include "str.h"
HAYSTACK_LEN. Returns a pointer to the needle found. */
char *
mm_find_reverse (const char *haystack, size_t haystack_len,
- const char *needle, size_t needle_len)
+ const char *needle, size_t needle_len)
{
int i;
for (i = haystack_len - needle_len; i >= 0; i--)
return 0;
}
+/* Compares the SIZE bytes in A to those in B, disregarding case,
+ and returns a strcmp()-type result. */
+int
+mm_case_compare (const void *a_, const void *b_, size_t size)
+{
+ const unsigned char *a = a_;
+ const unsigned char *b = b_;
+
+ while (size-- > 0)
+ {
+ unsigned char ac = toupper (*a++);
+ unsigned char bc = toupper (*b++);
+
+ if (ac != bc)
+ return ac > bc ? 1 : -1;
+ }
+
+ return 0;
+}
+
/* Compares A of length A_LEN to B of length B_LEN. The shorter
string is considered to be padded with spaces to the length of
the longer. */
dest[n - 1] = 0;
}
}
+
+/* Copies SRC to DST, truncating DST to N-1 characters if
+ necessary. Always appends a null character. */
+void
+st_trim_copy (char *dst, const char *src, size_t n)
+{
+ size_t len = strlen (src);
+ assert (n > 0);
+ if (len + 1 < n)
+ memcpy (dst, src, len + 1);
+ else
+ {
+ memcpy (dst, src, n - 1);
+ dst[n - 1] = '\0';
+ }
+}
+
+
+/* Converts each character in S to uppercase. */
+void
+st_uppercase (char *s)
+{
+ for (; *s != '\0'; s++)
+ *s = toupper ((unsigned char) *s);
+}
\f
/* Initializes ST with initial contents S. */
void