Re: substr() - copying or not copying, that is here the question.

Liste des GroupesRevenir à cl awk 
Sujet : Re: substr() - copying or not copying, that is here the question.
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.awk
Date : 01. Jun 2025, 14:27:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <101hkfn$24hd5$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 01.06.2025 14:06, Kenny McCormack wrote:
In article <101hecq$22ab2$1@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
...
An alternative (depending on the context) would be to consider an
extension that provides an index function with a third argument giving
the initial offset.  I've not looked at how extensions get access to
GAWK strings, so this many not be as easy as it sounds, but I would
guess that it might be relatively simple to do.
>
This, first of all, sounds like a good idea! It would make it
unnecessary to (mis-)use the substr() function as (sort of) a
costly copying-descriptor.[*]
>
I'm unsure about using an extension here. Would there be a name
clash between an built-in index(haystack,needle) function and an
extension index(haystack,needle,start) function? Should they be
separate functions in the first place? (I don't think so.)
 
Nobody is talking about changing the index() built-in function.

Well, I was.

asort(source [, dest [, how ] ])
gensub(regexp, replacement, how [, target])
gsub(regexp, replacement [, target])
match(string, regexp [, array])
patsplit(string, array [, fieldpat [, seps ] ])
split(string, array [, fieldsep [, seps ] ])
substr(string, start [, length ])  # already standard Awk
close(filename [, how])
mktime(datespec [, utc-flag ])
strftime([format [, timestamp [, utc-flag] ] ])

...there are already standard Awk functions (sensibly!) extended by
optional arguments, and also GNU Awk specific functions that either
have from the beginning optional arguments or got extended later.

 
This would be a brand new function, written as an extension library.
 
You could name it something like index_ex() if you like, or you could give
it a brand new name (**).

None of that I'd find a good solution given the existence of index().
(YMMV.)

[...]
 
(**) My conception of how this would be implemented would handle the
"start"-only case (just add the offset to the "haystack" arg of strstr() -
with error checking to make sure it doesn't overflow, of course).
Implementing "end" would be a bit trickier (but not much).

Yes, I'd second that.

Janis


Date Sujet#  Auteur
31 May 25 * substr() - copying or not copying, that is here the question.18Janis Papanagnou
31 May 25 `* Re: substr() - copying or not copying, that is here the question.17Mack The Knife
31 May 25  +* Re: substr() - copying or not copying, that is here the question.15Janis Papanagnou
1 Jun 25  i+* Re: substr() - copying or not copying, that is here the question.8Ben Bacarisse
1 Jun 25  ii+* Re: substr() - copying or not copying, that is here the question.3Janis Papanagnou
1 Jun 25  iii`* Re: substr() - copying or not copying, that is here the question.2Kenny McCormack
1 Jun 25  iii `- Re: substr() - copying or not copying, that is here the question.1Janis Papanagnou
1 Jun 25  ii`* Re: substr() - copying or not copying, that is here the question.4Kenny McCormack
1 Jun 25  ii `* Re: substr() - copying or not copying, that is here the question.3Janis Papanagnou
1 Jun 25  ii  `* Re: substr() - copying or not copying, that is here the question.2Kenny McCormack
7 Jun 25  ii   `- Re: substr() - copying or not copying, that is here the question.1Janis Papanagnou
3 Jun 25  i`* Re: substr() - copying or not copying, that is here the question.6Mack The Knife
3 Jun 25  i +- Re: substr() - copying or not copying, that is here the question.1Kenny McCormack
7 Jun 25  i `* Re: substr() - copying or not copying, that is here the question.4Janis Papanagnou
8 Jun 25  i  `* Re: substr() - copying or not copying, that is here the question.3Mack The Knife
11 Jun 25  i   `* Re: substr() - copying or not copying, that is here the question.2Janis Papanagnou
11 Jun 25  i    `- Meta chat (Was: substr() - copying or not copying, that is here the question.)1Kenny McCormack
1 Jun 25  `- Re: substr() - copying or not copying, that is here the question.1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal