mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added strnstr function. Included stdint.h from bx.h
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#ifndef __BX_H__
|
||||
#define __BX_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "macros.h"
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#ifndef __BX_FLOAT4_SSE_H__
|
||||
#define __BX_FLOAT4_SSE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <emmintrin.h> // __m128i
|
||||
#if defined(__SSE4_1__)
|
||||
# include <smmintrin.h>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#ifndef __BX_FLOAT4_T_H__
|
||||
#define __BX_FLOAT4_T_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bx.h"
|
||||
|
||||
#define BX_FLOAT4_INLINE BX_FORCE_INLINE
|
||||
|
||||
@@ -23,40 +23,77 @@ namespace bx
|
||||
#endif // BX_COMPILER_
|
||||
}
|
||||
|
||||
/// Find substring in string. Limit search to _size.
|
||||
inline const char* strnstr(const char* _str, const char* _find, size_t _size)
|
||||
{
|
||||
char first = *_find;
|
||||
if ('\0' == first)
|
||||
{
|
||||
return _str;
|
||||
}
|
||||
|
||||
const char* cmp = _find + 1;
|
||||
size_t len = strlen(cmp);
|
||||
do
|
||||
{
|
||||
for (char match = *_str++; match != first && 0 < _size; match = *_str++, --_size)
|
||||
{
|
||||
if ('\0' == match)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == _size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} while (0 != strncmp(_str, cmp, len) );
|
||||
|
||||
return --_str;
|
||||
}
|
||||
|
||||
/// Find new line. Returns pointer after new line terminator.
|
||||
inline const char* strnl(const char* _str)
|
||||
{
|
||||
const char* eol = strstr(_str, "\n\r");
|
||||
if (NULL != eol)
|
||||
for (; '\0' != *_str; _str += strnlen(_str, 1024) )
|
||||
{
|
||||
return eol + 2;
|
||||
const char* eol = strnstr(_str, "\n\r", 1024);
|
||||
if (NULL != eol)
|
||||
{
|
||||
return eol + 2;
|
||||
}
|
||||
|
||||
eol = strnstr(_str, "\n", 1024);
|
||||
if (NULL != eol)
|
||||
{
|
||||
return eol + 1;
|
||||
}
|
||||
}
|
||||
|
||||
eol = strstr(_str, "\n");
|
||||
if (NULL != eol)
|
||||
{
|
||||
return eol + 1;
|
||||
}
|
||||
|
||||
return eol + strlen(_str);
|
||||
return _str;
|
||||
}
|
||||
|
||||
/// Find end of line. Retuns pointer to new line terminator.
|
||||
inline const char* streol(const char* _str)
|
||||
{
|
||||
const char* eol = strstr(_str, "\n\r");
|
||||
if (NULL != eol)
|
||||
for (; '\0' != *_str; _str += strnlen(_str, 1024) )
|
||||
{
|
||||
return eol;
|
||||
const char* eol = strnstr(_str, "\n\r", 1024);
|
||||
if (NULL != eol)
|
||||
{
|
||||
return eol;
|
||||
}
|
||||
|
||||
eol = strnstr(_str, "\n", 1024);
|
||||
if (NULL != eol)
|
||||
{
|
||||
return eol;
|
||||
}
|
||||
}
|
||||
|
||||
eol = strstr(_str, "\n");
|
||||
if (NULL != eol)
|
||||
{
|
||||
return eol;
|
||||
}
|
||||
|
||||
return eol + strlen(_str);
|
||||
return _str;
|
||||
}
|
||||
|
||||
/// Skip whitespace.
|
||||
|
||||
Reference in New Issue
Block a user