A complete, "tested" and working proof of concept!
Pipe the output to a file and load it in an editor that allows you to mess with the size of tabs and no matter what width they have things will still line up (as long as the font is fixed width).
I'm pretty sure this is sub optimal even though I did change from my original design so that there is less going on on the path for characters and spaces which I assume would be the more common case.
A...
=====
import std.stdio;
enum lsb = 0x1L;
enum msb = 0x8000_0000_0000_0000L;
enum max = 0xFFFF_FFFF_FFFF_FFFFL;
struct columnRange
{
private string input;
private ulong pattern;
private long check;
this(string s)
{
input = s;
}
@property bool empty()
{
return input.length == 0;
}
@property string front()
{
return input;
}
columnRange save()
{
return this;
}
void popFront()
{
if (input.length > 0)
{
if (pattern == 0)
{
if (input[0] != 0x09)
{
pattern = ~lsb;
}
else
{
pattern = lsb;
}
input = input[1..$];
++check;
return;
}
pattern <<= 1;
if (input[0] == 0x09)
{
pattern |= lsb;
}
input = input[1..$];
++check;
}
}
@property string indent()
{
if (pattern == 0)
{
return "";
}
if (check >= 64)
{
return "somewhere way way way down there
--->";
}
auto copy = pattern;
auto ret = "";
size_t i;
if ((pattern & msb) == 0)
{
ret ~= "\t";
do
{
copy <<= 1;
++i;
} while ((copy & msb) == 0);
}
else
{
ret ~= " ";
do
{
copy <<= 1;
++i;
} while ((copy & msb) != 0);
}
if (i < 64)
{
copy <<= 1;
++i;
while (i < 64)
{
if ((copy & msb) == 0)
{
ret ~= " ";
}
else
{
ret ~= "\t";
}
copy <<= 1;
++i;
}
}
return ret;
}
}
void main()
{
enum input1 = "1s in input1 \twill have 1 caret directly below them,\t
1 per line, except this 1";
writefln("%s", input1);
auto r1 = columnRange(input1);
while(!r1.empty)
{
if (r1.front[0] == '1')
{
writefln("%s^", r1.indent);
}
r1.popFront;
}
}
