Espresso 0.0.2c
This commit is contained in:
47
lib/string.c
47
lib/string.c
@ -1,10 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <vector_extensions/sse.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef DEBUG_USE_SSE2
|
||||
#include <vector_extensions/sse.h>
|
||||
extern int32_t sse_initialized;
|
||||
#endif
|
||||
|
||||
size_t strlen(const char* str)
|
||||
{
|
||||
@ -76,10 +78,12 @@ char* strcpy(char *dst, const char *src)
|
||||
|
||||
char* strncpy(char *dest, const char *src, uint32_t n)
|
||||
{
|
||||
#ifdef DEBUG_USE_SSE2
|
||||
if (sse_initialized > 0)
|
||||
{
|
||||
return sse2_strncpy(dest, src, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t i = 0;
|
||||
for (; i < n && src[i]; ++i)
|
||||
@ -217,10 +221,12 @@ void* memset(void* dst, int c, size_t n)
|
||||
|
||||
void* memcpy(void *dst, const void *src, uint32_t n)
|
||||
{
|
||||
#ifdef DEBUG_USE_SSE2
|
||||
if (sse_initialized > 1)
|
||||
{
|
||||
return sse2_memcpy(dst, src, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
@ -234,8 +240,8 @@ void* memcpy(void *dst, const void *src, uint32_t n)
|
||||
|
||||
int32_t memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
const uint8_t *p1 = (const uint8_t *)s1;
|
||||
const uint8_t *p2 = (const uint8_t *)s2;
|
||||
const uint8_t *p1 = (const uint8_t*) s1;
|
||||
const uint8_t *p2 = (const uint8_t*) s2;
|
||||
|
||||
/*printf("p1: %i, p2: %i\n", (int32_t)*p1, (int32_t)*p2);*/
|
||||
|
||||
@ -252,10 +258,12 @@ int32_t memcmp(const void *s1, const void *s2, size_t n)
|
||||
|
||||
void* memclr(void* m_start, size_t m_count)
|
||||
{
|
||||
#ifdef DEBUG_USE_SSE2
|
||||
if (sse_initialized > 1)
|
||||
{
|
||||
return memclr_sse2(m_start, m_count);
|
||||
}
|
||||
#endif
|
||||
|
||||
return memset(m_start, '\0', (uint32_t)m_count);
|
||||
}
|
||||
@ -451,3 +459,36 @@ double atof(const char *str)
|
||||
return sign * (res + frac / frac_div);
|
||||
}
|
||||
|
||||
char* strnlstrip(const char* s)
|
||||
{
|
||||
if (!s)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* new = strdup(s);
|
||||
if (!new)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t len = strlen(new);
|
||||
|
||||
while (len > 0 && (new[len-1] == '\n' || new[len-1] == '\r'))
|
||||
{
|
||||
new[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
void strlnstripip(char* s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
|
||||
if (len > 0 && s[len-1] == '\n')
|
||||
{
|
||||
s[len-1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user