(********************************************************************)
(*                                                                  *)
(*  chartype.s7i  Character type definitions                        *)
(*  Copyright (C) 1989 - 2009, 2019, 2024  Thomas Mertes            *)
(*                                                                  *)
(*  This file is part of the Seed7 Runtime Library.                 *)
(*                                                                  *)
(*  The Seed7 Runtime Library is free software; you can             *)
(*  redistribute it and/or modify it under the terms of the GNU     *)
(*  Lesser General Public License as published by the Free Software *)
(*  Foundation; either version 2.1 of the License, or (at your      *)
(*  option) any later version.                                      *)
(*                                                                  *)
(*  The Seed7 Runtime Library is distributed in the hope that it    *)
(*  will be useful, but WITHOUT ANY WARRANTY; without even the      *)
(*  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *)
(*  PURPOSE.  See the GNU Lesser General Public License for more    *)
(*  details.                                                        *)
(*                                                                  *)
(*  You should have received a copy of the GNU Lesser General       *)
(*  Public License along with this program; if not, write to the    *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


const set of char: letter_char is {'A' .. 'Z'} | {'a' .. 'z'};
const set of char: digit_char is {'0' .. '9'};
const set of char: hexdigit_char is digit_char | {'A' .. 'F'} | {'a' .. 'f'};
const set of char: octdigit_char is {'0' .. '7'};
const set of char: alphanum_char is letter_char | digit_char;
const set of char: control_char is {'\0;' .. '\31;'} | {'\127;' .. '\159;'};
const set of char: special_char is
    {'!', '$', '%', '&', '*', '+', ',', '-', '.', '/',
     ':', ';', '<', '=', '>', '?', '@', '\\','^', '`',
     '|', '~'};
const set of char: extended_special_char is special_char | { '"', '#', ''' };
const set of char: left_angle_bracket is {'<'};
const set of char: right_angle_bracket is {'>'};
const set of char: special_html_char is special_char - left_angle_bracket;
const set of char: single_quotation_char is {'''};
const set of char: double_quotation_char is {'"'};
const set of char: sharp_char is {'#'};
const set of char: hyphen_char is {'-'};
const set of char: slash_char is {'/'};
const set of char: special_sql_char is special_char - hyphen_char - slash_char;
const set of char: paren_char is {'(', ')', '[', ']', '{', '}'};
const set of char: left_paren_char is {'('};
const set of char: other_paren_char is {')', '[', ']', '{', '}'};
const set of char: name_start_char is letter_char | {'_'};
const set of char: name_char is letter_char | digit_char | {'_'};
const set of char: space_or_tab is {' ', '\t'};
const set of char: line_end_char is {'\n', '\r'};
const set of char: white_space_char is {' ', '\t', '\n', '\r'};
const set of char: white_space_or_end_tag is white_space_char | {'>'};
const set of char: white_space_or_printable is white_space_char | {'!' .. '~'};
const set of char: equals_or_end_tag is {'=', '>'};
const set of char: special_comment_char is {'(', '*', EOF};
const set of char: html_name_start_char is letter_char | {'-', '.', '_', ':'};
const set of char: html_name_char is alphanum_char | {'-', '.', '_', ':'};
const set of char: http_separators is
    {'(', ')', '<', '>', '@', ',', ';', ':', '\\',
     '/', '[', ']', '?', '=', '{', '}'};
const set of char: http_token_char is {'!' .. '~'} - http_separators - double_quotation_char;

const set of char: no_escape_char is
    {' ', '!',      '#', '$', '%', '&', ''',
     '(', ')', '*', '+', ',', '-', '.', '/',
     '0', '1', '2', '3', '4', '5', '6', '7',
     '8', '9', ':', ';', '<', '=', '>', '?',
     '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
     'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
     'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
     'X', 'Y', 'Z', '[',      ']', '^', '_',
     '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
     'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
     'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
     'x', 'y', 'z', '{', '|', '}', '~'};

const array string: esc_tab is [](
    (* " *) "\"", (* # *) " ",  (* $ *) " ",  (* % *) " ",  (* & *) " ",
    (* ' *) "'",  (* ( *) " ",  (* ) *) " ",  (* * *) " ",  (* + *) " ",
    (* , *) " ",  (* - *) " ",  (* . *) " ",  (* / *) " ",  (* 0 *) " ",
    (* 1 *) " ",  (* 2 *) " ",  (* 3 *) " ",  (* 4 *) " ",  (* 5 *) " ",
    (* 6 *) " ",  (* 7 *) " ",  (* 8 *) " ",  (* 9 *) " ",  (* : *) " ",
    (* ; *) " ",  (* < *) " ",  (* = *) " ",  (* > *) " ",  (* ? *) " ",
    (* @ *) " ",  (* A *) "\A", (* B *) "\B", (* C *) "\C", (* D *) "\D",
    (* E *) "\E", (* F *) "\F", (* G *) "\G", (* H *) "\H", (* I *) "\I",
    (* J *) "\J", (* K *) "\K", (* L *) "\L", (* M *) "\M", (* N *) "\N",
    (* O *) "\O", (* P *) "\P", (* Q *) "\Q", (* R *) "\R", (* S *) "\S",
    (* T *) "\T", (* U *) "\U", (* V *) "\V", (* W *) "\W", (* X *) "\X",
    (* Y *) "\Y", (* Z *) "\Z", (* [ *) " ",  (* \ *) "\\", (* ] *) " ",
    (* ^ *) " ",  (* _ *) " ",  (* ` *) " ",  (* a *) "\a", (* b *) "\b",
    (* c *) " ",  (* d *) " ",  (* e *) "\e", (* f *) "\f", (* g *) " ",
    (* h *) " ",  (* i *) " ",  (* j *) " ",  (* k *) " ",  (* l *) " ",
    (* m *) " ",  (* n *) "\n", (* o *) " ",  (* p *) " ",  (* q *) " ",
    (* r *) "\r", (* s *) " ",  (* t *) "\t", (* u *) " ",  (* v *) "\v");


(**
 *  Determine leftmost position of a char from ''chSet'' in ''stri''.
 *  @return the position of a char from ''chSet'' or 0 if ''stri''
 *          does not contain any character from ''chSet''.
 *)
const func integer: pos (in string: stri, in set of char: chSet) is func
  result
    var integer: pos is 0;
  local
    var char: ch is ' ';
    var integer: index is 0;
  begin
    for ch key index range stri until pos <> 0 do
      if ch in chSet then
        pos := index;
      end if;
    end for;
  end func;