I need to get this as a result in the preprocessor definitions of the msvc generator:
MYPATH=\"d:\\;.\\Lib\"
But when I use the following escape sequence in set_source_files_properties:
set_source_files_properties(source.c PROPERTIES COMPILE_FLAGS "-DMYPATH=\\\"d:\\\;.\\\\Lib\\\"")
the generated result is: MYPATH=\"d:\";".\Lib\"
Note the double-quoted semicolon. Is there a quoting workaround to allow unquoted semicolons?
AFAIR, cmake treat ; as list separator, so it behaves in such way for properties as per documentation.
PROPERTY [value1 [value2 ...]
Probably you've better to try something like this - make it string variable and then try substitute it.
set(MY_PATH "\"d:\\\;.\\\\Lib\\\"")
set_source_files_properties(source.c PROPERTIES COMPILE_FLAGS ${MY_PATH})
HTH,
Sergey
Related
Hi I'm trying to dynamically create a atrribute value with Nifi and it looks something like this
$(absolute.path:substringAfterLast('\'):trim)
I'm not able to escape that backslash, is there any workaround to this?
We can achieve this in different ways.
Method1:
Instead of using substringAfterLast function use replaceAll function to get the value after
\ (last backslash).
Use UpdateAttribute processor
add new property as
val
${absolute.path:replaceAll('(.*)(?:\\\\(.*?))+$', '$2'):trim()}
This regex will extract the value after last backslash and replaces the absolute.path attribute value with the extracted value.
(or)
Method2:
Use substringAfterLast + trim functions
${absolute.path:substringAfterLast("\\"):trim()}
This should do: ${absolute.path:substringAfterLast('\\'):trim()}.
Your problem is, that you used () instead of {}, you didn't add () after the trim function and you didn't escape the backslash.
This way works.
To add to Shu's answer:
You can also use the path attribute of your Flowfile to retrieve it's parent directory. If I had
C:\foo\bar\myfile.txt then ${path} will give you bar\
I don't know what you want to do with the substring after the last \ considering how #{absolute.path} gives you C:\something\like\this\
I had the following problem with erb in combination with Puppet, Hiera and templates:
Via Hiera I got the following strings as variables:
First the variable example in an array (data[example])
something with _VARIABLE_ in it
and variable example_information with
some kind of \1 and maybe also a \2
Now I wanted to substitute _VARIABLE_ in a Puppet template with the second string which contains a legit backslash () in it. So I did it like this:
result=data['example'].gsub('_VARIABLE_', #example_information)
So I took example out of an array and filled the placeholder with #example_information.
The result was as follows:
something with some kind of and maybe also a in it
There was no backslash as gsub interpreted them as backreferences. So how can I solve my issue to preserve my backslashes without double escape them in the Hiera file? I need the Hiera variable further in the code without double escaped backslashes.
I now made this to solve that specific problem as follows:
Variable again example
something with _VARIABLE_ in it
and variable example_information with
some kind of \1 and maybe also a \2
Code part in the template:
# we need to parse out any backslashes
info_temp=example_information.gsub('\\', '__BACKSLASH__')
# now we substitute the variables with real data (but w/o backslashes)
result_temp=data['example'].gsub(/__ITEM_NAME__/, info_temp)
# now we put together the real string with backslashes again as before
result=result_temp.gsub('__BACKSLASH__', '\\')
Now the result looks as follows:
something with some kind of \1 and maybe also a \2 in it
Note
Maybe there is a better way to do it but on my research I didn't stumble upon a better solution so please add comments if you know a better way to do it.
I have inherited a cookbook that sets some attributes in the ./attributes/default.rb file as per normal.
However, we have a problem with one of the lines is, which is:
default["obscured"]["mysql"] = "#{node['jboss']['jboss_home']}/modules/com/mysql/jdbc/main"
When run, it write this into the node as:
{}/com/mysql/jdbc/main
I can confirm that the node['jboss']['jboss_home'] attribute exists and has correct values.
So, I cannot see any problem with the above, except that every other declaration of this type in our cookbooks has single quotes on the attribute to be set (i.e. left side), not double quotes. I haven't heard this of as being an issue before, but I am pretty new to chef.
Is there any rule that says they must be single quotes?
The answer is that there is no rule.
Using double-quotes in something like this is completely fine:
default["obscured"]["mysql"] = blah blah
The reason I know that is that I just found one being set, with double quotes, that actually works. :-)
What you have there is fine, how are you confirming the value of node['jboss']['jboss_home'] and how are you using it in the template?
In Ruby single and double quoted literals both become Strings but single quotes are relatively literal while double quotes allow backslash escapes and #{} interpolation.
You are most likely hitting the derived attributes problem:
https://coderanger.net/derived-attributes/
The attribute code in your cookbook is getting parsed before the jboss_home attribute is being set. One way or another the solution is to move the interpolation into recipe code.
You could just use a plain old ruby variable instead of the attribute you are trying to construct -- particularly if nothing else in your system ever sets that attribute.
You also should be able to delete the declaration from your attributes file and use this in recipe code as well:
node.default_unless["obscured"]["mysql"] =
"#{node['jboss']['jboss_home']}/modules/com/mysql/jdbc/main"
Although you need to place that statement early in your run_list, before you ever use node["obscured"]["mysql"] as an argument to any resource.
I have some string like
C:\dev\deploy_test.log
I want by means of Groovy to convert string to
C:/dev/deploy_test.log
I try to perform it with command
Change_1 = Log_file_1.replaceAll('\','/');
It doesn't convert this string
You need to escape the backslash \:
println yourString.replace("\\", "/")
You could also use Groovy's slashy string, which helps reduce the clutter of Java's escape character \ requirements. In this case, you would use:
Change_1 = Log_file_1.replaceAll(/\/,'/');
Slashy strings also support interpolation, and can be multi-line. They're a great tool to add to your expertise.
References
Groovy's syntax documentation
Baeldung's Groovy strings documentation
I'm trying to use a Make substitution reference to alter a string. The problem being that the string happens to contain an equals = symbol.
For example:
INPUT = -switch1 -switch2=potato -switch3
OUTPUT = $(INPUT:-switch2=%=-switch2=turnip)
all:
#echo TEST : $(OUTPUT)
so in the form $(var:a=b), INPUT is var, -switch2=% is a and -switch2=turnip is b.
Obviously that doesn't work because = is a special character in this context, but I've no idea how to make it realize that this is part of string a.
I've tried quoting, backslashes, alternative escape characters and putting -switch2=% in a variable and using that instead. All to no avail.
I know I can use patsubst, but that'd be adding the first non-POSIX extension to the file and i'd prefer to not be that guy.
Any suggestions appreciated!
You'll have to use a full patsubst function. Substitution references are just a shortcut for patsubst:
OUTPUT = $(patsubst -switch2=%,-switch2=turnip,$(INPUT))