~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/internal/mf_arr_appstr.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2007 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include <config.h>
17
 
 
18
 
#include <drizzled/internal/my_sys.h>
19
 
#include <drizzled/internal/m_string.h>
20
 
 
21
 
namespace drizzled
22
 
{
23
 
namespace internal
24
 
{
25
 
 
26
 
/**
27
 
  Append str to array, or move to the end if it already exists
28
 
 
29
 
  @param str    String to be appended
30
 
  @param array  The array, terminated by a NULL element, all unused elements
31
 
                pre-initialized to NULL
32
 
  @param size   Size of the array; array must be terminated by a NULL
33
 
                pointer, so can hold size - 1 elements
34
 
 
35
 
  @retval false  Success
36
 
  @retval true   Failure, array is full
37
 
*/
38
 
 
39
 
bool array_append_string_unique(const char *str,
40
 
                                   const char **array, size_t size)
41
 
{
42
 
  const char **p;
43
 
  /* end points at the terminating NULL element */
44
 
  const char **end= array + size - 1;
45
 
  assert(*end == NULL);
46
 
 
47
 
  for (p= array; *p; ++p)
48
 
  {
49
 
    if (strcmp(*p, str) == 0)
50
 
      break;
51
 
  }
52
 
  if (p >= end)
53
 
    return true;                               /* Array is full */
54
 
 
55
 
  assert(*p == NULL || strcmp(*p, str) == 0);
56
 
 
57
 
  while (*(p + 1))
58
 
  {
59
 
    *p= *(p + 1);
60
 
    ++p;
61
 
  }
62
 
 
63
 
  assert(p < end);
64
 
  *p= str;
65
 
 
66
 
  return false;                                 /* Success */
67
 
}
68
 
 
69
 
} /* namespace internal */
70
 
} /* namespace drizzled */