Re: Converting WideChar/WideString to AnsiChar/AnsiString



On 29 Mai, 14:41, Rob Kennedy <m...@xxxxxxxxxxx> wrote:
ckoegl wrote:
I cannot find anything definitive in the Delphi docs and in the
relevant newsgroups that answers this simple question:

What is the exact definition of the WideChar to AnsiChar conversion
(and in extension of the WideString to AnsiString conversion)?

I suppose that for all WideChar values that are valid AnsiChar values
(i.e. the ones with Ord-values of 0 to 255) are preserved in the
conversion, but what about the rest?

They're truncated, I think. Or it's a range-check error.

Converting a WideString to an AnsiString involves converting the
WideString to the current system code page, but I'm pretty sure that
effort is *not* used for converting WideChar to AnsiChar.

And if that's the case, then the conversion is nonsense. Don't do it.

--
Rob

Ok, in my case I simply cannot dodge the problem: I have (for whatever
reasons) text
data given as WideString and I need to call given procedures/functions
that only accept
String (which in my case means AnsiString). It is entirely acceptable
that some data
ist lost during the WideString to String conversion, but: (1) All
character information that
can be transferred should be transferred, and (2) I need to know quite
exactly what happens
in case unconvertible character data is encountered.

Well, I guess I could simply try out what happens, but I thought that
maybe you
folks already have deeper experience of what pitfalls may lie ahead of
me ...

One valuable information I already got is that the string conversion
is not simply a sequence
of single character conversions.

Thanks,

Christoph
.



Relevant Pages

  • Re: IDE products roadmap updated
    ... I know, we're doing just that, but not having a separate type means its quite easy to have some UTF8 string processed as Ansi at some point, cutting a string at the wrong point, or have the UTF8 converted to WideString as an AnsiString (by Delphi's automated conversion). ...
    (borland.public.delphi.non-technical)
  • Re: Unicode in Delphi: just deprecate WideString/WideChar
    ... conversion between ansistrings and widestrings happens today. ... AnsiString to WideString will use system locale, ...
    (borland.public.delphi.non-technical)
  • Re: Unicode in Delphi/VCL (yet again)
    ... The problem is how does .AsString or .Text know when to handle it as an ANSI and when to handle it as UNICODE? ... What about the performance of WideString vs String? ... This made the conversion smoother too ...
    (borland.public.delphi.non-technical)
  • Re: Converting WideChar/WideString to AnsiChar/AnsiString
    ... What is the exact definition of the WideChar to AnsiChar conversion ... I suppose that for all WideChar values that are valid AnsiChar values ... Converting a WideString to an AnsiString involves converting the WideString to the current system code page, but I'm pretty sure that effort is *not* used for converting WideChar to AnsiChar. ...
    (alt.comp.lang.borland-delphi)
  • Re: what if (f)printf returns EINTR ?
    ... vsnprintf - formatted output conversion ... int fprintf; ... write to the character string str. ...
    (comp.unix.programmer)