Re: Announcing start of WTL10

"Jim Barry [email protected] [wtl]" <[email protected]> Tue, 26 Sep 2017 16:41:27 +0100
Newsgroups gmane.comp.windows.wtl
Message-ID <CAHtY=NdLN_FHD5s8Om9iBgS1b7m-qsQ4VYfB51V9V6rDT=ysKA@mail.gmail.com>
--94eb2c06262232f5ff055a1982cc
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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=C4=87 [email protected] [w=
tl] <
[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

--94eb2c06262232f5ff055a1982cc
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>
<html>
<head>
<style type=3D"text/css">
<!--
#ygrp-mkp {
  border: 1px solid #d8d8d8;
  font-family: Arial;
  margin: 10px 0;
  padding: 0 10px;
}

#ygrp-mkp hr {
  border: 1px solid #d8d8d8;
}

#ygrp-mkp #hd {
  color: #628c2a;
  font-size: 85%;
  font-weight: 700;
  line-height: 122%;
  margin: 10px 0;
}

#ygrp-mkp #ads {
  margin-bottom: 10px;
}

#ygrp-mkp .ad {
  padding: 0 0;
}

#ygrp-mkp .ad p {
  margin: 0;
}

#ygrp-mkp .ad a {
  color: #0000ff;
  text-decoration: none;
}
-->
</style>
</head>
<body>



<!-- |**|begin egp html banner|**| -->

<br><br>

<!-- |**|end egp html banner|**| -->


<div dir=3D"ltr">Hi Nenad,<br><br>I think it would be good to support std::=
string. However, it is perhaps not quite as straightforward as it might see=
m.<br><br>I have added some std::string support to my local copy of WTL. I =
strongly adhere to the &quot;UTF-8 Everywhere&quot; philosophy (see <a href=
=3D"http://utf8everywhere.org/">http://utf8everywhere.org/</a>) where every=
 std::string is considered to be UTF-8 encoded, and std::wstring is not use=
d except for performing wide/narrow conversions at API boundaries.<br><br>S=
o, for example, std::string wrappers for Get/SetWindowText look something l=
ike this:<br><br><div><span style=3D"font-family:monospace,monospace">void =
SetWindowText(std::string const &amp; text)</span><br></div><font face=3D"m=
onospace, monospace">{<br>=C2=A0 =C2=A0 SetWindowText(widen(text).c_str());=
<br>}<br><br>std::string GetWindowText() const<br>{<br>=C2=A0 =C2=A0 ATL::C=
String str;<br>=C2=A0 =C2=A0 GetWindowText(str);<br>=C2=A0 =C2=A0 return na=
rrow(str);<br>}<br></font><br>The &quot;get&quot; wrapper delegates to the =
CString version, partly for convenience, and also because the non-const ver=
sion of std::string::data() is only available since C++17.<br><br>I suppose=
 that some people are still going to want to use std::wstring, which presen=
ts a difficulty with the &quot;get&quot; wrappers, since functions can&#39;=
t be overloaded on return type. A shim type could be returned (offering use=
r-defined conversions to std::string/wstring) but this approach has some pr=
oblems.<br><br>Otherwise, if both std::string and std::wstring support is r=
equired, then out-parameters must be used:<br><br><font face=3D"monospace, =
monospace">BOOL SetWindowText(std::string const &amp; text);<br>BOOL SetWin=
dowText(std::wstring const &amp; text);<br>int GetWindowText(std::string &a=
mp; text);<br>int GetWindowText(std::wstring &amp; text);</font><div><br></=
div><div>Which, if nothing else, is in keeping with the existing WTL style.=
</div><div><br></div><div>This is all assuming a Unicode build. ANSI flavou=
rs of WinAPI functions (e.g. GetWindowTextA) don&#39;t understand UTF-8 so =
it makes little sense for Unicode strings to exist in an ANSI build.=C2=A0<=
/div><div><br></div><div>Thoughts?</div><div><br><br>On 22 September 2017 a=
t 01:27, Nenad Stefanovi=C4=87 <a href=3D"mailto:[email protected]">nenad=
[email protected]</a> [wtl] &lt;<a href=3D"mailto:[email protected]">wtl@yah=
oogroups.com</a>&gt; wrote:<br>&gt;<br>&gt;<br>&gt;<br>&gt; Hi Jeff,<br>&gt=
;<br>&gt; 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.<br>&gt;<br>&gt; I hope that others can reply to t=
his thread if they think that direct use of std:string/wstring is needed.<b=
r>&gt;<br>&gt; Cheers,<br>&gt; Nenad</div></div>




<!-- |**|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: Jim Barry &lt;[email protected]&gt;         <hr style=3D=
"height:2px ; border-width:0; color:#E3E3E3; background-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=3D16752/stime=3D1506461465" width=3D"1" height=3D"1"> <=
br>

<!-- |**|end egp html banner|**| -->

=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=3DX3oDMTJkNXZvOTduBF9TAzk3MzU5NzE0BGdycElkAzQ4ODYyMQRncnBzcElkAzE3M=
DUwMDY3NjQEc2VjA3Z0bARzbGsDdmdocARzdGltZQMxNTA2NDYxNDYx" 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=3DX3oDMTJjOXZoYjZ1BF9TAzk3ND=
c2NTkwBGdycElkAzQ4ODYyMQRncnBzcElkAzE3MDUwMDY3NjQEc2VjA2Z0cgRzbGsDZ2ZwBHN0a=
W1lAzE1MDY0NjE0NjU-" 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;"> &bull; <a href=3D"https://i=
nfo.yahoo.com/privacy/us/yahoo/groups/details.html" style=3D"text-decoratio=
n: none;">Privacy</a> &bull; <a href=3D"mailto:wtl-unsubscribe@yahoogroups.=
com?subject=3DUnsubscribe" style=3D"text-decoration: none;">Unsubscribe</a>=
 &bull; <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>

--94eb2c06262232f5ff055a1982cc--