~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/str/trim.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/function/str/trim.h>
23
23
 
24
 
namespace drizzled
25
 
{
26
 
 
27
24
String *Item_func_ltrim::val_str(String *str)
28
25
{
29
26
  assert(fixed == 1);
94
91
 
95
92
  ptr= (char*) res->ptr();
96
93
  end= ptr+res->length();
 
94
#ifdef USE_MB
97
95
  char *p=ptr;
98
96
  register uint32_t l;
 
97
#endif
99
98
  if (remove_length == 1)
100
99
  {
101
100
    char chr=(*remove_str)[0];
 
101
#ifdef USE_MB
102
102
    if (use_mb(res->charset()))
103
103
    {
104
104
      while (ptr < end)
105
105
      {
106
 
        if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l,p=ptr;
107
 
        else ++ptr;
 
106
        if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l,p=ptr;
 
107
        else ++ptr;
108
108
      }
109
109
      ptr=p;
110
110
    }
 
111
#endif
111
112
    while (ptr != end  && end[-1] == chr)
112
113
      end--;
113
114
  }
114
115
  else
115
116
  {
116
117
    const char *r_ptr=remove_str->ptr();
 
118
#ifdef USE_MB
117
119
    if (use_mb(res->charset()))
118
120
    {
119
 
loop:
 
121
  loop:
120
122
      while (ptr + remove_length < end)
121
123
      {
122
 
        if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l;
123
 
        else ++ptr;
 
124
        if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l;
 
125
        else ++ptr;
124
126
      }
125
127
      if (ptr + remove_length == end && !memcmp(ptr,r_ptr,remove_length))
126
128
      {
127
 
        end-=remove_length;
128
 
        ptr=p;
129
 
        goto loop;
 
129
        end-=remove_length;
 
130
        ptr=p;
 
131
        goto loop;
130
132
      }
131
133
    }
132
134
    else
 
135
#endif /* USE_MB */
133
136
    {
134
137
      while (ptr + remove_length <= end &&
135
 
          !memcmp(end-remove_length, r_ptr, remove_length))
136
 
        end-=remove_length;
 
138
             !memcmp(end-remove_length, r_ptr, remove_length))
 
139
        end-=remove_length;
137
140
    }
138
141
  }
139
142
  if (end == res->ptr()+res->length())
172
175
  r_ptr= remove_str->ptr();
173
176
  while (ptr+remove_length <= end && !memcmp(ptr,r_ptr,remove_length))
174
177
    ptr+=remove_length;
 
178
#ifdef USE_MB
175
179
  if (use_mb(res->charset()))
176
180
  {
177
181
    char *p=ptr;
191
195
    ptr=p;
192
196
  }
193
197
  else
 
198
#endif /* USE_MB */
194
199
  {
195
200
    while (ptr + remove_length <= end &&
196
201
           !memcmp(end-remove_length,r_ptr,remove_length))
236
241
  args[0]->print(str, query_type);
237
242
  str->append(')');
238
243
}
239
 
 
240
 
} /* namespace drizzled */