From 4b3ca1f6798e5fac3fdd16c3437a4cb1b124da77 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Thu, 21 Mar 2019 10:53:51 +0100 Subject: [PATCH] fix(script/gen_constants_cpp): do not insert '_' between two upper case letters --- script/gen_constants_cpp.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/script/gen_constants_cpp.py b/script/gen_constants_cpp.py index bb8152d7c8..6f1c8f36a6 100755 --- a/script/gen_constants_cpp.py +++ b/script/gen_constants_cpp.py @@ -13,32 +13,16 @@ # This script is used to generate src/library/constants.cpp and src/library/constants.h import sys import os +import re def error(msg): print("Error: %s" % msg) exit(1) def to_c_const(s): - out = "" - first = True - for c in s: - if c == '.': - out += '_' - first = True - elif c == '_': - out += '_' - first = False - elif c.isalpha() or c.isdigit(): - if c.isupper(): - if not first: - out += "_" - out += c.lower() - else: - out += c - first = False - else: - error("unsupported character in constant: %s" % s) - return out + # insert '_' instead of '.' and between lower case and upper case + s = re.sub(r"\.|(?<=[a-z0-9])(?=[A-Z])", '_', s) + return s.lower() def main(argv=None): if argv is None: