[rtems-central commit] content: Fix to_camel_case()

Sebastian Huber sebh at rtems.org
Tue May 9 13:45:26 UTC 2023


Module:    rtems-central
Branch:    master
Commit:    d51b4e507dc2768930dc75a1e7d9e53e0b618b94
Changeset: http://git.rtems.org/rtems-central/commit/?id=d51b4e507dc2768930dc75a1e7d9e53e0b618b94

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri May  5 14:41:18 2023 +0200

content: Fix to_camel_case()

Make sure the result starts with a valid character.

---

 rtemsspec/content.py            | 5 +++--
 rtemsspec/tests/test_content.py | 7 ++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 9045c890..2b3c33e1 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -1193,9 +1193,10 @@ _CAMEL_CASE_DISCARD = re.compile(r"[^ \t\n\r\f\va-zA-Z0-9]")
 
 def to_camel_case(name: str) -> str:
     """ Returns the name in CamelCase. """
-    return name[0].upper() + _CAMEL_CASE_TO_UPPER.sub(
+    name = _CAMEL_CASE_TO_UPPER.sub(
         lambda match: match.group(1).upper(),
-        _CAMEL_CASE_DISCARD.sub(" ", name[1:].replace("+", "X")))
+        _CAMEL_CASE_DISCARD.sub(" ", name.replace("+", "X")))
+    return f"{name[0].upper()}{name[1:]}"
 
 
 def get_integer_type(value: int) -> str:
diff --git a/rtemsspec/tests/test_content.py b/rtemsspec/tests/test_content.py
index 517bb070..f794c96b 100644
--- a/rtemsspec/tests/test_content.py
+++ b/rtemsspec/tests/test_content.py
@@ -28,7 +28,12 @@ import os
 import pytest
 
 from rtemsspec.content import Content, enabled_by_to_exp, \
-    ExpressionMapper, PythonExpressionMapper
+    ExpressionMapper, PythonExpressionMapper, to_camel_case
+
+
+def test_to_camel_case():
+    assert to_camel_case("/x") == "X"
+    assert to_camel_case("/ab cd?ef+") == "AbCdEfX"
 
 
 def test_tab():



More information about the vc mailing list