Statistics
| Revision:

root / trunk / src / tools99 / string3.cpp @ 914

History | View | Annotate | Download (911 Bytes)

1
/*
2
 * $Id: string3.cpp 914 2013-04-03 17:26:06Z jsibert $
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California 
6
 */
7
#include <fvar.hpp>
8
#include <string.h>
9
#include <stdlib.h>
10

    
11
adstring::adstring(const char * t) : clist()
12
{
13
  unsigned int sz = 0;
14
  if (t)
15
  {
16
    sz = strlen (t);
17
  }
18
  allocate(sz);
19
  for (unsigned int i = 1; i <= sz; i++)
20
  {
21
    s[i] = t[i - 1];
22
  }
23
  s[sz + 1] = '\0';
24
}
25

    
26
adstring::adstring(void) : clist()
27
{
28
  unsigned int sz = 0;
29
  allocate(sz);
30
  s[sz + 1] = '\0';
31
}
32

    
33
int adstring::pos(const adstring& substr) const
34
{
35
#if (defined __ZTC__) || (defined __NDPX__)
36
  char* ptr = strstr(*this, substr);
37
#else
38
  const char * ptr = strstr((const char *)(*this), (const char *)(substr));
39
#endif
40
  unsigned int i = 0;
41

    
42
  if (ptr != NULL)
43
  {
44
    while ( (ptr != (char*)(s+i)) && (i < size()) ) i++;
45
  }
46
  return i;
47
}
48

    
49
int pos(const adstring& substr, const adstring& s)
50
{
51
  return(s.pos(substr));
52
}