--------------------------------------------------------------- {{{1 ---------- --: Copyright © 2003 … 2023 Martin Krischik «krischik@users.sourceforge.net» ------------------------------------------------------------------------------ --: This library is free software; you can redistribute it and/or modify it --: under the terms of the GNU Library General Public License as published by --: the Free Software Foundation; either version 2 of the License, or (at your --: option) any later version. --: --: This 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 Library General Public --: License for more details. --: --: You should have received a copy of the GNU Library General Public License --: along with this library; if not, write to the Free Software Foundation, --: Inc., 675 Mass Ave, Cambridge, MA 02139, USA. --------------------------------------------------------------- }}}1 ---------- pragma License (Modified_Gpl); pragma Ada_2022; with Ada.Strings.Wide_Unbounded; with Ada.Strings.Wide_Maps; with Ada.Containers; --- -- @summary -- -- @description -- No, I have not created some new Wide_String class - yet. Just a few string tools. -- package AdaCL.Wide_Strings is subtype Hex_Digit is Natural range 0 .. 16#F#; --- -- Replace all Search with Replace -- --: @param Source String to be changed --: @param Search String we look for --: @param Replace String we want to have --: @param Mapping Search mapping procedure Change_All (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; Replace : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Replace all Search with Replace and Count how often it was done. -- --: @param Source String to be changed --: @param Search String we look for --: @param Replace String we want to have --: @param Mapping Search mapping --: @param Count Count of replaces done procedure Change_All (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; Replace : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Count : out Natural); --- -- Replace all Search with Replace -- --: @param Source String to be changed --: @param Search String we look for --: @param Replace String we want to have --: @param Mapping Search mapping procedure Change_First (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; Replace : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Replace First Search with Replace and return success flag. -- --: @param Source String to be changed --: @param Search String we look for --: @param Replace String we want to have --: @param Mapping Search mapping --: @param Found Count of replaces done procedure Change_First (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; Replace : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Found : out Boolean); --- -- Replace Last Search with Replace -- --: @param Source : String we look for --: @param Search : String to be changed --: @param Replace : String we want to have --: @param Mapping : Search mapping procedure Change_Last (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; Replace : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Replace Last Search with Replace and return success flag. -- --: @param Source String to be changed --: @param Search String we look for --: @param Replace String we want to have --: @param Mapping Search mapping --: @param Found Count of replaces done procedure Change_Last (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; Replace : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Found : out Boolean); --- -- Searches for all occurences of text "Search" and Inserts text "Insert" after the found text but only when -- "Insert" is not allready there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping procedure Append_All (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Searches for all occurences of text "Search" and Inserts text "Insert" after the found text but only when -- "Insert" is not allready there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping --: @param Count Count of replaces done procedure Append_All (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Count : out Natural); --- -- Searches for first occurence of text "Search" and Inserts text "Insert" after the found text but only when -- "Insert" is not allready there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping procedure Append_First (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Searches for first occurence of text "Search" and Inserts text "Insert" after the found text but only when -- "Insert" is not allready there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping --: @param Found Count of replaces done procedure Append_First (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Found : out Boolean); --- -- Searches for last occurence of text "Search" and Inserts text "Insert" after the found text but only when -- "Insert" is not allready there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping procedure Append_Last (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Searches for last occurence of text "Search" and Inserts text "Insert" after the found text but only when -- "Insert" is not allready there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping --: @param Found Count of replaces done procedure Append_Last (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Found : out Boolean); --- -- Return the end-of-field position in Data after "Starting_Index", assuming that fields are separated by the -- Field_Separator. If there's no Field_Separator, return the end of the Data. --: @param Source String to search in --: @param Field_Separator Field seperator. --: @param Starting_At Start search at. function Field_End (Source : in Wide_String; Field_Separator : in Wide_Character; Starting_At : Positive) return Natural with Pure_Function; --- -- Searches for first occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping procedure Insert_First (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Searches for first occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping --: @param Found Count of replaces done procedure Insert_First (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Found : out Boolean); --- -- Searches for all occurences of text "Search" and Inserts text "Insert" bevore when "Insert" is there. -- --: @param Source Search mapping --: @param Search String we want to insert --: @param New_Item String we look for --: @param Mapping String to be changed procedure Insert_All (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Searches for all occurences of text "Search" and Inserts text "Insert" bevore when "Insert" is there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping --: @param Count Count of replaces done procedure Insert_All (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Count : out Natural); --- -- Searches for last occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping procedure Insert_Last (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity); --- -- Searches for last occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there. -- --: @param Source String to be changed --: @param Search String we look for --: @param New_Item String we want to insert --: @param Mapping Search mapping --: @param Found Count of replaces done procedure Insert_Last (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String; Search : in Wide_String; New_Item : in Wide_String; Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity; Found : out Boolean); ------------------------------------------------------------------------------ --- -- Hash function for booch components. -- --: @param Key String to calculate a hash value form --: @return hash value function Hash (Key : Wide_String) return Natural with Pure_Function; --- -- Hash function for booch components. -- --: @param Key String to calculate a hash value form --: @return hash value function Hash (Key : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String) return Natural with Pure_Function; --- -- Hash function for Ada components. -- --: @param Key String to calculate a hash value form --: @return hash value function Hash (Key : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String) return Ada.Containers.Hash_Type with Pure_Function; --- -- Hash function for Ada components. -- --: @param Key String to calculate a hash value form --: @return hash value function Hash (Key : Wide_String) return Ada.Containers.Hash_Type with Pure_Function; --- -- convert Wide_String into Integer -- --: @param Image String to to be shown as Integer --: @return pased integer value function Value (Image : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String) return Integer with Pure_Function; ------------------------------------------------------------------------------ --- -- Extract the first word. -- --: @param Source String to search --: @param Delimiter word delimiter. Default is space. function First_Word (Source : in Wide_String; Delimiter : in Wide_Character := ' ') return Wide_String with Pure_Function; --- -- Extract the last word. -- --: @param Source String to search --: @param Delimiter word delimiter. Default is space. function Last_Word (Source : in Wide_String; Delimiter : in Wide_Character := ' ') return Wide_String with Pure_Function; end AdaCL.Wide_Strings; ---------------------------------------------------------------- {{{ ---------- --: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab : --: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr : --: vim: set spell spelllang=en_gb