gstring

Unsafe use of user-supplied GString:s in Groovy/Grails

The GString concept in Groovy is pretty powerful (see http://groovy.codehaus.org/Strings+and+GString). GStrings let you do things like: world = "World" println "Hello ${world}" # Output: Hello World println "1+2 = ${1+2}" # Output: 1+2 = 3 println "${System.exit(-1)}" # Program terminated I'm trying to figure out if using Groovy GStr...

GStrings in Python

Groovy has a concept of GStrings. I can write code like this: def greeting = 'Hello World' println """This is my first program ${greeting}""" I can access the value of a variable from within the String. How can I do this in Python? -- Thanks ...

Replace GString tags in a file

Hello, i've got a word document saved in xml format. In this document, there are some GString Tag like $name. In my groovy code, i load the xml file to replace this GString tag like this: def file = new File ('myDocInXml.xml') def name = 'myName' file.eachLine { line -> println line } But it doesn't works. The G...

Groovy GString issues

Hi, All! I'm want use $ macro in groovy GString. When i'm wrote this code ['cdata','tdata'].each { def sql = "select * from $it_1" } i'm get error unknown property $it_ ok, i'm rewrite it ['cdata','tdata'].each { def sql = "select * from ${it}_1" } then i'm get unwanted quotes in result string - "select * from 'cdata'_1" ...

Why doesn't .collect() work in the following GString?

This works as expected in a GSP-page: <td>${Foo.findAllByBar(bar)}</td> But when adding a collect statement the code breaks .. <td>${Foo.findAllByBar(bar).collect { it.name }}</td> with Error 500: Could not parse script [...gsp]: startup failed, ...: 129: expecting '}', found ')' @ line 129, column 196. 1 error`. I wa...

How to execute functions in gstring database queries for groovy

I am hoping to use Groovy more as a functional language than I can with Java, but one area that seems to be a problem is when I call to a stored procedure, as I am passing perhaps 40 parameters in a single call, but, I also need to do some prep work, at the moment before I even call. So, for example, I need a time stamp, so I will have ...

Why a concatenation of gstrings returned from a function is an empty string - Groovy 1.7.4

I have the following code: public class TestGr { static String aaa = "wwww"; public static void main(args) { println "["+getAAA()+"]"; println "[" + getBBB() +"]"; } static String getAAA() { return "" + "${aaa}" } static String getBBB() { return "" + "${aaa}" } } The output of this code is:...

How to avoid saying "gstring"?

I am picking up Groovy. The language is fine. But I have a non-technical problem. One of the classes is called GString. In some context, it can be misleading. And mentioning it is not very appropriate in the office, especially when some non-technical female colleagues are around. I guess this is not enough to justify renaming the class ...