Re: CString and UTF-8

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



So far as I can tell from the source of GetLength() it simple returns the
number of characters divided by the size of a character (overall) so I'm
guessing it is unreliable and I haven't counted on it for some time to
contain the correct length. Converting strings to UTF-16 (assuming no
surrogates are involved) makes the task a lot easier and CString seems to
know how to work with those strings just fine.

Tom

"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:%232ZkYq1IHHA.780@xxxxxxxxxxxxxxxxxxxxxxx

Mr Asm:

This is what I meant by my previous statement. In this sense, CString does
not understand MBCS with the local code page either.

The only important sense in which CString "supports" MBCS (in ANSI build)
is that if you pass it to an API like SetWindowText() then the OS will
display the string correctly if it is a correct MBCS string in the local
code page. But this is not a property of CString, it is a property of the
OS.

To my knowledge, the only things CString knows about MBCS are

1. It has conversion constructors from UTF-16 that use the local MBCS code
page (a VERY bad feature, IMHO).

2. Methods like CString::Compare() which can return a failure code if
either of the strings is not valid.

Other than that, as Joe says, it's just a container for passing bytes
around. Just like std::string.

David Wilkinson


.



Relevant Pages

  • Re: Is there a Unicode equivalent to ASCIIZ Stings?
    ... I don't use MBCS any more, but CString did provide the correct lengths so ... But whatever that is, it should do it for wide strings also, ...
    (microsoft.public.vc.mfc)
  • Re: CString and UTF-8
    ... Well, what does CString know about MBCS, other than having some (very ... I agree with Tom, about using UTF-8 for external data, and UTF-16 ...
    (microsoft.public.vc.mfc)
  • Re: Starting from the beginning
    ... From what I see, you are mixing code for "generic" strings and functions, which expand to ASCII or UNICODE strings and methods depending on the settings, with ASCII-only methods. ... You are also comparing characters of CipStr (I assume it is declared as CString, since I see no declaration for it) with bytes which would not be right in a UNICODE build. ... /CIP3PreviewImageHeight 726 def ...
    (microsoft.public.vc.mfc)
  • Re: CString and UTF-8
    ... How can it find a multibyte character? ... CString are not that great. ... There are API/members that are locale aware (including MBCS, ...
    (microsoft.public.vc.mfc)
  • Re: Stack getting corrupted
    ... I am still getting some junk in the strings, ... strncpy(sReturn, strData, dwValSize); ... char strData; ... Can I avoid using MFC CString or std::string types here? ...
    (microsoft.public.vc.language)