LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Lars Hellström <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Mon, 17 Oct 2011 16:22:38 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (48 lines)
Bruno Le Floch skrev 2011-10-17 03.36:
> On 10/16/11, Joseph Wright<[log in to unmask]>  wrote:
>> I don't like the name in \str_from_to:nnn - it sounds like a copy
>> function. What's wrong with \str_substr:nnn or just \str_sub:nnn?
>
> I couldn't think of an unambiguous name. \str_substr:nnn is fine.

"range" is a name I'm used to for this (i.e. \str_range:nnn), but you might 
have considered that already.

>> In the same function, the indexing is described as "\meta{start index}
>> (inclusive) and \meta{end index} (exclusive)". This seems very odd to me
>> - I'd expect
>>
>>    \str_from_to:nnn { abcdef } { 1 } { 4 }
>>
>> to leave "bcde" in the input stream.
>
> I followed the python convention, in which you think of the index as
> lying between pairs of characters:
>
> (0)a(1)b(2)c(3)d(4)e(5)f(6)

Since MetaFont does the same thing (unless my memory is playing tricks on 
me), I suppose there is also some TeXy precedence for this. But if applying 
this convention (positions are between characters), it might be preferable 
to make it explicit in the documentation and state the "from (inclusive) to 
(exclusive)" property more as an alternative interpretation of what happens.

> Hence, extracting from 1 to 4 gives "bcd". The advantage of doing it
> that way is that the length of what you get is \(4 - 1\). Another
> advantage is that getting the first<n>  characters is easy:
> \str_substr:nnn {<string>  } { 0 } {<n>  }. A drawback is that getting
> all characters from a given point to the end is \str_substr:nnn {
> <string>  } {<n>  } { \c_max_int } rather than \str_substr:nnn {
> <string>  } {<n>  } { -1 }. Does that make sense?

One thing I'm used to (and find very useful) is writing just "end" for the 
position at the end of the string, "end-1" for the one before that, "end-2" 
for the one before that, etc. In other words,

   \str_substr:nnn { <string> } { <n> } { end }

for what you wrote above. I don't know how hard this would be to implement, 
however; it might not be worth it.

Lars Hellström

ATOM RSS1 RSS2