0

I'm writing a GUI for a C++ backend, and the backend at some point requires a string containing a format specifier. The java frontend needs to replicate the behaviour of the backend by reading in numerical values using the same format specifier string. I'm just wondering if anyone has solved this problem. 1hr of google searches so far hasn't revealed any easy answers, and it's increasingly looking probable that I'll have to write my own custom code to handle this...

Thanks.

queenbee
  • 155
  • 1
  • 7
  • What's your format specifier string? – C.B. Apr 08 '14 at 16:41
  • Any - the user of my GUI will specify the ...um... specifier. – queenbee Apr 08 '14 at 16:43
  • It would be very helpful to provide an example, the expected/desired output, and errors you are receiving. – C.B. Apr 08 '14 at 16:44
  • Is it an option to just expose the C++ formatting code to the gui code? IMO, it'd be ideal to not replicate logic between front and back ends. – Sam Dufel Apr 08 '14 at 16:47
  • @C.B. I haven't written anything yet - I want to avoid having to do something which someone else has already solved. – queenbee Apr 08 '14 at 16:52
  • @Sam If you mean by "expose the formatting code", I assume you mean to convert the C++ formatting code to java? I certainly could do that. I was hoping to avoid that, but i will pursue that if there's no other option :( I agree about not replicating if possible, but it seems necessary in this case. – queenbee Apr 08 '14 at 16:52
  • I think what C.B. means is: what is the format of the format specifier? Regular expression? printf specifier? And I think what Sam means is not to convert the C++ code in java, but rather "call" the C++ code from java. – Djizeus Apr 08 '14 at 16:58
  • Possible solution from Jon Skeet for the variable args. http://stackoverflow.com/questions/2635229/java-variadic-function-parameters. Now all you have to figure out is what to do with %d, %f etc – cup Apr 08 '14 at 17:04
  • I gather that QB wants to READ data using a format string and is wondering if Java reasonably supports that. So am I. – Hot Licks Apr 08 '14 at 17:08
  • @queenbee - not converting the code, but using JNI or similar to include the C++ code in your java. – Sam Dufel Apr 08 '14 at 17:08
  • @Djizeus - printf specifier. Yeah, i could use JNI. That's a good idea! Thanks! – queenbee Apr 08 '14 at 17:17
  • You realize that Java supports the `printf` syntax pretty well, right? – Hot Licks Apr 08 '14 at 18:49

0 Answers0