Skip to content

Leedehai/Camel2Snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Camel2Snake

A Python script to convert variable names in camelCase to snake_case using regular expression matching.

Usages:

./camel2snake.py --help

Sanity check examples:

./camel2snake.py --test "CookieData_t data2 = buildCookie(dataPieces, isHTTPOnly_, kDefaultOption);"
# result:
# CookieData_t data_2 = buildCookie(data_pieces, is_http_only_, kDefaultOption);

./camel2snake.py --test "bool bHasAnonymousUsers, authenticationNeeded, useHTTPSChannel;"
# result:
# bool has_anonymous_users, authentication_needed, use_https_channel;

./camel2snake.py --test "net::PacketBuffer *packetBuf = new net::PacketBuffer(memSize_);"
# result:
# net::PacketBuffer *packet_buffer = new net::PacketBuffer(memory_size_);

Prerequisites

macOS or Linux (Windows should be fine, but not tested)
Python2.7+ or Python 3.4+

Motivation

Originally I'm used to using camelCase to name variables in C++. But as I work on the Chromium project I start to appreciate snake_case, for no obvious reason. As a result, I decided to write a script to convert my other projects.

Limitation

Because the conversion is done using regex, there might be errors caused by lack of syntax awareness (see camel2snake.py's comments at the top). A more precise approach is using Clang's Python bindings cindex.
You may check ccindex to see how cindex could be used to parse and extract info from C++ files.

EOF

About

Variable names in C++: camelCase to snake_case (why? I like Chromium!)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages