Drizzled Public API Documentation

mf_arr_appstr.cc

00001 /* Copyright (C) 2007 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #include <config.h>
00017 
00018 #include <drizzled/internal/my_sys.h>
00019 #include <drizzled/internal/m_string.h>
00020 
00021 namespace drizzled
00022 {
00023 namespace internal
00024 {
00025 
00039 bool array_append_string_unique(const char *str,
00040                                    const char **array, size_t size)
00041 {
00042   const char **p;
00043   /* end points at the terminating NULL element */
00044   const char **end= array + size - 1;
00045   assert(*end == NULL);
00046 
00047   for (p= array; *p; ++p)
00048   {
00049     if (strcmp(*p, str) == 0)
00050       break;
00051   }
00052   if (p >= end)
00053     return true;                               /* Array is full */
00054 
00055   assert(*p == NULL || strcmp(*p, str) == 0);
00056 
00057   while (*(p + 1))
00058   {
00059     *p= *(p + 1);
00060     ++p;
00061   }
00062 
00063   assert(p < end);
00064   *p= str;
00065 
00066   return false;                                 /* Success */
00067 }
00068 
00069 } /* namespace internal */
00070 } /* namespace drizzled */