zivid / zivid-python

Official Python package for Zivid 3D cameras
BSD 3-Clause "New" or "Revised" License
40 stars 14 forks source link

toSnakeCase could be simplified #91

Closed anordal closed 3 years ago

anordal commented 3 years ago

This should be exactly equivalent:

--- a/src/include/ZividPython/Wrappers.h
+++ b/src/include/ZividPython/Wrappers.h
@@ -18,6 +18,8 @@ namespace ZividPython
 {
     namespace
     {
+        /// Inserts underscore on positive case flank and before negative case flank:
+        /// ZividSDKVersion -> zivid_sdk_version
         std::string toSnakeCase(const std::string upperCamelCase)
         {
             if(upperCamelCase.empty())
@@ -39,20 +41,13 @@ namespace ZividPython
                     auto previous = i - 1;
                     auto next = i + 1;

-                    // if surrounded by capital case (looking at the B character): ABC -> abc
-                    if(isupper(upperCamelCase[previous])
-                       && ((next < upperCamelCase.size() && isupper(upperCamelCase[next]))
-                           || (next >= upperCamelCase.size())))
+                    if(!isupper(upperCamelCase[previous])
+                       || (next < upperCamelCase.size() && !isupper(upperCamelCase[next])))
                     {
-                        ss << char(tolower(upperCamelCase[i]));
-                    }
-                    // all other cases results in adding an underscore first
-                    else
-                    {
-                        ss << "_" << char(tolower(upperCamelCase[i]));
+                        ss << "_";
                     }
+                    ss << char(tolower(upperCamelCase[i]));
                 }
-                // already lower case stays lower case: a -> a
                 else
                 {
                     ss << char(upperCamelCase[i]);
eskaur commented 3 years ago

This is done now, right @anordal ?

anordal commented 3 years ago

Yes, I see it's in master even. Closing.

See StdExt.cpp for how it ended up in SDK.