From 5a422aba704c375a307a902bafe658342e209906 Mon Sep 17 00:00:00 2001 From: scuri Date: Fri, 17 Oct 2008 06:10:15 +0000 Subject: First commit - moving from LuaForge to SourceForge --- src/im_str.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/im_str.cpp (limited to 'src/im_str.cpp') diff --git a/src/im_str.cpp b/src/im_str.cpp new file mode 100644 index 0000000..f50dcf1 --- /dev/null +++ b/src/im_str.cpp @@ -0,0 +1,67 @@ +/** \file + * \brief String Utilities + * + * See Copyright Notice in im_lib.h + * $Id: im_str.cpp,v 1.1 2008/10/17 06:10:16 scuri Exp $ + */ + + +#include +#include +#include + +#include "im_util.h" + +int imStrEqual(const char* str1, const char* str2) +{ + assert(str1); + assert(str2); + + /* While both strings are equal and not 0 */ + while (*str1 == *str2 && *str1) + { + str1++; + str2++; + } + + /* Is last char not equal ? */ + if (*str1 != *str2) + return 0; + + return 1; +} + +int imStrNLen(const char* str, int max_len) +{ + assert(str); + + const char* start_str = str; + + while(max_len && *str) + { + max_len--; + str++; + } + + return str - start_str; +} + +int imStrCheck(const void* data, int count) +{ + const char* str = (char*)data; + + if (str[count-1] == 0) + return 1; + + while(count && *str) + { + count--; + str++; + } + + if (count > 0) + return 1; + + return 0; +} + -- cgit v1.2.3