【发布时间】:2018-02-15 15:53:40
【问题描述】:
我需要一个 sed 脚本来自动将 C 函数转换为小写蛇形。
到目前为止,我所拥有的是以下内容,它将用下划线分隔驼峰式单词,但它不会小写它们并且会影响所有内容。
sed -i -e 's/\([a-z0-9]\)\([A-Z]\)/\1_\L\2/g' `find source/ -type f`
如何使其仅适用于函数? IE。仅在后跟字符 '(' 的字符串上。
另外,我需要什么使字符串变为小写?
例如,如果我有这个代码:
void destroyPoolLender(PoolLender *lender)
{
while (!isListEmpty(&lender->pools)) {
MemoryPool *myPool = listPop(&this->pool);
if (pool->inUse) {
logError("%s memory pool still in use. Pool not released.", pool->lenderName);
} else {
free(pool);
}
}
listDestroy(&this->pool);
}
转换后应该是这样的:
void destroy_pool_lender(PoolLender *lender)
{
while (!is_list_empty(&lender->pools)) {
MemoryPool *myPool = list_pop(&this->pool);
if (pool->inUse) {
log_error("%s memory pool still in use. Pool not released.", pool->lenderName);
} else {
free(pool);
}
}
list_destroy(&lender->pools);
}
注意 myPool 是如何保持不变的,因为它不是函数名。
【问题讨论】:
-
我认为您应该通过管道输出
sed并使用tr将其变为小写。 -
发布输入数据和预期结果
-
输入数据是一个大约 70k 行代码的 C 代码库,其函数以驼峰式风格编写。预期的结果是那些转换为小写蛇形样式的函数。其余代码不得触碰。
标签: function sed case-conversion