Menu

AVR.Strings Log in to Edit

Package AVR.Strings

The AVR.Strings package defines a space saving string type for AVR platforms where memory space is limited. Type AVR_String differs from the standard string in that the array index is type Unsigned_8 instead of the 16-bit Positive type.

package AVR.Strings is
   pragma Pure;

   Space : constant Character := ' ';

   type AVR_String is array (Unsigned_8 range <>) of Character;

   --  some string subtypes with predefined length.

   subtype AStr2  is AVR_String (1 ..  2);
   subtype AStr3  is AVR_String (1 ..  3);
   subtype AStr4  is AVR_String (1 ..  4);
   subtype AStr5  is AVR_String (1 ..  5);
   subtype AStr6  is AVR_String (1 ..  6);
   subtype AStr7  is AVR_String (1 ..  7);
   subtype AStr8  is AVR_String (1 ..  8);
   subtype AStr9  is AVR_String (1 ..  9);
   subtype AStr10 is AVR_String (1 .. 10);
   subtype AStr11 is AVR_String (1 .. 11);
   subtype AStr12 is AVR_String (1 .. 12);
   subtype AStr13 is AVR_String (1 .. 13);
   subtype AStr14 is AVR_String (1 .. 14);
   subtype AStr15 is AVR_String (1 .. 15);
   subtype AStr16 is AVR_String (1 .. 16);
   subtype AStr17 is AVR_String (1 .. 17);
   subtype AStr18 is AVR_String (1 .. 18);
   subtype AStr19 is AVR_String (1 .. 19);
   subtype AStr20 is AVR_String (1 .. 20);
   subtype AStr100 is AVR_String (1 .. 100);

   --  Progmem_String and PStr are not part of the ARM.

   type Progmem_String is new AVR_String;
   pragma Linker_Section (Progmem_String, ".progmem.data");

   subtype PStr is Progmem_String;

   type Alignment  is (Left, Right, Center);

   type Truncation is (Left, Right);
   type Membership is (Inside, Outside);
   type Direction  is (Forward, Backward);
   type Trim_End   is (Left, Right, Both);

end AVR.Strings;

AVR_String Type

From it's definition, you can see that an AVR_String is the same as an Ada string, except that it's array index is Unsigned_8 instead of the 16-bit Positive type. This saves 2-bytes for each string because of the lower and upper bounds maintained for each string.

type AVR_String is array (Unsigned_8 range <>) of Character;

Progmem_String Type

The Progmem_String is an AVR_String that resides in the program's EPROM memory instead of precious SRAM.

type Progmem_String is new AVR_String;
pragma Linker_Section (Progmem_String, ".progmem.data");

The type PStr is a subtype of Progmem_String, which acts as an abbreviated name for the same string type. It matches the name used in AVR-libc

subtype PStr is Progmem_String;

Exceptions

The exceptions:

  • Length_Error
  • Pattern_Error
  • Index_Error
  • Translation_Error

are part of Ada.Strings, but are not included here.

Truncation Type

Normally Truncation is declared as follows:

type Truncation is (Left, Right, Error);

but Error has not been included here.

Child Packages


Related

Wiki: AVR.Strings.C
Wiki: AVR.Strings.Maps.Constants
Wiki: AVR.Strings.Maps
Wiki: AVR.Strings.Pstring
Wiki: AVR.Strings.Search
Wiki: Strings

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.