Skip to content
代码片段 群组 项目
提交 109afdda 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Add ability to convert camel case strings to delimited macros.

上级 1019579e
No related branches found
No related tags found
无相关合并请求
......@@ -26,7 +26,8 @@ const bin = require('../util/bin.js')
*/
/**
* Formats label as a C macro.
* Formats label as a C macro. This method performs a very simply substition
* of illegal characters, such as ' ', ':' and such into a '_' character.
*
* @param {*} label
* @returns Label formatted as C macro.
......@@ -39,6 +40,31 @@ function asMacro(label) {
return l
}
/**
* Takes a label, and delimits is on camelcasing.
* For example:
* VerySimpleLabel will turn into VERY_SIMPLE_LABEL
* @param {*} label
*/
function asDelimitedMacro(label) {
var ret = ''
if (label == null) return ret
for (var i = 0; i < label.length; i++) {
var ch = label.charAt(i)
var upch = ch.toUpperCase()
if (ch == upch) {
// uppercase
if (i != 0) ret = ret.concat('_')
ret = ret.concat(ch.toUpperCase())
} else {
// lowercase
ret = ret.concat(upch)
}
}
return ret
}
/**
* Formats label as a C hex constant.
* If value starts as 0x or 0X it is already treated as hex,
......@@ -149,3 +175,4 @@ exports.asHex = asHex
exports.asType = asType
exports.asSymbol = asSymbol
exports.asBytes = asBytes
exports.asDelimitedMacro = asDelimitedMacro
......@@ -4,7 +4,7 @@
// Global, non-cluster-specific things
{{#zcl_global_commands}}
#define ZCL_{{asMacro label}}_COMMAND_ID ({{asHex code}})
#define ZCL_{{asDelimitedMacro label}}_COMMAND_ID ({{asHex code}})
{{/zcl_global_commands}}
{{#zcl_clusters}}
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册