cpmcgrath / codealignment

http://www.codealignment.com
199 stars 51 forks source link

Aligning floating point numbers in two columns #105

Closed tgalaj closed 2 years ago

tgalaj commented 3 years ago

Hi,

I'd like to align the following code:

const vec2 poisson25[25] = vec2[](
    vec2(-0.978698, -0.0884121),
    vec2(-0.841121, 0.521165),
    vec2(-0.71746, -0.50322),
    vec2(-0.702933, 0.903134),
    vec2(-0.663198, 0.15482),
    vec2(-0.495102, -0.232887),
    vec2(-0.364238, -0.961791),
    vec2(-0.345866, -0.564379),
    vec2(-0.325663, 0.64037),
    vec2(-0.182714, 0.321329),
    vec2(-0.142613, -0.0227363),
    vec2(-0.0564287, -0.36729),
    vec2(-0.0185858, 0.918882),
    vec2(0.0381787, -0.728996),
    vec2(0.16599, 0.093112),
    vec2(0.253639, 0.719535),
    vec2(0.369549, -0.655019),
    vec2(0.423627, 0.429975),
    vec2(0.530747, -0.364971),
    vec2(0.566027, -0.940489),
    vec2(0.639332, 0.0284127),
    vec2(0.652089, 0.669668),
    vec2(0.773797, 0.345012),
    vec2(0.968871, 0.840449),
    vec2(0.991882, -0.657338));

in such a way:

const vec2 poisson25[25] = vec2[](
    vec2(-0.978698,  -0.0884121),
    vec2(-0.841121,   0.521165),
    vec2(-0.71746,   -0.50322),
    vec2(-0.702933,   0.903134),
    vec2(-0.663198,   0.15482),
    vec2(-0.495102,  -0.232887),
    vec2(-0.364238,  -0.961791),
    vec2(-0.345866,  -0.564379),
    vec2(-0.325663,   0.64037),
    vec2(-0.182714,   0.321329),
    vec2(-0.142613,  -0.0227363),
    vec2(-0.0564287, -0.36729),
    vec2(-0.0185858,  0.918882),
    vec2( 0.0381787, -0.728996),
    vec2( 0.16599,    0.093112),
    vec2( 0.253639,   0.719535),
    vec2( 0.369549,  -0.655019),
    vec2( 0.423627,   0.429975),
    vec2( 0.530747,  -0.364971),
    vec2( 0.566027,  -0.940489),
    vec2( 0.639332,   0.0284127),
    vec2( 0.652089,   0.669668),
    vec2( 0.773797,   0.345012),
    vec2( 0.968871,   0.840449),
    vec2( 0.991882,  -0.657338));

I've tried aligning by space, regex, etc. but none of these gave me the result that I want. Is there a way to align these numbers in both columns by "0."?

cpmcgrath commented 2 years ago

Hi, Sorry for the delay. The approach to this would be similar to https://github.com/cpmcgrath/codealignment/wiki/Right-Align with of course https://github.com/cpmcgrath/codealignment/wiki/Chaining-Alignments

The following regex gives me the result you want:

(?<insert>-?0)(?<compare>)