[tor-commits] [stem/master] Minor improvement to to_camel_case() function
atagar at torproject.org
atagar at torproject.org
Thu Jan 3 16:47:15 UTC 2013
commit 0439570531bb909ba85b9b4ede4070e96994083d
Author: Damian Johnson <atagar at torproject.org>
Date: Wed Jan 2 20:21:33 2013 -0800
Minor improvement to to_camel_case() function
On reflection arm has a better function signature than us for to_camel_case().
Adopting it.
---
stem/util/str_tools.py | 9 +++++----
test/unit/util/str_tools.py | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index 776ed48..ca4f44d 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -44,7 +44,7 @@ TIME_UNITS = (
(1.0, "s", " second"),
)
-def to_camel_case(label, word_divider = " "):
+def to_camel_case(label, divider = "_", joiner = " "):
"""
Converts the given string to camel case, ie:
@@ -54,18 +54,19 @@ def to_camel_case(label, word_divider = " "):
'I Like Pepperjack!'
:param str label: input string to be converted
- :param str word_divider: string used to replace underscores
+ :param str divider: word boundary
+ :param str joiner: replacement for word boundaries
:returns: camel cased string
"""
words = []
- for entry in label.split("_"):
+ for entry in label.split(divider):
if len(entry) == 0: words.append("")
elif len(entry) == 1: words.append(entry.upper())
else: words.append(entry[0].upper() + entry[1:].lower())
- return word_divider.join(words)
+ return joiner.join(words)
def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
"""
diff --git a/test/unit/util/str_tools.py b/test/unit/util/str_tools.py
index 84fd850..8c161fb 100644
--- a/test/unit/util/str_tools.py
+++ b/test/unit/util/str_tools.py
@@ -22,7 +22,7 @@ class TestStrTools(unittest.TestCase):
self.assertEquals("Hello", str_tools.to_camel_case("HELLO"))
self.assertEquals("Hello World", str_tools.to_camel_case("hello__world"))
self.assertEquals("Hello\tworld", str_tools.to_camel_case("hello\tWORLD"))
- self.assertEquals("Hello\t\tWorld", str_tools.to_camel_case("hello__world", "\t"))
+ self.assertEquals("Hello\t\tWorld", str_tools.to_camel_case("hello__world", "_", "\t"))
def test_get_size_label(self):
"""
More information about the tor-commits
mailing list