Commit 25e45a35 authored by Pekka Pessi's avatar Pekka Pessi

memspn.c, memcspn.c: use functions from <sofia-sip/su_string.h>

darcs-hash:20090108180814-db55f-1e0d5fd329e0196950a97998b5d7b5a5bc8fcc4d.gz
parent 68c6a989
...@@ -32,50 +32,13 @@ ...@@ -32,50 +32,13 @@
#include "config.h" #include "config.h"
#include <string.h> #include <sofia-sip/su_string.h>
#include <limits.h>
size_t memcspn(const void *mem, size_t memlen,
const void *reject, size_t rejectlen);
/**Search memory for bytes not in a given set.
*
* The memcspn() function calculates the length of the memory area @a mem
* which consists entirely of bytes not in @a reject.
*
* @param mem pointer to memory area
* @param memlen size of @a mem in bytes
* @param reject pointer to table containing bytes to reject
* @param rejectlen size of @a reject table
*
* @return
* The memspn() function returns the number of bytes in the memory area @a
* which consists entirely of bytes not in @a reject.
* @par
* If @a rejectlen is 0, or @a reject is NULL, it returns @a memlen, size of
* the memory area.
*/
size_t memcspn(const void *mem, size_t memlen, size_t memcspn(const void *mem, size_t memlen,
const void *reject, size_t rejectlen) const void *reject, size_t rejectlen)
{ {
size_t i; return su_memcspn(mem, memlen, reject, rejectlen);
unsigned char const *m = mem, *r = reject;
char rejected[UCHAR_MAX + 1];
if (rejectlen == 0 || reject == 0)
return memlen;
if (mem == NULL || memlen == 0)
return 0;
memset(rejected, 0, sizeof rejected);
for (i = 0; i < rejectlen; i++)
rejected[r[i]] = 1;
for (i = 0; i < memlen; i++)
if (rejected[m[i]])
break;
return i;
} }
...@@ -34,43 +34,13 @@ ...@@ -34,43 +34,13 @@
#include "config.h" #include "config.h"
#include <string.h> #include <sofia-sip/su_string.h>
#include <limits.h>
size_t memspn(const void *mem, size_t memlen,
const void *accept, size_t acceptlen);
/**Scan memory for a set of bytes.
*
* The memspn() function calculates the length of the memory area @a mem
* which consists entirely of bytes in @a accept.
*
* @param mem pointer to memory area
* @param memlen size of @a mem in bytes
* @param accept pointer to table containing bytes to accept
* @param acceptlen size of @a accept table
*
* @return
* The memspn() function returns the number of bbytes in the memory area @a
* which consists entirely of bytes in @a accept.
*/
size_t memspn(const void *mem, size_t memlen, size_t memspn(const void *mem, size_t memlen,
const void *accept, size_t acceptlen) const void *accept, size_t acceptlen)
{ {
size_t i; return su_memspn(mem, memlen, accept, acceptlen);
unsigned char const *m = mem, *a = accept;
char accepted[UCHAR_MAX + 1];
if (mem == NULL || memlen == 0 || acceptlen == 0 || accept == NULL)
return 0;
memset(accepted, 0, sizeof accepted);
for (i = 0; i < acceptlen; i++)
accepted[a[i]] = 1;
for (i = 0; i < memlen; i++)
if (!accepted[m[i]])
break;
return i;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment