cni converting String args[]

Andrew Haley aph@redhat.com
Fri Dec 10 17:58:00 GMT 2004


Andrew Haley writes:
 > Little-John writes:
 >  > * littlejohn@paranoici.org (littlejohn@paranoici.org) ha scritto:
 >  > > * Andrew Haley (aph@redhat.com) ha scritto:
 >  > > >  >       arguments[i] = (char *) elements(argsElements[i]->getBytes());
 >  > > > 
 >  > > > If you want chars, you'll need an encoding -- elements returns a
 >  > > > jchar*.  Try JvGetStringUTFRegion.
 >  > > 
 >  > >  ok, I'll let you know
 >  > 
 >  > jint A::init(JArray< ::java::lang::String *> *args) {
 >  > 
 >  >   int argc = 0;
 >  >   char* arguments[argc];
 >  > 
 >  >   if (args != NULL) // It's a very bad day otherwise
 >  >   {
 >  >     argc = args->length;
 >  >     arguments[argc];
 >  > 
 >  >     /*
 >  >     * convert the JArray<String*>*  in char**
 >  >     * so in a way suitable for VLC_Init
 >  >     */
 >  >     ::java::lang::String** argsElements = elements(args);
 >  > 
 >  >     for (int i = 0; i < argc; i++) {
 >  >       ::java::lang::System::out->println(argsElements[i]->length());
 >  >       JvGetStringUTFRegion(argsElements[i], 0,
 >  >       argsElements[i]->length(), arguments[i]);
 > 
 > You need memory to put this in:
 > 
 >     len = JvGetStringUTFLength (argsElements[i]);
 >     char s[len];

len+1

 >     JvGetStringUTFRegion(argsElements[i], 0, argsElements[i]->length(), s);
 >     s[len] = 0;

Andrew.



More information about the Java mailing list