Revision 1105

trunk/src/tools99/string1.cpp (revision 1105)
1
/*
2
 * $Id$
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California 
6
 */
7
#include <fvar.hpp>
8
#include <string.h>
9
#include <stdlib.h>
10
#include "admb_messages.h"
11

  
12
adstring adstring::operator()(int i, int j)
13
{
14
  if (i < 1 || i > (int) shape->size())
15
  {
16
    ADMB_ARRAY_BOUNDS_ERROR("First index out of bounds", "adstring adstring::operator()(int i, int j)", 1, shape->size(), i);
17
  }
18
  if (i > j)
19
  {
20
    ADMB_ARRAY_BOUNDS_ERROR("First index must be less than or equal to second index", "adstring adstring::operator()(int i, int j)", 1, shape->size(), j);
21
  }
22
  if (j > (int) shape->size())
23
  {
24
    ADMB_ARRAY_BOUNDS_ERROR("Second index out of bounds", "adstring adstring::operator()(int i, int j)", 1, shape->size(), j);
25
  }
26
  adstring tmp(1, size_t(j - i + 1));
27
  for (int ii = i; ii <= j; ii++)
28
  {
29
    tmp(ii - i + 1) = (* this) (ii);
30
  }
31
  return (tmp);
32
}
33

  
34
#if defined (USE_CONST)
35
adstring adstring::operator()(int i, int j) const
36
{
37
  if (i < 1 || i > (int) shape->size())
38
  {
39
    ADMB_ARRAY_BOUNDS_ERROR("First index out of bounds", "adstring adstring::operator()(int i, int j)", 1, shape->size(), i);
40
  }
41
  if (i > j)
42
  {
43
    ADMB_ARRAY_BOUNDS_ERROR("First index must be less than or equal to second index", "adstring adstring::operator()(int i, int j)", 1, shape->size(), j);
44
  }
45
  if (j > (int) shape->size())
46
  {
47
    ADMB_ARRAY_BOUNDS_ERROR("Second index out of bounds", "adstring adstring::operator()(int i, int j)", 1, shape->size(), j);
48
  }
49
  adstring tmp(1, size_t(j - i + 1));
50
  for (int ii = i; ii <= j; ii++)
51
  {
52
    tmp(ii - i + 1) = (* this) (ii);
53
  }
54
  return (tmp);
55
}
56
#endif
57
 
58
adstring& adstring::operator=(const adstring & t)
59
{
60
  if (s != t.s)
61
  {
62
    int sz = t.size ();
63
    shape->size() = t.size();
64
    delete [] ++s;
65
    s=new unsigned char[sz+1];
66
    s--;
67
    int size = t.size();
68
    for (int i = 1; i <= size; i++)
69
    {
70
      s[i] = t[i];
71
    }
72
    s[sz + 1] = '\0';
73
    adstring * tmp = (adstring *) this->next;
74
    while (tmp != this)
75
    {
76
      tmp->shape = shape;
77
      tmp->s = s;
78
      tmp = (adstring *) tmp->next;
79
    }
80
  }
81
  return (* this);
82
}
83

  
84
void adstring::realloc(const char * t)
85
{
86
  int sz = strlen(t);
87
  shape->size() = strlen(t);
88
  delete [] ++s;
89
  s=new unsigned char[sz+1];
90
  strcpy((char*)(s),t);
91
  s--;
92
  adstring * tmp = (adstring *) this->next;
93
  while (tmp != this)
94
  {
95
    tmp->shape = shape;
96
    tmp->s = s;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff