1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2024 Antmicro
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# SPDX-License-Identifier: Apache-2.0
19
20from typing import Iterable
21from functools import reduce
22from itertools import chain
23
24def split_list(it: Iterable[str], sep: str) -> Iterable[str]:
25    # Splits elements of an iterable and flattens them
26    return chain(*map(lambda s: s.split(sep), it))
27
28def PascalCase(s: str):
29    def pascalize_split(s: str, *separators: str) -> str:
30        splitted = reduce(split_list, separators, [s])
31        return reduce(lambda a, b: a + b, map(str.capitalize, splitted))
32
33    return pascalize_split(s, '_', '-')
34
35def camelCase(s: str):
36    pascal = PascalCase(s)
37    if len(pascal) == 0:
38        return ''
39    if len(pascal) == 1:
40        return pascal[0].lower()
41    return pascal[0].lower() + pascal[1:]
42