| # Copyright (c) 2022 Project CHIP Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import stringcase |
| |
| |
| def normalize_acronyms(s: str) -> str: |
| """Replaces variations of acronyms when converting various words. |
| |
| Specifically when considering how to generate a CONST_CASE constant, |
| strings such as WiFi should not be WI_FI but rather WIFI |
| """ |
| return s.replace('WiFi', 'Wifi').replace('WI_FI', 'WIFI') |
| |
| |
| def RegisterCommonFilters(filtermap): |
| """ |
| Register filters that are NOT considered platform-generator specific. |
| |
| Codegen often needs standardized names, like "method names are CamelCase" |
| or "command names need-to-be-spinal-case" so these filters are often |
| generally registered on all generators. |
| """ |
| |
| # General casing for output naming |
| filtermap['camelcase'] = stringcase.camelcase |
| filtermap['capitalcase'] = stringcase.capitalcase |
| filtermap['constcase'] = stringcase.constcase |
| filtermap['pascalcase'] = stringcase.pascalcase |
| filtermap['snakecase'] = stringcase.snakecase |
| filtermap['spinalcase'] = stringcase.spinalcase |
| |
| filtermap['normalize_acronyms'] = normalize_acronyms |