Skip to content

Instantly share code, notes, and snippets.

@wweir
wweir / j2p
Last active September 20, 2022 07:17
json to protobuf definition transfer tool
#!/usr/bin/env php
<?php
$usage = "usage:\n\t" . $argv[0] . " <path_to_json_file>\n\t<pipe_json_string> | " . $argv[0] . " -\n";
function from_camel_case($input) {
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
$ret = $matches[0];
foreach ($ret as &$match) {
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
}