@c Generated automatically from stringutils.pas
@c DO NOT CHANGE THIS FILE MANUALLY!

@example
@{
Some routines for string handling on a higher level than those
provided by the RTS.

Copyright (C) 1999-2000 Free Software Foundation, Inc.

Author: Frank Heckenbach <frank@@pascal.gnu.de>

This file is part of GNU Pascal.

GNU Pascal is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Pascal 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Pascal; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.

As a special exception, if you link this file with files compiled
with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public
License. This exception does not however invalidate any other
reasons why the executable file might be covered by the GNU General
Public License.
@}

@{$gnu-pascal@}
@{$if __GPC_RELEASE__ < 20000814@}
@{$error This unit requires GPC release 20000814 or newer.@}
@{$endif@}

unit StringUtils;

interface

uses GPC;

@{ Returns the number of disjoint occurences of SubStr in s. Returns
  0 if SubStr is empty. @}
function  StrCount (const SubStr : String; s : String) : Integer;

@{ Returns s, with all disjoint occurences of Source replaced by
  Dest. @}
function  StrReplace (const s, Source, Dest : String) : TString;

@{ Converts a digit character to its numeric value. Handles every
  base up to 36 (0 .. 9, a .. z, upper and lower case recognized).
  Returns -1 if the character is not a digit at all. If you want to
  use it for a base < 36, you have to check if the result is smaller
  than the base and not equal to -1. @}
function  Char2Digit (ch : Char) : Integer;

@{ Encode a string in a printable format (quoted printable and
  surrounded with @samp{"}). All occurences of @samp{"} within the string are
  encoded, so the result string contains exactly two @samp{"} characters
  (at the beginning and ending). This is useful to store arbitrary
  strings in text files while keeping them as readable as possible
  (which is the goal of the quoted printable encoding in general,
  RFC 1521, section 5.1) and being able to read them back losslessly
  (with UnQuoteString). @}
function  QuoteString (const s : String) : TString;

@{ Decode a string encoded by QuoteString (removing the @samp{"} and
  expanding quoted printable encoded characters). Returns True if
  successful and False if the string has an invalid form. A string
  returned by QuoteString is always valid. @}
function  UnQuoteString (var s : String) : Boolean;

@{ Decode a quoted-printable string (not enclosed in @samp{"}, unlike for
  UnQuoteString). Returns True if successful and False if the string
  has an invalid form. @}
function  UnQPString (var s : String) : Boolean;

@{ Replaces all tab characters in s with the appropriate amount of
  spaces, assuming tab stops at every TabSize columns. Returns True
  if successful and False if the expanded string would exceed the
  capacity of s. In the latter case, some, but not all of the tabs
  in s may have been expanded. @}
function  ExpandTabs (var s : String; TabSize : Integer) : Boolean;

@{ Returns s, with all occurences of C style escape sequences (e.g.
  @samp{\n}) replaced by the characters they mean. If AllowOctal is True,
  also octal character specifications (e.g. @samp{\007}) are replaced. If
  RemoveQuoteChars is True, any other backslashes are removed (e.g.
  @samp{\*} -> @samp{*} and @samp{\\} -> @samp{\}), otherwise they are kept, and also
  @samp{\\} is left as two backslashes then. @}
function  ExpandCEscapeSequences (const s : String;
  RemoveQuoteChars, AllowOctal : Boolean) : TString;

@{ String hash table @}

const
  DefaultHashSize = 1403;

type
  THash = Cardinal;

  PStrHashList = ^TStrHashList;
  TStrHashList = record
    Next : PStrHashList;
    s : PString;
    i : Integer;
    p : Pointer
  end;

  PStrHashTable = ^TStrHashTable;
  TStrHashTable (Size : Cardinal) = record
    CaseSensitive : Boolean;
    Table : array [0 .. Size - 1] of PStrHashList
  end;

function  HashString          (const s : String) : THash;
function  NewStrHashTable     (Size : Cardinal; CaseSensitive :
  Boolean) : PStrHashTable;
procedure AddStrHashTable     (HashTable : PStrHashTable; s :
  String; i : Integer; p : Pointer);
procedure DeleteStrHashTable  (HashTable : PStrHashTable; s :
  String);
function  SearchStrHashTable  (HashTable : PStrHashTable; const s :
  String; var p : Pointer) : Integer; @{ p may be null @}
procedure DisposeStrHashTable (HashTable : PStrHashTable);

@end example
