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