2

I would like to output floral formulae by my DSL in groovy, so I need some special symbols such as female sign and Superscripts and Subscripts.

The question is about the Eclipse IDE (Groovy/Grails Tool Suite Version: 3.1.0.RELEASE to develop a grails project) and Groovy console (GroovyStarter)

given this sample groovy statement:

println '♀ Ca\u2075'

I get the expected output in terminal if I run the program from the terminal:

$ groovy Testformula.groovy   
♀ Ca⁵

The same is OK if I run it from the Groovy/Grails Tool Suite as a Java application but if I eighter run it as a Groovy script or in the Groovy console (Groovy starter) I get question mark instead of unicode symbols:

groovy> package org.rondakit.test 
groovy> class Testformula { 
groovy>     static void main(def args) { 
groovy>         println '\u2640' 
groovy>         println '♀ Ca\u2075' 
groovy>     } 
groovy> } 

I get the nasty result:

?
? Ca?

Question: is it possible to configure GroovyStarter or the Groovy Console on GGTS to display unicode symbols?

lepe
  • 24,677
  • 9
  • 99
  • 108
Franco Rondini
  • 10,841
  • 8
  • 51
  • 77
  • Groovy Version: 2.0.5 JVM: 1.7.0_06 Vendor: Oracle Corporation OS: Mac OS X $ Grails version: 2.1.1 – – Franco Rondini Dec 28 '12 at 05:01
  • 1
    It works fine in my box (ubuntu 12.04) under GGTS using "Run as..." either Groovy Console or Groovy Script. Are you sure there isn't any configuration in your ggts? – Will Dec 31 '12 at 12:28
  • @Will P: your comment suggested me to try in another box: then I try on a Windows 7 x64 the same exercise on Groovy/Grails Tool Suite Version: 3.1.0.M1 Build Id: 201209120902 and I get results similar to those previously seen on Mac OSX. 1) "Run as" "Java Application" in OK; 2) "Run as" "Groovy script" give bad output: ? ♀ Ca?; 3) "Run As" "Grovy Console" open the GroovyConsole 1.8.6 but the output was bad ? ? Ca? – Franco Rondini Dec 31 '12 at 15:15
  • @WillP +1: great tip! I investigate my ggts settings with these findings: in "Preferences"->"Workspace" I suspected the "Text File Encoding" set on defalt "Cp1252" then I try to change this setting to "Other: UTF-8" and this solves both problems! if you want post your answer I will be happy to accept ut as a solution. – Franco Rondini Dec 31 '12 at 15:32
  • On the Mac OSX the GGTS default setting of "Text file Encoding" was "US-ASCII" this might explain the small difference ( "? ? Ca?" Vs. "? ♀ Ca?" ) anyway by settings "UTF-8" also solve the problem. – Franco Rondini Dec 31 '12 at 16:07

2 Answers2

7

I found the solution for groovyConsole, You need to put "export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8" to environment variable

Sunti Sireannoi
  • 101
  • 1
  • 3
2

It works fine in my box (ubuntu 12.04) under GGTS using "Run as..." either Groovy Console or Groovy Script. You may want to check configuration in your ggts.

Windows by default runs on cp1252 encoding (we had some troubles with source on wrong encoding in some projects this year). Linux by default is utf-8. I'm not sure about OS X

Will
  • 14,348
  • 1
  • 42
  • 44