Rules of the game:

Note: Wiki not updated, actual design header: [http:/people/ct/escaping.h]

TableOfContents

Set Up

define an array of str_esc

Where each entry is in the form of:

 {
  { "unescaped", "escaped", flags, special_parser },
  ...
  { 0,0,0,0 }
 }

generate the lookup tables

 str_esclookup * str_esclookup_alloc (alloc_limits limits,
                                      str_esc * conv,
                                      isprint_cnt_func,
                                      escape_func)

converting unescaped to escaped strings:

 t_uchar * str_save_escaped (alloc_limits limits,
                             const t_uchar * str,
                             int size,
                             const str_conv_lookup * lookup)

  for every char in str
    is_print_cnt is invoked, found characters are copied verbatim
    if the return was zero
      it lookups the longest matching string from unescaped
      if found and GENERIC flag is not set
        copy the escaped string
      else
        escape_func is invoked to generate a generic escape

converting escaped to unescaped strings:

 t_uchar * str_save_unescaped (alloc_limits limits,
                               const t_uchar * str,
                               size_t* size,
                               const str_esc_lookup * lookup)

  for ever character in str
    is_print_cnt is invoked, found characters are copied verbatim
    if return was zero
      lookup longest matching escaped string
      if found
        if unescaped != NOCHARS
          copy the unescaped string
        if parser_func != 0
          invoke parserfunc
      else
        free memory, abort, return zero ( this is the only case of an error, illegal escape sequence)

DISCLAIMER

GenericEscapingEngine (last edited 2004-01-14 15:43:04 by ct)