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:

scc:s string docs have information about this I think, but I toss in my 
2 cents anyway.


> 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)"


WideOSFunction(nsPromiseFlatString(value).get);


> 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.


OtherFunction(nsDependantString(string_pointer));


> 3) Is there a macro for an empty string? I was using this: static
> nsLiteralString static_empty(L"", 0);
> 
> 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;
> }


You want to use the NS_NAMED_LITERAL_STRING macro.

/Daniel


Reply via email to