What string type do you use in your Ada program?

1

Ada has several types to manage strings. Each of them have different character width.

/// String Wide_String Wide_Wide_String ///

Which of them do you use and why?

Stephane Carrez 2013-02-15 22:52:38

1 answer

0

String contains Character components and can hold text in 8-bit or narrower encodings, e.g. in ASCII. This is a historically first text representation; I would use it for maximum backwards compatibility. It is also the most frugal text representation.

Wide_Wide_String is can contain Wide_Wide_Characters at least 31 bit wide; they cover all Unicode. I would use it to represent multi-lingual text if I am not constraint in memory.

Other intereseting String types are Unbounded_String from Ada.Strings.Unbounded :)

To be exact:

1 An enumeration type is said to be a character type if at least one of its enumeration literals is a character_literal.

2/2 The predefined type Character is a character type whose values correspond to the 256 code positions of Row 00 (also known as Latin-1) of the ISO/IEC 10646:2003 Basic Multilingual Plane (BMP). Each of the graphic characters of Row 00 of the BMP has a corresponding character_literal in Character. Each of the nongraphic positions of Row 00 (0000-001F and 007F-009F) has a corresponding language-defined name, which is not usable as an enumeration literal, but which is usable with the attributes Image, Wide_Image, Wide_Wide_Image, Value, Wide_Value, and Wide_Wide_Value; these names are given in the definition of type Character in A.1, “The Package Standard”, but are set in italics.

3/2 The predefined type Wide_Character is a character type whose values correspond to the 65536 code positions of the ISO/IEC 10646:2003 Basic Multilingual Plane (BMP). Each of the graphic characters of the BMP has a corresponding character_literal in Wide_Character. The first 256 values of Wide_Character have the same character_literal or language-defined name as defined for Character. Each of the graphic_characters has a corresponding character_literal.

3.1/2 The predefined type Wide_Wide_Character is a character type whose values correspond to the 2147483648 code positions of the ISO/IEC 10646:2003 character set. Each of the graphic_characters has a corresponding character_literal in Wide_Wide_Character. The first 65536 values of Wide_Wide_Character have the same character_literal or language-defined name as defined for Wide_Character.

3.2/2 The characters whose code position is larger than 16#FF# and which are not graphic_characters have language-defined names which are formed by appending to the string "Hex_" the representation of their code position in hexadecimal as eight extended digits. As with other language-defined names, these names are usable only with the attributes (Wide_)Wide_Image and (Wide_)Wide_Value; they are not usable as enumeration literals.

From: https://www.adaic.org/resources/add_content/standards/05rm/html/RM-3-5-2.html

Sgrazulis 2025-09-05 08:57:15

  • Syntax for headers
  • !!!! Header 1 # Header 1 = Header 1 =
  • !!! Header 2 ## Header 2 == Header 2 ==
  • !! Header 3 ### Header 3 === Header 3 ===
  • ! Header 4 #### Header 4 ==== Header 4 ====
  • Text style syntax
  • __Bold item__ ''Italic item'' **Bold item** __Italic item__ '''Bold item''' ''Italic item''
  • @@Inline code item@@ `Inline code item`
  • --Strike item-- ++Underline item++ <s>Strike item</s> <u>Underline item</u> <ins>Inserted</ins> <del>Deleted</del>
  • Syntax for lists
  • * Bullet list * Bullet list
  • # Numbered list 1. Numbered list
  • /// <pre>
  • verbatim code block
  • /// ``` </pre>
  • Links and images
  • [Link label | Link URL] [[Link URL | Link label ]] [Link label](Link URL)
  • ((Image link | Image label)) [[Image:Image link | Image label ]] {{Image link | Image label }} ![Link label](Image:Image link)