Questions tagged [gstring]

Groovy String class

gstring is the groovy string class which implements some special features. For example, a gstring may contain code which is executed every time the gstring is converted to a string, for instance when it is output.

http://groovy.codehaus.org/Strings+and+GString

69 questions
1
vote
1 answer

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}" } …
Skarab
  • 6,981
  • 13
  • 48
  • 86
1
vote
1 answer

Easy way to access POJO properties in groovy?

I'm new to groovy and still learning my way around. Is there an easy way to get POJO property values in groovy using dot notation? For example, I have the following POJO: public class MyPOJO { protected String name; public String…
SWS3D
  • 109
  • 9
1
vote
3 answers

segfault in g_slice_alloc

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); …
user434345
  • 299
  • 5
  • 8
1
vote
1 answer

Can pointer returned by malloc be changed

While programming for a personal project I found out that when I was passing a pointer to one function, its value could not be changed. Example: ... GString *buf = NULL; buf = g_string_sized_new(64); somefunc(buf, filename); ... and void…
user1533288
  • 291
  • 3
  • 6
0
votes
2 answers

runtime invocation of method with arguments in groovy

For simplicity let's say I have code similar to this: def testMethod(String txt) { return txt; } public String evaluate(String expression) { //String result = "${testMethod('asdasdasd')}"; String result = "${expression}"; return…
Yuri Dolzhenko
  • 242
  • 2
  • 7
0
votes
1 answer

Groovy "inpsect()" on ArrayList with GString value

There is a job which will run daily to collect some info on Jenkins. For debug, I will print one ArrayList to Jenkins console for possible further debug. So I run inspect() to print it, and find it's not working as expected. If all the elements of…
MadHatter
  • 301
  • 3
  • 12
0
votes
1 answer

Groovy ClassCastException on retieving MongoDB aggregation results

I have a Groovy application that uses MongoDB Java Sync Driver v4.x.x. I've recently upgraded MongoDB from an old v3.4 to new v5.0.12 which requires the new driver mentioned above. The issue I'm having is that any results I return from the database…
ionised
  • 123
  • 1
  • 12
0
votes
1 answer

Groovy StringBuilder append GString performance issue

I have an issue with log4j2 logging. (groovy-all 4.0.0, org.apache.logging.log4j 2.17.1, gmavenplus-plugin 1.13.0) I have a big nested Map object (10 keys and one value is a 100-lengths list of Maps). And I call the log like: Map myNestedMap =…
Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14
0
votes
2 answers

Create GString from String

We're using groovy in a type-safe way. At some point I want to invoke a method with signature void foo(GString baa) As long the String I enter contains some ${baz} everything is fine, but when I use a pure String I get a compile error foo("Hello,…
mibutec
  • 2,929
  • 6
  • 27
  • 39
0
votes
1 answer

Confusing error when trying to create a JSON structure in Groovy

I am trying to create a JSON structure in groovy as such: def builder = new JsonBuilder() builder.configuration { software { name name version version description "description" …
Evil Washing Machine
  • 1,293
  • 4
  • 18
  • 43
0
votes
1 answer

`indexOf` returns unexpected result on list of groovy.Gstrings

When running indexOf on a list of Gstrings, the return value is always -1 despite an expected index match: mystr = "foo" // expect .indexOf to return 0 println "${["${mystr}_bar", "baz"].indexOf("foo_bar")}" // -1 println "${[mystr + "_bar",…
James Baye
  • 43
  • 5
0
votes
0 answers

Parsing Json Strings as GStrings in Groovy

I am trying to parse a Json file in Groovy which contains a List of Strings. Some of these Strings contain GString formatting, and so I hoped to parse these as GStrings instead of normal Strings. For example, the member description in the following…
Batte
  • 15
  • 4
0
votes
2 answers

Not able to compare string entered from Input Dialog with a different string in Groovy

Below is my code: def readln = javax.swing.JOptionsPane.&showInputDialog def env = readln 'Which environment you want to test' I entered input as syst While i am comparing this is what i am doing if("$env".equalsIgnoreCase("syst")){ some…
Ram
  • 59
  • 1
  • 10
0
votes
1 answer

How to generate runtime data using DB stored GString definitions

Hi how can I use database stored GString definitions for dynamically generated data. I was able to use GString for pick and choose row attributes if format is defined in the code code_format = "${-> row.ACCOUNT} ${-> row.ACCOUNT_OWNER}" However…
LSasmazel
  • 21
  • 1
  • 4
0
votes
1 answer

GString performance

If I need plain string in Groovy, does using double-quoted literals make any influence on performance? For instance: def plainString = 'Custom string' def gString = "Custom string" In my understanding, plain String should be faster because during…
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96