REALstring to char

Hello again,

I’ve a new question pertaining the converstion from a REALstring to a char. The other way is documentated but this is driving me crazy.

In REALplugin.h:

[code]struct REALstringData {
/** The bytes of the string in the required encoding. */
const void *data;

/** The length of the data, in bytes. */
size_t length;

/** The encoding of the data.
* This will always match what was passed to REALGetStringData and is
* included here for convenience.
uint32_t encoding;

const void *private1;
uint32_t private2;


I thought about translating a REALstring to a REALstringData and acccess the data-field in known ASCII-format. This seems a little bit an extra-way and does not work as excepted.

Is there a simplier way to access a REALstring in a known format (ASCII) a convert it to a char*?

Thank you,

Please check REALGetStringContents function.

First I tried this, but it was marked to be deleted in a future version.

Well, maybe REALGetStringData than?

That is the problem I wrote about above: This routine only writes to a REALStringData and not to a char.

That is not the problem.
The problem is you :wink:

The REALstringData contains a data pointer which is your char* pointer.

May I quote myself:

So my question was, if there was an easier way to do this…

And an answer to this like: You are the problem is not a nice one, or?

Sorry. Sometimes I am a problem, too.

REALstringData is the best way to go.
You ask the Xojo runtime to provide the text in a given encoding and put it in REALstringData.
That may do conversion, but most often just copies the internal pointer to the data structure.
You can use it and later call the dispose method.

Are you sure? REALGetStringContents is not listed as REAL_DEPRECATED. And I prefer this one over all others. Don’t need to maintain and handle REALstringData or REALTextData to dispose it at a later time. The REALunlockString is your friend and the true upshot is that you can put it into a variant, use the variant to change it to a REALtext etc.

Yeah, I’ld also prefer this one, because it does not produce so much overhead.

From Current Xojo (r4.1), in Plugin SDK String Reference.html#REALGetStringContents:

I still use REALGetStringContents to get a pointer to the internal data in whatever encoding it is.

This is ok, but from the viewpoint of an energy saving (or economic) programmer i must insist that wittingly using functions marked as “highly” deprecated is a little bit ‘unefficient’

[quote=314307:@G. Deppendorf]Yeah, I’ld also prefer this one, because it does not produce so much overhead.

From Current Xojo (r4.1), in Plugin SDK String Reference.html#REALGetStringContents:[/quote]

Check out the rb_plugin_deprecated.h; not sure if the docs are representative. If this were to be deprecated then it becomes a pain in the but. For example REALstring Text_To_String(REALtext str) { REALtextData* data = REALGetTextData(str, "UTF-8", false); REALstring ret = REALBuildString((const char *)data->data, data->size, kREALTextEncodingUTF8); REALDisposeTextData(data); return ret; }
Does not give something I can work with. Perhaps the encoding string is incorrect. Tried a couple of times but to no avail. The one that truly works is: REALstring Introspection_Text_To_String(REALtext text) { REALobject obj = REALNewVariantText(text); REALstring value = 0; assert(REALGetPropValueString(obj, "StringValue", &value)); REALUnlockObject(obj); return value; }

I really do not understand the proposed changes by giving us copies of text and string data, since it can be done through the dynamic access api’s, letting the Xojo framework handle this through the REALUnlock api’s.

“utf-8” and “us-ascii” work here for encoding strings.