gstring

segfault in g_slice_alloc

吃可爱长大的小学妹 提交于 2019-12-24 08:28:17
问题 I am calling a function with the following lines: void call_system_command(const char *command_params) { GString *cmd = g_string_sized_new(1024); g_string_append_printf(cmd, "/bin/bash /path/to/my/script '%s'", command_params); system(cmd->str); g_string_free(cmd, TRUE); } I am getting segfault in the line with g_string_sized_new. Backtrace from gdb shows: (gdb) bt #0 0x000000320ce56264 in g_slice_alloc () from /lib64/libglib-2.0.so.0 #1 0x000000320ce5c3db in g_string_sized_new () from /lib64

Groovy String evaluation runtime

孤者浪人 提交于 2019-12-21 21:43:41
问题 Hi I have a String value that is populated runtime and I want to use it to construct another String. static value= '' static construct = "${-> value - '/'}" So when I value = "/www.stackoverflow.com" , construct is equal to "www.stackoverflow.com" but when I do static value= '' static construct = {-> value - '/'} construct is equals to some closure name . I am wondering what is the purpose of this? Why using closure,GString everything is ok? And why when use only closure nothing happens?

Why Map does not work for GString in Groovy?

自闭症网瘾萝莉.ら 提交于 2019-12-17 16:59:29
问题 With the following snippet I cannot retrieve gString from a map: def contents = "contents" def gString = "$contents" def map = [(gString): true] assert map.size() == 1 // Passes assert gString.hashCode() == map.keySet().first().hashCode() // Passes, same hash code assert map[gString] // Fails How on earth is that possible? Assertion message clearly shows that there's something seriously wrong with Groovy: assert map[gString] // Fails | || | |contents | null [contents:true] It's not the same

Groovy: Nested evaluation of variables inside ${}

ε祈祈猫儿з 提交于 2019-12-10 14:20:27
问题 I there a way to do nested evaluation of "$-Strings" in Groovy like, e.g. def obj = {["name":"Whatever", "street":"ABC-Street", "zip":"22222"]} def fieldNames = ["name", "street", "zip"] fieldNames.each{ fieldname -> def result = " ${{->"obj.${fieldname}"}}" //can't figure out how this should look like println("Gimme the value "+result); } Result should be: Gimme the value Whatever Gimme the value ABC-Street Gimme the value 22222 My attempts to solve this either don't give proper results (e.g

Grails accessing nested fields using gstrings

点点圈 提交于 2019-12-07 16:44:39
问题 I am trying to access a nested field using gstring but it throws exception groovy.lang.MissingPropertyException I have two classes Class Person{ Address address } Class Address{ String city } Somewhere in my code I am doing, def person = Person.get(1) def field = "address.city" def city = person."${field}" The line where I am trying to fetch city from person is throwing groovy.lang.MissingPropertyException If I try to fetch a direct property using gstring it works but the above given code

Grails accessing nested fields using gstrings

巧了我就是萌 提交于 2019-12-05 22:42:07
I am trying to access a nested field using gstring but it throws exception groovy.lang.MissingPropertyException I have two classes Class Person{ Address address } Class Address{ String city } Somewhere in my code I am doing, def person = Person.get(1) def field = "address.city" def city = person."${field}" The line where I am trying to fetch city from person is throwing groovy.lang.MissingPropertyException If I try to fetch a direct property using gstring it works but the above given code doesnt work. Any help? What you're doing here is trying to access a property by name address.city which is

String concatenation with Groovy

此生再无相见时 提交于 2019-11-30 10:14:11
问题 What is the best (idiomatic) way to concatenate Strings in Groovy? Option 1: calculateAccountNumber(bank, branch, checkDigit, account) { bank + branch + checkDigit + account } Option 2: calculateAccountNumber(bank, branch, checkDigit, account) { "$bank$branch$checkDigit$account" } I've founded an interesting point about this topic in the old Groovy website: Things you can do but better leave undone. As in Java, you can concatenate Strings with the "+" symbol. But Java only needs that one of

Passing variable to be evaluated in groovy gstring

夙愿已清 提交于 2019-11-30 09:40:05
问题 I am wondering if I can pass variable to be evaluated as String inside gstring evaluation. simplest example will be some thing like def var ='person.lName' def value = "${var}" println(value) I am looking to get output the value of lastName in the person instance. As a last resort I can use reflection, but wondering there should be some thing simpler in groovy, that I am not aware of. 回答1: Can you try: def var = Eval.me( 'new Date()' ) In place of the first line in your example. The Eval

String concatenation with Groovy

梦想的初衷 提交于 2019-11-29 19:30:14
What is the best (idiomatic) way to concatenate Strings in Groovy? Option 1: calculateAccountNumber(bank, branch, checkDigit, account) { bank + branch + checkDigit + account } Option 2: calculateAccountNumber(bank, branch, checkDigit, account) { "$bank$branch$checkDigit$account" } I've founded an interesting point about this topic in the old Groovy website: Things you can do but better leave undone. As in Java, you can concatenate Strings with the "+" symbol. But Java only needs that one of the two items of a "+" expression to be a String, no matter if it's in the first place or in the last

Passing variable to be evaluated in groovy gstring

时光毁灭记忆、已成空白 提交于 2019-11-29 16:29:38
I am wondering if I can pass variable to be evaluated as String inside gstring evaluation. simplest example will be some thing like def var ='person.lName' def value = "${var}" println(value) I am looking to get output the value of lastName in the person instance. As a last resort I can use reflection, but wondering there should be some thing simpler in groovy, that I am not aware of. Can you try: def var = Eval.me( 'new Date()' ) In place of the first line in your example. The Eval class is documented here edit I am guessing (from your updated question) that you have a person variable, and