[MDEV-31992] Automatic conversion from LEX_STRING to LEX_CSTRING Created: 2023-08-23  Updated: 2023-09-17  Resolved: 2023-08-23

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Fix Version/s: 11.3.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-31531 Remove my_casedn_str() and my_caseup_... In Testing
blocks MDEV-31606 Refactor check_db_name() to get a con... Closed

 Description   

Let's add automatic conversion operator from LEX_STRING to LEX_CSTRING.

struct st_mysql_lex_string
{
  char *str;
  size_t length;
#ifdef __cplusplus
  // Allow automatic cast from LEX_STRING to LEX_CSTRING in c++.
  operator struct st_mysql_const_lex_string() const
  {
    return {str, length};
  }
#endif

This will help to remove some duplicate functions/methods accepting LEX_CSTRING and LEX_STRING and to avoid adding duplicate functions/methods in the future.

Duplicate methods:

  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)
  { }

  Storage_engine_name(const LEX_CSTRING &name)
   :m_storage_engine_name(name)
  { }
  Storage_engine_name(const LEX_STRING &name)
  {
    m_storage_engine_name.str= name.str;
    m_storage_engine_name.length= name.length;
  }

  // Append with optional character set conversion from ASCII (e.g. to UCS2)
  bool append(const LEX_STRING *ls)
  {
    DBUG_ASSERT(ls->length < UINT_MAX32 &&
                ((ls->length == 0 && !ls->str) ||
                 ls->length == strlen(ls->str)));
    return append(ls->str, (uint32) ls->length);
  }
  bool append(const LEX_CSTRING *ls)
  {
    DBUG_ASSERT(ls->length < UINT_MAX32 &&
                ((ls->length == 0 && !ls->str) ||
                 ls->length == strlen(ls->str)));
    return append(ls->str, (uint32) ls->length);
  }

The version with LEX_STRING should be removed.


Generated at Thu Feb 08 10:28:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.