1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  The GString struct contains the public fields of a GString. 
  26. -- 
  27. --  </description> 
  28. pragma Ada_2005; 
  29.  
  30. pragma Warnings (Off, "*is already use-visible*"); 
  31. with Glib;                 use Glib; 
  32. with Interfaces.C.Strings; use Interfaces.C.Strings; 
  33.  
  34. package Glib.String is 
  35.  
  36.    type Gstring is record 
  37.       Str : Interfaces.C.Strings.chars_ptr; 
  38.       Len : Gsize; 
  39.       Allocated_Len : Gsize; 
  40.    end record; 
  41.    pragma Convention (C, Gstring); 
  42.  
  43.    function From_Object_Free (B : access Gstring) return Gstring; 
  44.    pragma Inline (From_Object_Free); 
  45.    --  The GString struct contains the public fields of a GString. 
  46.  
  47.    ------------------ 
  48.    -- Constructors -- 
  49.    ------------------ 
  50.  
  51.    function Get_Type return Glib.GType; 
  52.    pragma Import (C, Get_Type, "g_gstring_get_type"); 
  53.  
  54.    ------------- 
  55.    -- Methods -- 
  56.    ------------- 
  57.  
  58.    function Append (Self : Gstring; Val : UTF8_String) return Gstring; 
  59.    --  Adds a string onto the end of a Glib.String.Gstring, expanding it if 
  60.    --  necessary. 
  61.    --  "val": the string to append onto the end of String 
  62.  
  63.    function Append_C (Self : Gstring; C : Gchar) return Gstring; 
  64.    pragma Import (C, Append_C, "g_string_append_c"); 
  65.    --  Adds a byte onto the end of a Glib.String.Gstring, expanding it if 
  66.    --  necessary. 
  67.    --  "c": the byte to append onto the end of String 
  68.  
  69.    function Append_Len 
  70.       (Self : Gstring; 
  71.        Val  : UTF8_String; 
  72.        Len  : Gssize) return Gstring; 
  73.    --  Appends Len bytes of Val to String. Because Len is provided, Val may 
  74.    --  contain embedded nuls and need not be nul-terminated. 
  75.    --  Since this function does not stop at nul bytes, it is the caller's 
  76.    --  responsibility to ensure that Val has at least Len addressable bytes. 
  77.    --  "val": bytes to append 
  78.    --  "len": number of bytes of Val to use 
  79.  
  80.    function Append_Unichar (Self : Gstring; Wc : Gunichar) return Gstring; 
  81.    pragma Import (C, Append_Unichar, "g_string_append_unichar"); 
  82.    --  Converts a Unicode character into UTF-8, and appends it to the string. 
  83.    --  "wc": a Unicode character 
  84.  
  85.    function Append_Uri_Escaped 
  86.       (Self                   : Gstring; 
  87.        Unescaped              : UTF8_String; 
  88.        Reserved_Chars_Allowed : UTF8_String; 
  89.        Allow_Utf8             : Boolean) return Gstring; 
  90.    --  Appends Unescaped to String, escaped any characters that are reserved 
  91.    --  in URIs using URI-style escape sequences. 
  92.    --  Since: gtk+ 2.16 
  93.    --  "unescaped": a string 
  94.    --  "reserved_chars_allowed": a string of reserved characters allowed to be 
  95.    --  used, or null 
  96.    --  "allow_utf8": set True if the escaped string may include UTF8 
  97.    --  characters 
  98.  
  99.    function Ascii_Down (Self : Gstring) return Gstring; 
  100.    pragma Import (C, Ascii_Down, "g_string_ascii_down"); 
  101.    --  Converts all uppercase ASCII letters to lowercase ASCII letters. 
  102.  
  103.    function Ascii_Up (Self : Gstring) return Gstring; 
  104.    pragma Import (C, Ascii_Up, "g_string_ascii_up"); 
  105.    --  Converts all lowercase ASCII letters to uppercase ASCII letters. 
  106.  
  107.    function Assign (Self : Gstring; Rval : UTF8_String) return Gstring; 
  108.    --  Copies the bytes from a string into a Glib.String.Gstring, destroying 
  109.    --  any previous contents. It is rather like the standard strcpy function, 
  110.    --  except that you do not have to worry about having enough space to copy 
  111.    --  the string. 
  112.    --  "rval": the string to copy into String 
  113.  
  114.    function Down (Self : Gstring) return Gstring; 
  115.    pragma Import (C, Down, "g_string_down"); 
  116.    pragma Obsolescent (Down); 
  117.    --  Converts a Glib.String.Gstring to lowercase. 
  118.    --  Deprecated since 2.2, This function uses the locale-specific tolower 
  119.    --  function, which is almost never the right thing. Use 
  120.    --  Glib.String.Ascii_Down or g_utf8_strdown instead. 
  121.  
  122.    function Equal (Self : Gstring; V2 : Gstring) return Boolean; 
  123.    --  Compares two strings for equality, returning True if they are equal. 
  124.    --  For use with GHash_Table. 
  125.    --  "v2": another Glib.String.Gstring 
  126.  
  127.    function Erase 
  128.       (Self : Gstring; 
  129.        Pos  : Gssize; 
  130.        Len  : Gssize) return Gstring; 
  131.    pragma Import (C, Erase, "g_string_erase"); 
  132.    --  Removes Len bytes from a Glib.String.Gstring, starting at position Pos. 
  133.    --  The rest of the Glib.String.Gstring is shifted down to fill the gap. 
  134.    --  "pos": the position of the content to remove 
  135.    --  "len": the number of bytes to remove, or -1 to remove all following 
  136.    --  bytes 
  137.  
  138.    function Free (Self : Gstring; Free_Segment : Boolean) return UTF8_String; 
  139.    --  Frees the memory allocated for the Glib.String.Gstring. If Free_Segment 
  140.    --  is True it also frees the character data. If it's False, the caller 
  141.    --  gains ownership of the buffer and must free it after use with g_free. 
  142.    --  "free_segment": if True, the actual character data is freed as well 
  143.  
  144.    function Hash (Self : Gstring) return Guint; 
  145.    pragma Import (C, Hash, "g_string_hash"); 
  146.    --  Creates a hash code for Str; for use with GHash_Table. 
  147.  
  148.    function Insert 
  149.       (Self : Gstring; 
  150.        Pos  : Gssize; 
  151.        Val  : UTF8_String) return Gstring; 
  152.    --  Inserts a copy of a string into a Glib.String.Gstring, expanding it if 
  153.    --  necessary. 
  154.    --  "pos": the position to insert the copy of the string 
  155.    --  "val": the string to insert 
  156.  
  157.    function Insert_C 
  158.       (Self : Gstring; 
  159.        Pos  : Gssize; 
  160.        C    : Gchar) return Gstring; 
  161.    pragma Import (C, Insert_C, "g_string_insert_c"); 
  162.    --  Inserts a byte into a Glib.String.Gstring, expanding it if necessary. 
  163.    --  "pos": the position to insert the byte 
  164.    --  "c": the byte to insert 
  165.  
  166.    function Insert_Len 
  167.       (Self : Gstring; 
  168.        Pos  : Gssize; 
  169.        Val  : UTF8_String; 
  170.        Len  : Gssize) return Gstring; 
  171.    --  Inserts Len bytes of Val into String at Pos. Because Len is provided, 
  172.    --  Val may contain embedded nuls and need not be nul-terminated. If Pos is 
  173.    --  -1, bytes are inserted at the end of the string. 
  174.    --  Since this function does not stop at nul bytes, it is the caller's 
  175.    --  responsibility to ensure that Val has at least Len addressable bytes. 
  176.    --  "pos": position in String where insertion should happen, or -1 for at 
  177.    --  the end 
  178.    --  "val": bytes to insert 
  179.    --  "len": number of bytes of Val to insert 
  180.  
  181.    function Insert_Unichar 
  182.       (Self : Gstring; 
  183.        Pos  : Gssize; 
  184.        Wc   : Gunichar) return Gstring; 
  185.    pragma Import (C, Insert_Unichar, "g_string_insert_unichar"); 
  186.    --  Converts a Unicode character into UTF-8, and insert it into the string 
  187.    --  at the given position. 
  188.    --  "pos": the position at which to insert character, or -1 to append at 
  189.    --  the end of the string 
  190.    --  "wc": a Unicode character 
  191.  
  192.    function Overwrite 
  193.       (Self : Gstring; 
  194.        Pos  : Gsize; 
  195.        Val  : UTF8_String) return Gstring; 
  196.    --  Overwrites part of a string, lengthening it if necessary. 
  197.    --  Since: gtk+ 2.14 
  198.    --  "pos": the position at which to start overwriting 
  199.    --  "val": the string that will overwrite the String starting at Pos 
  200.  
  201.    function Overwrite_Len 
  202.       (Self : Gstring; 
  203.        Pos  : Gsize; 
  204.        Val  : UTF8_String; 
  205.        Len  : Gssize) return Gstring; 
  206.    --  Overwrites part of a string, lengthening it if necessary. This function 
  207.    --  will work with embedded nuls. 
  208.    --  Since: gtk+ 2.14 
  209.    --  "pos": the position at which to start overwriting 
  210.    --  "val": the string that will overwrite the String starting at Pos 
  211.    --  "len": the number of bytes to write from Val 
  212.  
  213.    function Prepend (Self : Gstring; Val : UTF8_String) return Gstring; 
  214.    --  Adds a string on to the start of a Glib.String.Gstring, expanding it if 
  215.    --  necessary. 
  216.    --  "val": the string to prepend on the start of String 
  217.  
  218.    function Prepend_C (Self : Gstring; C : Gchar) return Gstring; 
  219.    pragma Import (C, Prepend_C, "g_string_prepend_c"); 
  220.    --  Adds a byte onto the start of a Glib.String.Gstring, expanding it if 
  221.    --  necessary. 
  222.    --  "c": the byte to prepend on the start of the Glib.String.Gstring 
  223.  
  224.    function Prepend_Len 
  225.       (Self : Gstring; 
  226.        Val  : UTF8_String; 
  227.        Len  : Gssize) return Gstring; 
  228.    --  Prepends Len bytes of Val to String. Because Len is provided, Val may 
  229.    --  contain embedded nuls and need not be nul-terminated. 
  230.    --  Since this function does not stop at nul bytes, it is the caller's 
  231.    --  responsibility to ensure that Val has at least Len addressable bytes. 
  232.    --  "val": bytes to prepend 
  233.    --  "len": number of bytes in Val to prepend 
  234.  
  235.    function Prepend_Unichar (Self : Gstring; Wc : Gunichar) return Gstring; 
  236.    pragma Import (C, Prepend_Unichar, "g_string_prepend_unichar"); 
  237.    --  Converts a Unicode character into UTF-8, and prepends it to the string. 
  238.    --  "wc": a Unicode character 
  239.  
  240.    function Set_Size (Self : Gstring; Len : Gsize) return Gstring; 
  241.    pragma Import (C, Set_Size, "g_string_set_size"); 
  242.    --  Sets the length of a Glib.String.Gstring. If the length is less than 
  243.    --  the current length, the string will be truncated. If the length is 
  244.    --  greater than the current length, the contents of the newly added area 
  245.    --  are undefined. (However, as always, string->str[string->len] will be a 
  246.    --  nul byte.) 
  247.    --  "len": the new length 
  248.  
  249.    function Truncate (Self : Gstring; Len : Gsize) return Gstring; 
  250.    pragma Import (C, Truncate, "g_string_truncate"); 
  251.    --  Cuts off the end of the GString, leaving the first Len bytes. 
  252.    --  "len": the new size of String 
  253.  
  254.    function Up (Self : Gstring) return Gstring; 
  255.    pragma Import (C, Up, "g_string_up"); 
  256.    pragma Obsolescent (Up); 
  257.    --  Converts a Glib.String.Gstring to uppercase. 
  258.    --  Deprecated since 2.2, This function uses the locale-specific toupper 
  259.    --  function, which is almost never the right thing. Use 
  260.    --  Glib.String.Ascii_Up or g_utf8_strup instead. 
  261.  
  262. end Glib.String;