1#!/user/bin/env python 2# 3# Copyright 2019 The Chromium Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7import os 8import re 9import sys 10 11 12def GetScriptName(): 13 return os.path.basename(os.path.abspath(sys.argv[0])) 14 15 16def KCamelToShouty(s): 17 """Convert |s| from kCamelCase or CamelCase to SHOUTY_CASE. 18 19 kFooBar -> FOO_BAR 20 FooBar -> FOO_BAR 21 FooBAR9 -> FOO_BAR9 22 FooBARBaz -> FOO_BAR_BAZ 23 """ 24 if not re.match(r'^k?([A-Z][^A-Z]+|[A-Z0-9]+)+$', s): 25 return s 26 # Strip the leading k. 27 s = re.sub(r'^k', '', s) 28 # Add _ between title words and anything else. 29 s = re.sub(r'([^_])([A-Z][^A-Z_0-9]+)', r'\1_\2', s) 30 # Add _ between lower -> upper transitions. 31 s = re.sub(r'([^A-Z_0-9])([A-Z])', r'\1_\2', s) 32 return s.upper() 33