I recently had to translate propkeys.h (in C[++]?) in C#.
My goal was to come from:
DEFINE_PROPERTYKEY(PKEY_Audio_ChannelCount, 0x64440490, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 7);
To:
public static PropertyKey Audio_ChannelCount = new PropertyKey(new Guid("{64440490-4C8B-11D1-8B70-080036B11A03}"));
I was using Notepad++ for the regex, but I'm open to any other scriptable solution (perl, sed...). Please no compiled language (as C#, Java...).
I ended up with this (working):
// TURNS GUID into String
// Find what (Line breaks inserted for convenience):
0x([[:xdigit:]]{8}),\s*0x([[:xdigit:]]{4}),\s*0x([[:xdigit:]]
{4}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]
{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]
{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]{2})
// Replace with:
new Guid\("{$1-$2-$3-$4$5-$6$7$8$9$10$11}"\)
// Final pass
// Find what:
^DEFINE_PROPERTYKEY\(PKEY_(\w+),\s*(new Guid\("\{[[:xdigit:]|\-]+"\)),\s*\d+\);$
// Replace with:
public static PropertyKey $1 = new PropertyKey\($2\);
While this is working, I feel the first pass something odd. I wanted to replace the tons of {2} with just a repeating one. Something like:
(0x([[:xdigit:]]){2},\s*)+
But can't get it to work with groups. Can someone tell me a "standard" way of doing this with regexes ?