A crazy idea for accurately tracking source position

Alix Pexton via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 18 01:06:20 PDT 2014


On 17/04/2014 8:20 PM, matovitch wrote:
> You are doing it all wrong. The easiest way to compute
> the col position is the following :
>
> col_pos = 0;
>
> if (non_tab_character_encounter)
>       col_pos++;
> else
>       col_pos += tab_length - col_pos % tab_length;
>
> That's it.


Tabs can have variable widths, with your technique the end only lines up 
with the desired column if tab_length matches the width of tabs being 
used to display the output, which is at best happenstance.

By constructing a string that matches the pattern of characters that 
precede the column exactly, everything lines up no matter how wide the 
display tabs are.

A...

A...


More information about the Digitalmars-d mailing list