[ 
https://issues.apache.org/jira/browse/TINKERPOP-2966?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17928210#comment-17928210
 ] 

ASF GitHub Bot commented on TINKERPOP-2966:
-------------------------------------------

andreachild commented on code in PR #3039:
URL: https://github.com/apache/tinkerpop/pull/3039#discussion_r1960656791


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/PythonTranslator.java:
##########
@@ -479,9 +467,28 @@ private SymbolHelper() {
         }
 
         public static String toPython(final String symbol) {
-            // at some point we will want a camel to snake case converter 
here. for now the only step that needs
-            // this conversion is mergeE/V related as the rest still continue 
use in their deprecated forms.
-            return TO_PYTHON_MAP.getOrDefault(symbol, symbol);
+            return TO_PYTHON_MAP.getOrDefault(symbol, 
convertCamelCaseToSnakeCase(symbol));
+        }
+
+        public static String convertCamelCaseToSnakeCase(final String 
camelCase) {
+            if (camelCase == null || camelCase.isEmpty())
+                return camelCase;
+
+            // skip if this is a class/enum indicated by the first letter 
being upper case
+            if (Character.isUpperCase(camelCase.charAt(0)))
+                return camelCase;
+
+            final StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < camelCase.length(); i++) {

Review Comment:
   Instead of looping through each character can you use `replaceAll`?
   
   ```
   return camelCase.replaceAll("([A-Z])", "_$1").toLowerCase();
   ```





> Change PythonTranslator to generate underscore based step naming
> ----------------------------------------------------------------
>
>                 Key: TINKERPOP-2966
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2966
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: translator
>    Affects Versions: 3.5.6
>            Reporter: Stephen Mallette
>            Priority: Minor
>
> The more idiomatic underscore based step naming was introduced a long time 
> ago but the {{PythonTranslator}}} still produces the old camelcase style.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to