%%
%% This is file `l3keyval.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3keyval.dtx  (with options: `package')
%% 
%% 
%% EXPERIMENTAL CODE
%% 
%% Do not distribute this file without also distributing the
%% source files specified above.
%% 
%% Do not distribute a modified version of this file.
%% 
%% 
%% File: l3keyval.dtx Copyright (C) 2006-2009 LaTeX3 project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``expl3 bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%%    http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%%   Snapshots taken from the repository represent work in progress and may
%%   not work or may contain conflicting material!  We therefore ask
%%   people _not_ to put them into distributions, archives, etc. without
%%   prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
\RequirePackage{l3names}
\GetIdInfo$Id: l3keyval.dtx 1362 2009-05-28 20:19:21Z joseph $
       {L3 Experimental keyval processing}
\ProvidesExplPackage
  {\filename}{\filedate}{\fileversion}{\filedescription}
\package_check_loaded_expl:
\tl_new:N  \l_KV_tmpa_tl
\tl_new:N  \l_KV_tmpb_tl
\tl_new:Nn \c_KV_single_equal_sign_tl{=}
\toks_new:N \l_KV_parse_toks
\toks_new:N \l_KV_currkey_toks
\toks_new:N \l_KV_currval_toks
\bool_new:N \l_KV_remove_one_level_of_braces_bool
\bool_set_true:N \l_KV_remove_one_level_of_braces_bool
\group_begin:
\char_set_catcode:nn{`\=}{13}
\char_set_catcode:nn{`\,}{13}
\char_set_lccode:nn{`\8}{`\=}
\char_set_lccode:nn{`\9}{`\,}
\tl_to_lowercase:n{\group_end:
\cs_new_nopar:Npn \KV_sanitize_outerlevel_active_equals:N #1{
  \tl_replace_all_in:Nnn #1 = 8
}
\cs_new_nopar:Npn \KV_sanitize_outerlevel_active_commas:N #1{
  \tl_replace_all_in:Nnn #1 , 9
}
}
\group_begin:
\char_set_catcode:nn{`\Q}{3}
\cs_gnew:Npn\KV_remove_surrounding_spaces:nw#1#2\q_nil{
  #1{\KV_remove_surrounding_spaces_auxi:w \exp_not:N#2Q~Q}
}
\cs_gnew:Npn\KV_remove_surrounding_spaces_auxi:w#1~Q{
  \KV_remove_surrounding_spaces_auxii:w #1 Q
}
\cs_gnew:Npn\KV_remove_surrounding_spaces_auxii:w#1Q#2{#1}
\cs_gnew:Npn\KV_add_value_element:w\q_stop#1\q_nil{
  \toks_set:Nf\l_KV_currval_toks {
    \KV_remove_surrounding_spaces_auxi:w \exp_not:N#1Q~Q
  }
  \toks_put_right:No\l_KV_parse_toks{
    \exp_after:wN {\toks_use:N \l_KV_currval_toks}
  }
}
\cs_gnew:Npn\KV_set_key_element:w#1\q_nil{
  \toks_set:Nf\l_KV_currkey_toks
  {
    \exp_last_unbraced:NNo \KV_remove_surrounding_spaces_auxi:w
      \exp_not:N \use_none:n #1Q~Q
  }
  \bool_if:NT \l_KV_remove_one_level_of_braces_bool
  {
    \exp_args:NNo \toks_set:No \l_KV_currkey_toks {
      \exp_after:wN \KV_add_element_aux:w
        \toks_use:N \l_KV_currkey_toks \q_nil
    }
  }
}
\group_end:
\cs_new:Npn \KV_add_element_aux:w#1\q_nil{#1}
\cs_new:Npn \KV_parse_sanitize_aux:n #1 {
  \group_begin:
    \toks_clear:N \l_KV_parse_toks
    \tl_set:Nx \l_KV_tmpa_tl { \exp_not:n {#1} }
    \KV_sanitize_outerlevel_active_equals:N \l_KV_tmpa_tl
    \KV_sanitize_outerlevel_active_commas:N \l_KV_tmpa_tl
    \exp_last_unbraced:NNV \KV_parse_elt:w \q_no_value
      \l_KV_tmpa_tl , \q_nil ,
  \exp_last_unbraced:NV \group_end:
  \l_KV_parse_toks
}
\cs_new:Npn \KV_parse_no_sanitize_aux:n #1{
  \group_begin:
    \toks_clear:N \l_KV_parse_toks
    \KV_parse_elt:w \q_no_value #1 , \q_nil ,
  \exp_last_unbraced:NV \group_end:
  \l_KV_parse_toks
}
\cs_set:Npn \KV_parse_elt:w #1,{
  \tl_if_blank:oTF{\use_none:n #1}
  { \KV_parse_elt:w \q_no_value }
  {
    \quark_if_nil:oF {\use_ii:nn #1 }
    {
      \KV_split_key_value_current:w #1==\q_nil
      \KV_parse_elt:w \q_no_value
    }
  }
}
\cs_new:Npn \KV_split_key_value_current:w {\ERROR}
\cs_new:Npn \KV_split_key_value_space_removal:w #1 = #2\q_nil{
  \KV_set_key_element:w#1\q_nil
  \tl_set:Nx\l_KV_tmpa_tl{\exp_not:n{#2}}
  \tl_if_eq:NNTF\l_KV_tmpa_tl\c_KV_single_equal_sign_tl
  {
    \toks_put_right:No\l_KV_parse_toks{
      \exp_after:wN \KV_key_no_value_elt:n
      \exp_after:wN {\toks_use:N\l_KV_currkey_toks}
    }
  }
  {
    \KV_split_key_value_space_removal_detect_error:wTF#2\q_no_value\q_nil
    {\KV_split_key_value_space_removal_aux:w \q_stop #2}
    {\ERROR}
  }
}
\cs_new:Npn
  \KV_split_key_value_space_removal_detect_error:wTF#1=#2#3\q_nil{
    \tl_if_head_eq_meaning:nNTF{#3}\q_no_value
}
\cs_new:Npn \KV_val_preserve_braces:NnN #1#2#3{{#2}}
\cs_new:Npn\KV_split_key_value_space_removal_aux:w #1=={
  \tl_set:Nx\l_KV_tmpa_tl{\exp_not:o{\use_none:nnn#1\q_nil\q_nil}}
  \toks_put_right:No\l_KV_parse_toks{
    \exp_after:wN \KV_key_value_elt:nn
    \exp_after:wN {\toks_use:N\l_KV_currkey_toks}
  }
    \tl_if_empty:NTF\l_KV_tmpa_tl
  { \toks_put_right:Nn\l_KV_parse_toks{{}} }
  {
    \quark_if_nil:NTF\l_KV_tmpa_tl
    {
      \bool_if:NTF \l_KV_remove_one_level_of_braces_bool
      {
        \toks_put_right:No\l_KV_parse_toks{
          \exp_after:wN{\use_ii:nnn #1\q_nil}
        }
      }
      {
        \toks_put_right:No\l_KV_parse_toks{
          \exp_after:wN{\KV_val_preserve_braces:NnN #1\q_nil}
        }
      }
    }
    { \KV_add_value_element:w #1\q_nil }
  }
}
\cs_new:Npn \KV_split_key_value_no_space_removal:w #1#2=#3=#4\q_nil{
  \tl_set:Nn\l_KV_tmpa_tl{#4}
  \tl_if_empty:NTF \l_KV_tmpa_tl
  {
    \toks_put_right:Nn\l_KV_parse_toks{\KV_key_no_value_elt:n{#2}}
  }
  {
    \tl_if_eq:NNTF\c_KV_single_equal_sign_tl\l_KV_tmpa_tl
    {
      \toks_put_right:Nn\l_KV_parse_toks{\KV_key_value_elt:nn{#2}{#3}}
    }
    {\ERROR}
  }
}
\cs_new:Npn \KV_key_no_value_elt:n #1{\ERROR}
\cs_new:Npn \KV_key_value_elt:nn #1#2{\ERROR}
\cs_new_nopar:Npn \KV_parse_no_space_removal_no_sanitize:n {
  \cs_set_eq:NN \KV_split_key_value_current:w \KV_split_key_value_no_space_removal:w
  \KV_parse_no_sanitize_aux:n
}
\cs_new_nopar:Npn \KV_parse_space_removal_sanitize:n {
  \cs_set_eq:NN \KV_split_key_value_current:w \KV_split_key_value_space_removal:w
  \KV_parse_sanitize_aux:n
}
\cs_new_nopar:Npn \KV_parse_space_removal_no_sanitize:n {
  \cs_set_eq:NN \KV_split_key_value_current:w \KV_split_key_value_space_removal:w
  \KV_parse_no_sanitize_aux:n
}
%% 
%%
%% End of file `l3keyval.sty'.
