PluginSplitMergeCamelCase.py

changeset 20
8b4c08b95279
parent 19
e245c6797cee
child 22
7845a580e12f
diff -r e245c6797cee -r 8b4c08b95279 PluginSplitMergeCamelCase.py
--- a/PluginSplitMergeCamelCase.py	Wed Jan 01 17:30:50 2014 +0100
+++ b/PluginSplitMergeCamelCase.py	Wed Jan 01 19:47:09 2014 +0100
@@ -20,7 +20,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "0.4.0"
+version = "0.5.0"
 className = "SplitMergeCamelCasePlugin"
 packageName = "SplitMergeCamelCase"
 shortDescription = "Split, merge or convert camel case text"
@@ -211,11 +211,12 @@
             return
         
         text = editor.selectedText()
-        newText = re.sub(r"([A-Z])", r" \1", text)
-        if newText.startswith(" "):
-            newText = newText[1:]
-        if newText != text:
-            self.__applyChange(newText, editor)
+        if text:
+            newText = re.sub(r"([A-Z])", r" \1", text)
+            if newText.startswith(" "):
+                newText = newText[1:]
+            if newText != text:
+                self.__applyChange(newText, editor)
     
     def __mergeCamelCase(self):
         """
@@ -226,9 +227,10 @@
             return
         
         text = editor.selectedText()
-        newText = "".join(text.split())
-        if newText != text:
-            self.__applyChange(newText, editor)
+        if text:
+            newText = "".join(text.split())
+            if newText != text:
+                self.__applyChange(newText, editor)
     
     def __camelCaseToUnderscore(self):
         """
@@ -239,11 +241,12 @@
             return
         
         text = editor.selectedText()
-        newText = re.sub(r"([A-Z])", r"_\1", text).lower()
-        if newText.startswith("_"):
-            newText = newText[1:]
-        if newText != text:
-            self.__applyChange(newText, editor)
+        if text:
+            newText = re.sub(r"([A-Z])", r"_\1", text).lower()
+            if newText.startswith("_"):
+                newText = newText[1:]
+            if newText != text:
+                self.__applyChange(newText, editor)
     
     def __underscoreToCamelCase(self, uppercaseFirst=False):
         """
@@ -257,11 +260,12 @@
             return
         
         text = editor.selectedText()
-        newText = "".join([s.capitalize() for s in text.split("_")])
-        if not uppercaseFirst:
-            newText = newText[0].lower() + newText[1:]
-        if newText != text:
-            self.__applyChange(newText, editor)
+        if text:
+            newText = "".join([s.capitalize() for s in text.split("_")])
+            if not uppercaseFirst:
+                newText = newText[0].lower() + newText[1:]
+            if newText != text:
+                self.__applyChange(newText, editor)
     
     def __underscoreToCamelCaseUppercaseFirst(self):
         """

eric ide

mercurial