lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hallo guys,

I've written the following function to test if a string is in camel case, because Lua patterns don't support modifiers on groupings. It works, but as I have little experience with text processing in Lua, I am posting it here to see if someone comes up with a better solution. Thanks!

-- checks if a string is in CamelCase
function isCamelCase(str)
   local count = 0
   local s = string.gsub(str, "(%u%l+)",
                       function(n) count = count + 1 return "" end)

   if count < 2 or s ~= "" then
       return nil
   else
       return not nil
   end
end

-alex