CFEngine 3.6: new text manipulation functions
The next 3.6 release of CFEngine will offer some text manipulation functions. Their names are explicit enough, but the examples below will make their purposes crystal clear.
- strlen()
- upcase()
- downcase()
- head()
- tail()
# This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 2.0 France License.
# To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/2.0/fr/
# or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
body common control
{
bundlesequence => {
"text_functions"
};
}
bundle agent text_functions
{
vars:
"banana_phone" string => "RING ring ring ring ring ring ring banana phone";
"banana_length" int => strlen("$(banana_phone)");
"banana_upcase" string => upcase("$(banana_phone)");
"banana_downcase" string => downcase("$(banana_phone)");
"banana_reversed" string => reversestring("$(banana_phone)");
"banana_head" string => head("$(banana_phone)", 9);
"banana_tail" string => tail("$(banana_phone)", 12);
reports:
"Test string - $(banana_phone)";
"Length - $(banana_length)";
"Upper case - $(banana_upcase)";
"Lower case - $(banana_downcase)";
"Reversed - $(banana_reversed)";
"First 9 characters - $(banana_head)";
"Last 12 characters - $(banana_tail)";
}
Output was stripped for lisibility:
$ cf-agent -f /home/loic/.cfagent/inputs/text_manipulation.cf
R: Test string - RING ring ring ring ring ring ring banana phone
R: Length - 47
R: Upper case - RING RING RING RING RING RING RING BANANA PHONE
R: Lower case - ring ring ring ring ring ring ring banana phone
R: Reversed - enohp ananab gnir gnir gnir gnir gnir gnir GNIR
R: First 9 characters - RING ring
R: Last 12 characters - banana phone