~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.cc

  • Committer: Lee Bieber
  • Date: 2011-03-13 16:37:38 UTC
  • mfrom: (2227.4.18 session2)
  • Revision ID: kalebral@gmail.com-20110313163738-7ti21zk40o2xi3ew
Merge Olaf - Refactor Session

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* This file is originally from the mysql distribution. Coded by monty */
17
17
 
18
 
#include "config.h"
 
18
#include <config.h>
19
19
 
20
 
#include "drizzled/internal/my_sys.h"
21
 
#include "drizzled/internal/m_string.h"
22
 
#include "drizzled/charset.h"
23
 
#include "drizzled/global_charset_info.h"
 
20
#include <drizzled/internal/my_sys.h>
 
21
#include <drizzled/internal/m_string.h>
 
22
#include <drizzled/charset.h>
 
23
#include <drizzled/global_charset_info.h>
24
24
 
25
25
#include <algorithm>
26
26
 
27
 
#include "drizzled/sql_string.h"
 
27
#include <drizzled/sql_string.h>
28
28
 
29
29
using namespace std;
30
30
 
219
219
  return false;
220
220
}
221
221
 
 
222
bool String::copy(const std::string& arg, const CHARSET_INFO * const cs)        // Allocate new string
 
223
{
 
224
  if (alloc(arg.size()))
 
225
    return true;
 
226
 
 
227
  if ((str_length= arg.size()))
 
228
    memcpy(Ptr, arg.c_str(), arg.size());
 
229
 
 
230
  Ptr[arg.size()]= 0;
 
231
  str_charset= cs;
 
232
 
 
233
  return false;
 
234
}
 
235
 
222
236
bool String::copy(const char *str,size_t arg_length, const CHARSET_INFO * const cs)
223
237
{
224
238
  if (alloc(arg_length))
419
433
    if (!s.length())
420
434
      return ((int) offset);    // Empty string is always found
421
435
 
422
 
    register const char *str = Ptr+offset;
423
 
    register const char *search=s.ptr();
 
436
    const char *str = Ptr+offset;
 
437
    const char *search=s.ptr();
424
438
    const char *end=Ptr+str_length-s.length()+1;
425
439
    const char *search_end=s.ptr()+s.length();
426
440
skip:
428
442
    {
429
443
      if (*str++ == *search)
430
444
      {
431
 
        register char *i,*j;
 
445
        char *i,*j;
432
446
        i=(char*) str; j=(char*) search+1;
433
447
        while (j != search_end)
434
448
          if (*i++ != *j++) goto skip;
449
463
  {
450
464
    if (!s.length())
451
465
      return offset;                            // Empty string is always found
452
 
    register const char *str = Ptr+offset-1;
453
 
    register const char *search=s.ptr()+s.length()-1;
 
466
    const char *str = Ptr+offset-1;
 
467
    const char *search=s.ptr()+s.length()-1;
454
468
 
455
469
    const char *end=Ptr+s.length()-2;
456
470
    const char *search_end=s.ptr()-1;
459
473
    {
460
474
      if (*str-- == *search)
461
475
      {
462
 
        register char *i,*j;
 
476
        char *i,*j;
463
477
        i=(char*) str; j=(char*) search-1;
464
478
        while (j != search_end)
465
479
          if (*i-- != *j--) goto skip;
819
833
  return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
820
834
}
821
835
 
 
836
std::ostream& operator<<(std::ostream& output, const String &str)
 
837
{
 
838
  output << "String:(";
 
839
  output <<  const_cast<String&>(str).c_str();
 
840
  output << ", ";
 
841
  output << str.length();
 
842
  output << ")";
 
843
 
 
844
  return output;  // for multiple << operators.
 
845
}
 
846
 
822
847
} /* namespace drizzled */
823
848
 
824
849
bool operator==(const drizzled::String &s1, const drizzled::String &s2)