Skip to content

Instantly share code, notes, and snippets.

@divinity76
Last active September 5, 2020 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/99d87dc396655b6432d1aae9e8882b7f to your computer and use it in GitHub Desktop.
Save divinity76/99d87dc396655b6432d1aae9e8882b7f to your computer and use it in GitHub Desktop.
<?php
$raw=<<<'RAW'
TEN = 10;
HUNDRED = 100;
THOUSAND = 1000;
MILLION = 1000000;
BILLION = 1000000000;
TRILLION = 1000000000000;
QUADRILLION = 1000000000000000;
QUINTILLION = 1000000000000000000;
INT64_MAX = 9223372036854775807;
UINT64_MAX = 18446744073709551615;
INT32_MAX = 2147483647;
UINT32_MAX = 4294967295;
RAW;
$raw=trim($raw);
foreach(explode("\n",$raw) as $line){
$matches=[];
preg_match('/^(?<name>[a-zA-Z0-9\_]+)\s*\=(?<spaces>\s*)(?<digits>\d+)\;\s*$/',$line,$matches);
$name=$matches["name"];
$number=$matches["digits"];
$spaces=$matches["spaces"];
$name=strtolower($name);
echo "const uint64_t num_{$name} ={$spaces}uint64_t({$number});\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment