ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
string3.cpp
Go to the documentation of this file.
1 
8 #include <adstring.hpp>
9 
10 adstring::adstring(const char* t): clist()
11 {
12  size_t sz = t ? strlen(t) : 0;
13  allocate(sz);
14  for (size_t i = 1; i <= sz; i++)
15  {
16  s[i] = (unsigned char)t[i - 1];
17  }
18  s[sz + 1] = '\0';
19 }
20 
21 adstring::adstring(const unsigned char* t): clist()
22 {
23  size_t sz = t ? strlen((const char*)t) : 0;
24  allocate(sz);
25  for (size_t i = 1; i <= sz; i++)
26  {
27  s[i] = t[i - 1];
28  }
29  s[sz + 1] = '\0';
30 }
31 
34 {
35  size_t sz = 0;
36  allocate(sz);
37  s[sz + 1] = '\0';
38 }
39 
40 size_t adstring::pos(const adstring& substr) const
41 {
42 #if (defined __ZTC__) || (defined __NDPX__)
43  char* ptr = strstr(*this, substr);
44 #else
45  const char* ptr = strstr((const char*)(*this), (const char*)(substr));
46 #endif
47  size_t i = 0;
48 
49  if (ptr != NULL)
50  {
51  while ( (ptr != (char*)(s+i)) && (i < size()) ) i++;
52  }
53  return i;
54 }
55 
56 size_t pos(const adstring& substr, const adstring& s)
57 {
58  return s.pos(substr);
59 }
size_t size() const
Definition: string.cpp:58
void allocate(const size_t sz)
Definition: string.cpp:12
size_t pos(const adstring &substr) const
Definition: string3.cpp:40
adstring()
Default constructor.
Definition: string3.cpp:33
Definition: clist.h:43
size_t pos(const adstring &substr, const adstring &s)
Definition: string3.cpp:56
unsigned char * s
Definition: adstring.hpp:76