summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-11 08:48:25 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-19 11:29:34 +0200
commit1d3866a30eea88ff99d4aceda53c4871f61c11c0 (patch)
tree0828740a4ed4603817e9f43594e43e9465fbbb5e
parentspec: Fix item format (diff)
downloadrtems-central-1d3866a30eea88ff99d4aceda53c4871f61c11c0.tar.bz2
content: Add to_camel_case()
-rw-r--r--rtemsspec/content.py11
-rw-r--r--rtemsspec/sphinxcontent.py11
2 files changed, 13 insertions, 9 deletions
diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 74b2b43e..3c28ab66 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -1031,3 +1031,14 @@ def enabled_by_to_exp(enabled_by: Any, mapper: ExpressionMapper) -> str:
if exp.startswith("("):
return exp[1:-1]
return exp
+
+
+_CAMEL_CASE_TO_UPPER = re.compile(r"\s+(.)")
+_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(
+ lambda match: match.group(1).upper(),
+ _CAMEL_CASE_DISCARD.sub(" ", name[1:].replace("+", "X")))
diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py
index 85c7858c..914e2436 100644
--- a/rtemsspec/sphinxcontent.py
+++ b/rtemsspec/sphinxcontent.py
@@ -25,10 +25,9 @@
# POSSIBILITY OF SUCH DAMAGE.
from contextlib import contextmanager
-import re
from typing import Any, Iterable, Iterator, List, Optional, Union
-from rtemsspec.content import Content, make_lines
+from rtemsspec.content import Content, make_lines, to_camel_case
from rtemsspec.items import Item, ItemGetValueContext, ItemMapper
GenericContent = Union[str, List[str], "Content"]
@@ -38,12 +37,6 @@ GenericContentIterable = Union[Iterable[str], Iterable[List[str]],
_HEADER_LEVELS = ["#", "*", "=", "-", "^", "\""]
-def _to_camel_case(name: str) -> str:
- return name[0].upper() + re.sub(
- r"\s+(.)", lambda match: match.group(1).upper(),
- re.sub(r"[^ \t\n\r\f\va-zA-Z0-9]", " ", name[1:].replace("+", "X")))
-
-
def get_reference(label: str, name: Optional[str] = None) -> str:
""" Returns the reference to the specified label. """
if name:
@@ -53,7 +46,7 @@ def get_reference(label: str, name: Optional[str] = None) -> str:
def get_label(name: str) -> str:
""" Returns the label for the specified name. """
- return _to_camel_case(name.strip())
+ return to_camel_case(name.strip())
class SphinxContent(Content):