summaryrefslogtreecommitdiff
path: root/im/src/im_str.cpp
blob: f50dcf1c3a4bb146de6a0191b9d317acf8d60e75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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 <stdlib.h>
#include <memory.h>
#include <assert.h>

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