Thu Jan 8 12:08:14 CST 2009 Pekka Pessi <first.last@nokia.com>

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



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11785 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2009-02-11 16:27:51 +00:00
parent aee3e653cc
commit 54c0937433
3 changed files with 11 additions and 78 deletions

View File

@ -1 +1 @@
Wed Feb 11 10:23:36 CST 2009 Wed Feb 11 10:27:42 CST 2009

View File

@ -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;
} }

View File

@ -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;
} }