mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
cleanup: versioning style fixes
rename LString/XString classes, remove unused ones
This commit is contained in:
@ -17,125 +17,85 @@
|
||||
#ifndef VERS_STRING_INCLUDED
|
||||
#define VERS_STRING_INCLUDED
|
||||
|
||||
struct Compare_strncmp
|
||||
/*
|
||||
LEX_CSTRING with comparison semantics.
|
||||
*/
|
||||
|
||||
// db and table names: case sensitive (or insensitive) in table_alias_charset
|
||||
struct Compare_table_names
|
||||
{
|
||||
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
|
||||
{
|
||||
return strncmp(a.str, b.str, a.length);
|
||||
}
|
||||
static CHARSET_INFO* charset()
|
||||
{
|
||||
return system_charset_info;
|
||||
DBUG_ASSERT(a.str[a.length] == 0);
|
||||
DBUG_ASSERT(b.str[b.length] == 0);
|
||||
return my_strnncoll(table_alias_charset,
|
||||
(uchar*)a.str, a.length,
|
||||
(uchar*)b.str, b.length);
|
||||
}
|
||||
};
|
||||
|
||||
template <CHARSET_INFO* &CS= system_charset_info>
|
||||
struct Compare_my_strcasecmp
|
||||
// column names and other identifiers: case insensitive in system_charset_info
|
||||
struct Compare_identifiers
|
||||
{
|
||||
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
|
||||
{
|
||||
DBUG_ASSERT(a.str[a.length] == 0 && b.str[b.length] == 0);
|
||||
return my_strcasecmp(CS, a.str, b.str);
|
||||
}
|
||||
static CHARSET_INFO* charset()
|
||||
{
|
||||
return CS;
|
||||
DBUG_ASSERT(a.str[a.length] == 0);
|
||||
DBUG_ASSERT(b.str[b.length] == 0);
|
||||
return my_strcasecmp(system_charset_info, a.str, b.str);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Compare_my_strcasecmp<files_charset_info> Compare_fs;
|
||||
typedef Compare_my_strcasecmp<table_alias_charset> Compare_t;
|
||||
|
||||
template <class Storage= LEX_CSTRING>
|
||||
struct LEX_STRING_u : public Storage
|
||||
class Lex_cstring : public LEX_CSTRING
|
||||
{
|
||||
LEX_STRING_u()
|
||||
public:
|
||||
Lex_cstring()
|
||||
{
|
||||
Storage::str= NULL;
|
||||
Storage::length= 0;
|
||||
str= NULL;
|
||||
length= 0;
|
||||
}
|
||||
LEX_STRING_u(const char *_str, size_t _len, CHARSET_INFO *)
|
||||
Lex_cstring(const char *_str, size_t _len)
|
||||
{
|
||||
Storage::str= _str;
|
||||
Storage::length= _len;
|
||||
str= _str;
|
||||
length= _len;
|
||||
}
|
||||
uint32 length() const
|
||||
void set(const char *_str, size_t _len)
|
||||
{
|
||||
return (uint32)Storage::length;
|
||||
}
|
||||
const char *ptr() const
|
||||
{
|
||||
return Storage::str;
|
||||
}
|
||||
void set(const char *_str, size_t _len, CHARSET_INFO *)
|
||||
{
|
||||
Storage::str= _str;
|
||||
Storage::length= _len;
|
||||
}
|
||||
const LEX_CSTRING& lex_cstring() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
const LEX_STRING& lex_string() const
|
||||
{
|
||||
return *(LEX_STRING *)this;
|
||||
str= _str;
|
||||
length= _len;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Compare= Compare_strncmp, class Storage= LEX_STRING_u<> >
|
||||
struct XString : public Storage
|
||||
template <class Compare>
|
||||
struct Lex_cstring_with_compare : public Lex_cstring
|
||||
{
|
||||
public:
|
||||
XString() {}
|
||||
XString(const char *_str, size_t _len) :
|
||||
Storage(_str, _len, Compare::charset())
|
||||
Lex_cstring_with_compare() {}
|
||||
Lex_cstring_with_compare(const char *_str, size_t _len) :
|
||||
Lex_cstring(_str, _len)
|
||||
{ }
|
||||
Lex_cstring_with_compare(const LEX_STRING src) :
|
||||
Lex_cstring(src.str, src.length)
|
||||
{ }
|
||||
Lex_cstring_with_compare(const LEX_CSTRING src) : Lex_cstring(src.str, src.length)
|
||||
{ }
|
||||
Lex_cstring_with_compare(const char *_str) : Lex_cstring(_str, strlen(_str))
|
||||
{ }
|
||||
bool streq(const Lex_cstring_with_compare& b) const
|
||||
{
|
||||
}
|
||||
XString(const LEX_STRING src) :
|
||||
Storage(src.str, src.length, Compare::charset())
|
||||
{
|
||||
}
|
||||
XString(const LEX_CSTRING src) :
|
||||
Storage(src.str, src.length, Compare::charset())
|
||||
{
|
||||
}
|
||||
XString(const char *_str) :
|
||||
Storage(_str, strlen(_str), Compare::charset())
|
||||
{
|
||||
}
|
||||
bool streq(const XString& b) const
|
||||
{
|
||||
return Storage::length() == b.length() && 0 == Compare()(this->lex_cstring(), b.lex_cstring());
|
||||
return Lex_cstring::length == b.length && 0 == Compare()(*this, b);
|
||||
}
|
||||
operator const char* () const
|
||||
{
|
||||
return Storage::ptr();
|
||||
}
|
||||
operator LEX_CSTRING& () const
|
||||
{
|
||||
return this->lex_cstring();
|
||||
}
|
||||
operator LEX_STRING () const
|
||||
{
|
||||
LEX_STRING res;
|
||||
res.str= const_cast<char *>(this->ptr());
|
||||
res.length= this->length();
|
||||
return res;
|
||||
return str;
|
||||
}
|
||||
operator bool () const
|
||||
{
|
||||
return Storage::ptr() != NULL;
|
||||
return str != NULL;
|
||||
}
|
||||
};
|
||||
|
||||
typedef XString<> LString;
|
||||
typedef XString<Compare_fs> LString_fs;
|
||||
typedef XString<Compare_my_strcasecmp<> > LString_i;
|
||||
|
||||
typedef XString<Compare_strncmp, String> SString;
|
||||
typedef XString<Compare_fs, String> SString_fs;
|
||||
typedef XString<Compare_t, String> SString_t;
|
||||
|
||||
typedef Lex_cstring_with_compare<Compare_identifiers> Lex_ident;
|
||||
typedef Lex_cstring_with_compare<Compare_table_names> Lex_table_name;
|
||||
|
||||
#define XSTRING_WITH_LEN(X) (X).ptr(), (X).length()
|
||||
#define DB_WITH_LEN(X) (X).db.str, (X).db.length
|
||||
|
Reference in New Issue
Block a user