ARNAUD2908
ARNAUD2908

Reputation: 21

Behavior of Ada.Strings.Fixed.Index_Non_Blank

I was thinking that, quite logically according to its name, this function will return the index of the 1st character not being whitespace, that is, among others, not being a space or a tabulation.

However, when testing it on some strings, and also when looking at its implementation (file a-strsea.adb for GNAT 4.7.4), I realized that this function returns in fact the index of the 1st character not being an ordinary space (ASCII 32). This is in my opinion not consistent with what its name could let suppose.

So, where could I find the expected behaviour of this function (apart from looking at the code)? Indeed, in the AARM for Ada 2012, I only found the prototypes, without any semantic information.

Upvotes: 1

Views: 382

Answers (1)

Keith Thompson
Keith Thompson

Reputation: 263337

I agree that the use of the word "Blank" is inappropriate. Elsewhere, the standard defines a "blank" as "a space or a horizontal tabulation character".

The AARM does define the behavior of Ada.Strings.Fixed.Index_Non_Blank:

function Index_Non_Blank (Source : in String;
                          From : in Positive;
                          Going : in Direction := Forward)
    return Natural;

Returns Index (Source, Maps.To_Set(Space), From, Outside, Going);

function Index_Non_Blank (Source : in String;
                          Going : in Direction := Forward)
    return Natural;

Returns Index(Source, Maps.To_Set(Space), Outside, Going)

where Space is Ada.Characters.Latin_1.Space, defined as ' '.

The fact that the standard shows the specification of the Ada.Strings.Fixed index without commentary, followed by the descriptions of the effects of the declared subprograms, might be confusing. Just search the document for Index_Non_Blank, and don't assume all the information about it will be in one place.

Upvotes: 5

Related Questions