<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="character-arrays">
      </a>
      12.13.1 Character Definition Arrays
     </h3>
    </div>
   </div>
  </div>
  <p>
   Each simple character set has a configuration file located in
        the
   <code class="filename">
    sql/share/charsets
   </code>
   directory. For a
        character set named
   <em class="replaceable">
    <code>
     MYSYS
    </code>
   </em>
   , the file
        is named
   <code class="filename">
    <em class="replaceable">
     <code>
      MYSET
     </code>
    </em>
    .xml
   </code>
   . It
        uses
   <code class="literal">
    &lt;map&gt;
   </code>
   array elements to list
        character set properties.
   <code class="literal">
    &lt;map&gt;
   </code>
   elements appear within these elements:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       &lt;ctype&gt;
      </code>
      defines attributes for each
            character.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       &lt;lower&gt;
      </code>
      and
      <code class="literal">
       &lt;upper&gt;
      </code>
      list the lowercase and
            uppercase characters.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       &lt;unicode&gt;
      </code>
      maps 8-bit character
            values to Unicode values.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       &lt;collation&gt;
      </code>
      elements indicate
            character ordering for comparison and sorting, one element
            per collation. Binary collations need no
      <code class="literal">
       &lt;map&gt;
      </code>
      element because the character
            codes themselves provide the ordering.
     </p>
    </li>
   </ul>
  </div>
  <p>
   For a complex character set as implemented in a
   <code class="filename">
    ctype-
    <em class="replaceable">
     <code>
      MYSET
     </code>
    </em>
    .c
   </code>
   file in the
   <code class="filename">
    strings
   </code>
   directory, there are
        corresponding arrays:
   <code class="literal">
    ctype_
    <em class="replaceable">
     <code>
      MYSET
     </code>
    </em>
    []
   </code>
   ,
   <code class="literal">
    to_lower_
    <em class="replaceable">
     <code>
      MYSET
     </code>
    </em>
    []
   </code>
   ,
        and so forth. Not every complex character set has all of the
        arrays. See also the existing
   <code class="filename">
    ctype-*.c
   </code>
   files for examples. See the
   <code class="filename">
    CHARSET_INFO.txt
   </code>
   file in the
   <code class="filename">
    strings
   </code>
   directory for additional
        information.
  </p>
  <p>
   Most of the arrays are indexed by character value and have 256
        elements. The
   <code class="literal">
    &lt;ctype&gt;
   </code>
   array is indexed
        by character value + 1 and has 257 elements. This is a legacy
        convention for handling
   <code class="literal">
    EOF
   </code>
   .
  </p>
  <p>
   <code class="literal">
    &lt;ctype&gt;
   </code>
   array elements are bit values.
        Each element describes the attributes of a single character in
        the character set. Each attribute is associated with a bitmask,
        as defined in
   <code class="filename">
    include/m_ctype.h
   </code>
   :
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-c"><div class="docs-select-all right" id="sa93161265"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-c"><span class="token macro property">#<span class="token directive keyword">define</span> _MY_U   01      </span><span class="token comment" spellcheck="true">/* Upper case */</span>
<span class="token macro property">#<span class="token directive keyword">define</span> _MY_L   02      </span><span class="token comment" spellcheck="true">/* Lower case */</span>
<span class="token macro property">#<span class="token directive keyword">define</span> _MY_NMR 04      </span><span class="token comment" spellcheck="true">/* Numeral (digit) */</span>
<span class="token macro property">#<span class="token directive keyword">define</span> _MY_SPC 010     </span><span class="token comment" spellcheck="true">/* Spacing character */</span>
<span class="token macro property">#<span class="token directive keyword">define</span> _MY_PNT 020     </span><span class="token comment" spellcheck="true">/* Punctuation */</span>
<span class="token macro property">#<span class="token directive keyword">define</span> _MY_CTR 040     </span><span class="token comment" spellcheck="true">/* Control character */</span>
<span class="token macro property">#<span class="token directive keyword">define</span> _MY_B   0100    </span><span class="token comment" spellcheck="true">/* Blank */</span>
<span class="token macro property">#<span class="token directive keyword">define</span> _MY_X   0200    </span><span class="token comment" spellcheck="true">/* heXadecimal digit */</span></code></pre>
  </div>
  <p>
   The
   <code class="literal">
    &lt;ctype&gt;
   </code>
   value for a given character
        should be the union of the applicable bitmask values that
        describe the character. For example,
   <code class="literal">
    'A'
   </code>
   is
        an uppercase character (
   <code class="literal">
    _MY_U
   </code>
   ) as well as a
        hexadecimal digit (
   <code class="literal">
    _MY_X
   </code>
   ), so its
   <code class="literal">
    ctype
   </code>
   value should be defined like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-c"><div class="docs-select-all right" id="sa6255714"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-c">ctype<span class="token punctuation">[</span><span class="token string">'A'</span><span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> _MY_U <span class="token operator">|</span> _MY_X <span class="token operator">=</span> <span class="token number">01</span> <span class="token operator">|</span> <span class="token number">0200</span> <span class="token operator">=</span> <span class="token number">0201</span></code></pre>
  </div>
  <p>
   The bitmask values in
   <code class="filename">
    m_ctype.h
   </code>
   are octal
        values, but the elements of the
   <code class="literal">
    &lt;ctype&gt;
   </code>
   array in
   <code class="filename">
    <em class="replaceable">
     <code>
      MYSET
     </code>
    </em>
    .xml
   </code>
   should
        be written as hexadecimal values.
  </p>
  <p>
   The
   <code class="literal">
    &lt;lower&gt;
   </code>
   and
   <code class="literal">
    &lt;upper&gt;
   </code>
   arrays hold the lowercase and
        uppercase characters corresponding to each member of the
        character set. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-none"><div class="docs-select-all right" id="sa96779705"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-none">lower['A'] should contain 'a'
upper['a'] should contain 'A'</code></pre>
  </div>
  <p>
   Each
   <code class="literal">
    &lt;collation&gt;
   </code>
   array indicates how
        characters should be ordered for comparison and sorting
        purposes. MySQL sorts characters based on the values of this
        information. In some cases, this is the same as the
   <code class="literal">
    &lt;upper&gt;
   </code>
   array, which means that sorting
        is case-insensitive. For more complicated sorting rules (for
        complex character sets), see the discussion of string collating
        in
   <a class="xref" href="string-collating.html" title="12.13.2 String Collating Support for Complex Character Sets">
    Section 12.13.2, “String Collating Support for Complex Character Sets”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
