diff options
author | pem@mysql.com <> | 2004-05-26 17:04:45 +0200 |
---|---|---|
committer | pem@mysql.com <> | 2004-05-26 17:04:45 +0200 |
commit | 71eddc362e7d22b9922bad9d093819592208726b (patch) | |
tree | e4e5bb1f8b9718ec195b357c050b3dc3254b447d /sql/sql_string.cc | |
parent | 350d8a215bb83518519a2c7c1bc218170bb6b8a9 (diff) | |
parent | 94c0611e6b1f7a1ee93facc31a2f2876cf664e7a (diff) | |
download | mariadb-git-71eddc362e7d22b9922bad9d093819592208726b.tar.gz |
Merging 4.1 to 5.0.
Diffstat (limited to 'sql/sql_string.cc')
-rw-r--r-- | sql/sql_string.cc | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 7c3f9bc5cde..4d85438b03f 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -416,16 +416,18 @@ bool String::append(const String &s) /* - Append a latin1 string to the a string of the current character set + Append an ASCII string to the a string of the current character set */ - bool String::append(const char *s,uint32 arg_length) { - if (!arg_length) // Default argument - if (!(arg_length= (uint32) strlen(s))) - return FALSE; - if (str_charset->mbmaxlen > 1) + if (!arg_length) + return FALSE; + + /* + For an ASCII incompatible string, e.g. UCS-2, we need to convert + */ + if (str_charset->mbminlen > 1) { uint32 add_length=arg_length * str_charset->mbmaxlen; if (realloc(str_length+ add_length)) @@ -434,6 +436,10 @@ bool String::append(const char *s,uint32 arg_length) s, arg_length, &my_charset_latin1); return FALSE; } + + /* + For an ASCII compatinble string we can just append. + */ if (realloc(str_length+arg_length)) return TRUE; memcpy(Ptr+str_length,s,arg_length); @@ -443,29 +449,39 @@ bool String::append(const char *s,uint32 arg_length) /* + Append a 0-terminated ASCII string +*/ + +bool String::append(const char *s) +{ + return append(s, strlen(s)); +} + + +/* Append a string in the given charset to the string with character set recoding */ - bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs) { - if (!arg_length) // Default argument - if (!(arg_length= (uint32) strlen(s))) - return FALSE; - if (cs != str_charset && str_charset->mbmaxlen > 1) + uint32 dummy_offset; + + if (needs_conversion(arg_length, cs, str_charset, &dummy_offset)) { - uint32 add_length=arg_length * str_charset->mbmaxlen; - if (realloc(str_length+ add_length)) + uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen; + if (realloc(str_length + add_length)) return TRUE; str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset, s, arg_length, cs); - return FALSE; } - if (realloc(str_length+arg_length)) - return TRUE; - memcpy(Ptr+str_length,s,arg_length); - str_length+=arg_length; + else + { + if (realloc(str_length + arg_length)) + return TRUE; + memcpy(Ptr + str_length, s, arg_length); + str_length+= arg_length; + } return FALSE; } @@ -554,40 +570,6 @@ skip: } /* - Search after a string without regarding to case - This needs to be replaced when we have character sets per string -*/ - -int String::strstr_case(const String &s,uint32 offset) -{ - if (s.length()+offset <= str_length) - { - if (!s.length()) - return ((int) offset); // Empty string is always found - - register const char *str = Ptr+offset; - register const char *search=s.ptr(); - const char *end=Ptr+str_length-s.length()+1; - const char *search_end=s.ptr()+s.length(); -skip: - while (str != end) - { - if (str_charset->sort_order[*str++] == str_charset->sort_order[*search]) - { - register char *i,*j; - i=(char*) str; j=(char*) search+1; - while (j != search_end) - if (str_charset->sort_order[*i++] != - str_charset->sort_order[*j++]) - goto skip; - return (int) (str-Ptr) -1; - } - } - } - return -1; -} - -/* ** Search string from end. Offset is offset to the end of string */ @@ -871,3 +853,23 @@ void String::print(String *str) } } } + + +/* + Exchange state of this object and argument. + + SYNOPSIS + String::swap() + + RETURN + Target string will contain state of this object and vice versa. +*/ + +void String::swap(String &s) +{ + swap_variables(char *, Ptr, s.Ptr); + swap_variables(uint32, str_length, s.str_length); + swap_variables(uint32, Alloced_length, s.Alloced_length); + swap_variables(bool, alloced, s.alloced); + swap_variables(CHARSET_INFO*, str_charset, s.str_charset); +} |