LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Condense Mail Headers

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

Print Reply
Mailing list for the LaTeX3 project <[log in to unmask]>
Mon, 17 Oct 2011 16:22:38 +0200
Mailing list for the LaTeX3 project <[log in to unmask]>
text/plain; charset=ISO-8859-1; format=flowed
Lars Hellström <[log in to unmask]>
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