Hi Jon,
for most of this, see scc's string-guide.html in mozilla/string/doc,
Jon Smirl wrote:
>
> I haven't been following the string API changes for the last couple of
> months and my old code doesn't compile anymore. What is the current accepted
> way for doing:
>
> 1) get a "const nsAReadableString&" into a buffer suitable to pass to the
> OS. My string is Unicode and the OS call wants Unicode too. Does this
> require a copy or is there a trick using nsPromiseFlatString where I can get
> a buffer pointer for the 99.9% of time the string is only in one buffer? I
> was doing this: "(void*)(const PRUnichar*)nsPromiseFlatString(value)"
Your OS has unicode functions? Your buffer in general is simple, and
nsPromiseFlatString won't do any allocations then, IIRC. (Is it still
called Promise?) And then it's a get() on the string, see the string
guide.
I guess you need char*, though. No way to get there without a copy.
>
> 2) I have a PRUnichar* to a string. I want to pass this to a routine that
> takes "const nsAReadableString&". The routine being called is going to copy
> the string so I just want to make a light weight wrapper around the
> PRUnichar*. I was using temp nsLiteralString variables to do this.
>
> 3) Is there a macro for an empty string? I was using this: static
> nsLiteralString static_empty(L"", 0);
L"" isn't portable. Some wchar implementations (solaris) are too wide.
nsLiteralString does the L foo on platforms that support it. IIRC.
>
> 4) I need to return an interface to a constant string. Old code....
> const nsAReadableString& Template::getTemplateName() {
> static nsLiteralString xmlfile(NS_LITERAL_STRING("XMLFile"));
> return xmlfile;
> }
>
> Thanks for the help,
> Jon Smirl
> [EMAIL PROTECTED]