Re: Announcing start of WTL10
"'Konstantin Mironovich' [email protected] [wtl]" <[email protected]> Wed, 27 Sep 2017 08:45:36 +0300
| Newsgroups | gmane.comp.windows.wtl |
|---|---|
| Organization | ixbt.com |
| Message-ID | <72F0E8A999734C3094C323EB9A4F3D8D@KLM64> |
------=_NextPart_000_0067_01D3376D.008E6010 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Hi gentlefolks, Nenad, in our project we also use std::wstring and Qt please look at QString http://doc.qt.io/qt-5/qstring.html it has some useful stuff like toStdString(), toStdWString(), etc Konstantin -km ----- Original Message ----- From: Nenad Stefanović [email protected] [wtl] To: [email protected] Sent: Wednesday, September 27, 2017 1:25 AM Subject: Re: [wtl] Announcing start of WTL10 Hi Jim, Thank you for the analysis and suggestions. Your own implementation shows how easy it is to use std::string with WTL without adding any direct support for it. I am still listening to all arguments and suggestions. Cheers, Nenad On Tue, Sep 26, 2017 at 5:41 PM, Jim Barry [email protected] [wtl] <[email protected]> wrote: Hi Nenad, I think it would be good to support std::string. However, it is perhaps not quite as straightforward as it might seem. I have added some std::string support to my local copy of WTL. I strongly adhere to the "UTF-8 Everywhere" philosophy (see http://utf8everywhere.org/) where every std::string is considered to be UTF-8 encoded, and std::wstring is not used except for performing wide/narrow conversions at API boundaries. So, for example, std::string wrappers for Get/SetWindowText look something like this: void SetWindowText(std::string const & text) { SetWindowText(widen(text).c_str()); } std::string GetWindowText() const { ATL::CString str; GetWindowText(str); return narrow(str); } The "get" wrapper delegates to the CString version, partly for convenience, and also because the non-const version of std::string::data() is only available since C++17. I suppose that some people are still going to want to use std::wstring, which presents a difficulty with the "get" wrappers, since functions can't be overloaded on return type. A shim type could be returned (offering user-defined conversions to std::string/wstring) but this approach has some problems. Otherwise, if both std::string and std::wstring support is required, then out-parameters must be used: BOOL SetWindowText(std::string const & text); BOOL SetWindowText(std::wstring const & text); int GetWindowText(std::string & text); int GetWindowText(std::wstring & text); Which, if nothing else, is in keeping with the existing WTL style. This is all assuming a Unicode build. ANSI flavours of WinAPI functions (e.g. GetWindowTextA) don't understand UTF-8 so it makes little sense for Unicode strings to exist in an ANSI build. Thoughts? On 22 September 2017 at 01:27, Nenad Stefanović [email protected] [wtl] <[email protected]> wrote: > > > > Hi Jeff, > > That can be done, depending on how many people are requesting it. Since WTL already uses CString, you can simply copy values from CString to std:string in your code. > > I hope that others can reply to this thread if they think that direct use of std:string/wstring is needed. > > Cheers, > Nenad ------=_NextPart_000_0067_01D3376D.008E6010 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <head> <style type=3D"text/css"> <!-- /* start of attachment style */ .ygrp-photo-title{ clear: both; font-size: smaller; height: 15px; overflow: hidden; text-align: center; width: 75px; } div.ygrp-photo{ background-position: center; background-repeat: no-repeat; background-color: white; border: 1px solid black; height: 62px; width: 62px; } div.photo-title=20 a, div.photo-title a:active, div.photo-title a:hover, div.photo-title a:visited { text-decoration: none;=20 } div.attach-table div.attach-row { clear: both; } div.attach-table div.attach-row div { float: left; /* margin: 2px;*/ } p { clear: both; padding: 15px 0 3px 0; overflow: hidden; } div.ygrp-file { width: 30px; valign: middle; } div.attach-table div.attach-row div div a { text-decoration: none; } div.attach-table div.attach-row div div span { font-weight: normal; } div.ygrp-file-title { font-weight: bold; } /* end of attachment style */ --> </style> </head> =EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Dutf-8" http-equiv=3DContent-Type> <META name=3DGENERATOR content=3D"MSHTML 8.00.6001.19727"></HEAD> <BODY style=3D"BACKGROUND-COLOR: #fff" bgColor=3D#ffffff> <!-- |**|begin egp html banner|**| --> <br><br> <!-- |**|end egp html banner|**| --> <DIV><FONT face=3DCalibri>Hi gentlefolks,</FONT></DIV> <DIV><FONT face=3DCalibri></FONT> </DIV> <DIV><FONT face=3DCalibri>Nenad,</FONT></DIV> <DIV><FONT face=3DCalibri>in our project we also use std::wstring and=20 Qt</FONT></DIV> <DIV><FONT face=3DCalibri>please look at QString <A=20 href=3D"http://doc.qt.io/qt-5/qstring.html">http://doc.qt.io/qt-5/qstring.h= tml</A></FONT></DIV> <DIV><FONT face=3DCalibri>it has some useful stuff like toStdString(),=20 toStdWString(), etc</FONT></DIV> <DIV><FONT face=3DCalibri></FONT> </DIV> <DIV><FONT face=3DCalibri>Konstantin</FONT></DIV> <DIV><FONT face=3DCalibri></FONT> </DIV> <DIV><FONT face=3DCalibri></FONT> </DIV> <DIV><FONT size=3D2>-km<BR></FONT></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: = 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>Fro= m:</B>=20 <A [email protected] href=3D"mailto:[email protected] [wtl]">= Nenad=20 Stefanovi=C4=87 [email protected] [wtl]</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A [email protected]= =20 href=3D"mailto:[email protected]">[email protected]</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, September 27, 201= 7 1:25=20 AM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [wtl] Announcing star= t of=20 WTL10</DIV> <DIV><BR></DIV><SPAN style=3D"DISPLAY: none"> </SPAN>=20 <DIV id=3Dygrp-text> <P> <DIV dir=3Dltr>Hi Jim, <DIV><BR></DIV> <DIV>Thank you for the analysis and suggestions.</DIV> <DIV><BR></DIV> <DIV>Your own implementation shows how easy it is to use std::string with= WTL=20 without adding any direct support for it. I am still listening to all=20 arguments and suggestions.</DIV> <DIV><BR></DIV> <DIV>Cheers,</DIV> <DIV>Nenad</DIV> <DIV><BR></DIV></DIV> <DIV class=3Dgmail_extra><BR> <DIV class=3Dgmail_quote>On Tue, Sep 26, 2017 at 5:41 PM, Jim Barry <A=20 href=3D"mailto:[email protected]">[email protected]</A> [wtl] <SPAN dir=3Dl= tr><<A=20 href=3D"mailto:[email protected]"=20 target=3D_blank>[email protected]</A>></SPAN> wrote:<BR> <BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid" class=3Dgmail_quote><U>= </U> <DIV style=3D"BACKGROUND-COLOR: #fff"><SPAN> </SPAN>=20 <DIV id=3Dm_-455343694678785389ygrp-mlmsg> <DIV id=3Dm_-455343694678785389ygrp-msg> <DIV id=3Dm_-455343694678785389ygrp-text> <P></P> <DIV dir=3Dltr>Hi Nenad,<BR><BR>I think it would be good to support=20 std::string. However, it is perhaps not quite as straightforward as it = might=20 seem.<BR><BR>I have added some std::string support to my local copy of = WTL.=20 I strongly adhere to the "UTF-8 Everywhere" philosophy (see <A=20 href=3D"http://utf8everywhere.org/"=20 target=3D_blank>http://utf8everywhere.org/</A>) where every std::string= is=20 considered to be UTF-8 encoded, and std::wstring is not used except for= =20 performing wide/narrow conversions at API boundaries.<BR><BR>So, for=20 example, std::string wrappers for Get/SetWindowText look something like= =20 this:<BR><BR> <DIV><SPAN style=3D"FONT-FAMILY: monospace,monospace">void=20 SetWindowText(std::string const & text)</SPAN><BR></DIV><FONT=20 face=3D"monospace, monospace">{<BR> =20 SetWindowText(widen(text).c_<WBR>str());<BR>}<BR><BR>std::string=20 GetWindowText() const<BR>{<BR> ATL::CString str;<BR> = =20 GetWindowText(str);<BR> return=20 narrow(str);<BR>}<BR></FONT><BR>The "get" wrapper delegates to the CStr= ing=20 version, partly for convenience, and also because the non-const version= of=20 std::string::data() is only available since C++17.<BR><BR>I suppose tha= t=20 some people are still going to want to use std::wstring, which presents= a=20 difficulty with the "get" wrappers, since functions can't be overloaded= on=20 return type. A shim type could be returned (offering user-defined=20 conversions to std::string/wstring) but this approach has some=20 problems.<BR><BR>Otherwise, if both std::string and std::wstring suppor= t is=20 required, then out-parameters must be used:<BR><BR><FONT=20 face=3D"monospace, monospace">BOOL SetWindowText(std::string const &= ;=20 text);<BR>BOOL SetWindowText(std::wstring const & text);<BR>int=20 GetWindowText(std::string & text);<BR>int GetWindowText(std::wstrin= g=20 & text);</FONT> <DIV><BR></DIV> <DIV>Which, if nothing else, is in keeping with the existing WTL=20 style.</DIV> <DIV><BR></DIV> <DIV>This is all assuming a Unicode build. ANSI flavours of WinAPI func= tions=20 (e.g. GetWindowTextA) don't understand UTF-8 so it makes little sense f= or=20 Unicode strings to exist in an ANSI build. </DIV> <DIV><BR></DIV> <DIV>Thoughts?</DIV><SPAN> <DIV><BR><BR>On 22 September 2017 at 01:27, Nenad Stefanovi=C4=87 <A=20 href=3D"mailto:[email protected]" target=3D_blank>[email protected]= </A>=20 [wtl] <<A href=3D"mailto:[email protected]"=20 target=3D_blank>[email protected]</A>>=20 wrote:<BR>><BR>><BR>><BR>> Hi Jeff,<BR>><BR>> That ca= n be=20 done, depending on how many people are requesting it. Since WTL already= uses=20 CString, you can simply copy values from CString to std:string in your= =20 code.<BR>><BR>> I hope that others can reply to this thread if th= ey=20 think that direct use of std:string/wstring is needed.<BR>><BR>>= =20 Cheers,<BR>> Nenad</DIV></SPAN></DIV> <P></P></DIV> <DIV=20 style=3D"HEIGHT: 0px; COLOR: #fff"></DIV></DIV></DIV></DIV></BLOCKQUOTE><= /DIV><BR></DIV> <P></P></DIV><!-- end group email --> <!-- |**|begin egp html banner|**| --> <br> <br> <!-- |**|end egp html banner|**| --> <div width=3D"1" style=3D"color: white; clear: both;"/>__._,_.___</div> =20=20=20=20=20=20 =20=20 =20=20=20=20 <div id=3D"fromDMARC" style=3D"clear:both; margin-top: 10px;"> <hr style=3D"height:2px ; border-width:0; color:#E3E3E3; backgroun= d-color:#E3E3E3;"> Posted by: "Konstantin Mironovich" <[email protected]>= ; <hr style=3D"height:2px ; border-width:0; color:#E3E3E3; backgrou= nd-color:#E3E3E3;"> </div> <!-- Start Recommendations --> <!-- End Recommendations --> <!-- |**|begin egp html banner|**| --> <img src=3D"http://geo.yahoo.com/serv?s=3D97476590/grpId=3D488621/grpspId= =3D1705006764/msgId=3D16754/stime=3D1506491161" width=3D"1" height=3D"1"> <= br> <!-- |**|end egp html banner|**| --> =20=20=20=20 <!-- |**|begin egp html banner|**| --> <br> =20=20=20 =20=20=20=20=20 =20 <!-- |**|begin egp html banner|**| --> <div id=3D"ygrp-vital" style=3D"background-color: #f2f2f2; font-fam= ily: Verdana; font-size: 10px; margin-bottom: 10px; padding: 10px;"> <span id=3D"vithd" style=3D"font-weight: bold; color: #333; text-tr= ansform: uppercase; "><a href=3D"https://groups.yahoo.com/neo/groups/wtl/in= fo;_ylc=3DX3oDMTJkY3IwNmU2BF9TAzk3MzU5NzE0BGdycElkAzQ4ODYyMQRncnBzcElkAzE3M= DUwMDY3NjQEc2VjA3Z0bARzbGsDdmdocARzdGltZQMxNTA2NDkxMTYx" style=3D"text-deco= ration: none;">Visit Your Group</a></span> <ul style=3D"list-style-type: none; margin: 0; padding: 0; display: in= line;"> </ul> </div> <div id=3D"ft" style=3D"font-family: Arial; font-size: 11px; margin-top: 5p= x; padding: 0 2px 0 0; clear: both;"> <a href=3D"https://groups.yahoo.com/neo;_ylc=3DX3oDMTJjaHBjY3IzBF9TAzk3ND= c2NTkwBGdycElkAzQ4ODYyMQRncnBzcElkAzE3MDUwMDY3NjQEc2VjA2Z0cgRzbGsDZ2ZwBHN0a= W1lAzE1MDY0OTExNjE-" style=3D"float: left;"><img src=3D"http://l.yimg.com/r= u/static/images/yg/img/email/new_logo/logo-groups-137x15.png" height=3D"15"= width=3D"137" alt=3D"Yahoo! Groups" style=3D"border: 0;"/></a> <div style=3D"color: #747575; float: right;"> • <a href=3D"https://i= nfo.yahoo.com/privacy/us/yahoo/groups/details.html" style=3D"text-decoratio= n: none;">Privacy</a> • <a href=3D"mailto:wtl-unsubscribe@yahoogroups.= com?subject=3DUnsubscribe" style=3D"text-decoration: none;">Unsubscribe</a>= • <a href=3D"https://info.yahoo.com/legal/us/yahoo/utos/terms/" style= =3D"text-decoration: none;">Terms of Use</a> </div> </div> <!-- |**|end egp html banner|**| --> </div> <!-- ygrp-msg --> =20=20=20 <br> <!-- |**|end egp html banner|**| --> <div style=3D"color: white; clear: both;"/>__,_._,___</div> </BODY></HTML> ------=_NextPart_000_0067_01D3376D.008E6010--