ADMB Documentation  11.1.2428
 All Classes Files Functions Variables Typedefs Friends Defines
string3.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: string3.cpp 2421 2014-09-28 03:59:00Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <fvar.hpp>
00008 #include <string.h>
00009 #include <stdlib.h>
00010 
00011 adstring::adstring(const char* t): clist()
00012 {
00013   size_t sz = 0;
00014   if (t)
00015   {
00016     sz = strlen(t);
00017   }
00018   allocate(sz);
00019   for (size_t i = 1; i <= sz; i++)
00020   {
00021     s[i] = t[i - 1];
00022   }
00023   s[sz + 1] = '\0';
00024 }
00025 
00026 adstring::adstring(void): clist()
00027 {
00028   size_t sz = 0;
00029   allocate(sz);
00030   s[sz + 1] = '\0';
00031 }
00032 
00033 size_t adstring::pos(const adstring& substr) const
00034 {
00035 #if (defined __ZTC__) || (defined __NDPX__)
00036   char* ptr = strstr(*this, substr);
00037 #else
00038   const char* ptr = strstr((const char*)(*this), (const char*)(substr));
00039 #endif
00040   size_t i = 0;
00041 
00042   if (ptr != NULL)
00043   {
00044     while ( (ptr != (char*)(s+i)) && (i < size()) ) i++;
00045   }
00046   return i;
00047 }
00048 
00049 size_t pos(const adstring& substr, const adstring& s)
00050 {
00051   return s.pos(substr);
00052 }