ADMB Documentation  11.1.2397
 All Classes Files Functions Variables Typedefs Friends Defines
string3.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: string3.cpp 2319 2014-09-11 01:10:01Z 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 #ifndef OPT_LIB
00012   #include <cassert>
00013   #include <climits>
00014 #endif
00015 
00016 adstring::adstring(const char* t): clist()
00017 {
00018   unsigned int sz = 0;
00019   if (t)
00020   {
00021 #ifdef OPT_LIB
00022     sz = (unsigned int)strlen(t);
00023 #else
00024     size_t len = strlen(t);
00025     assert(len <= (size_t)UINT_MAX);
00026     sz = (unsigned int)len;
00027 #endif
00028   }
00029   allocate(sz);
00030   for (unsigned int i = 1; i <= sz; i++)
00031   {
00032     s[i] = t[i - 1];
00033   }
00034   s[sz + 1] = '\0';
00035 }
00036 
00037 adstring::adstring(void): clist()
00038 {
00039   unsigned int sz = 0;
00040   allocate(sz);
00041   s[sz + 1] = '\0';
00042 }
00043 
00044 int adstring::pos(const adstring& substr) const
00045 {
00046 #if (defined __ZTC__) || (defined __NDPX__)
00047   char* ptr = strstr(*this, substr);
00048 #else
00049   const char* ptr = strstr((const char*)(*this), (const char*)(substr));
00050 #endif
00051   unsigned int i = 0;
00052 
00053   if (ptr != NULL)
00054   {
00055     while ( (ptr != (char*)(s+i)) && (i < size()) ) i++;
00056   }
00057   return i;
00058 }
00059 
00060 int pos(const adstring& substr, const adstring& s)
00061 {
00062   return(s.pos(substr));
00063 }