| Newsgroups |
gmane.comp.windows.wtl |
| Message-ID |
<CAK3Hp+8Fsua=42hRX+0FF4e3MN4-Pu9WnNC15d3aNzFgespkJg@mail.gmail.com> |
--f403045ef9065a43d0055a1f28dc
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
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 somethin=
g
> 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 so=
me
> 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] =
[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
>
>=20
>
--f403045ef9065a43d0055a1f28dc
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 Jim,<div><br></div><div>Thank you for the analysis and =
suggestions.</div><div><br></div><div>Your own implementation shows how eas=
y it is to use std::string with WTL without adding any direct support for i=
t. I am still listening to all arguments and suggestions.</div><div><br></d=
iv><div>Cheers,</div><div>Nenad</div><div><br></div></div><div class=3D"gma=
il_extra"><br><div class=3D"gmail_quote">On Tue, Sep 26, 2017 at 5:41 PM, J=
im Barry <a href=3D"mailto:[email protected]">[email protected]</a> [wtl] <sp=
an dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_blank"=
>[email protected]</a>></span> wrote:<br><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
">
<u></u>
=20
<div style=3D"background-color:#fff">
<span style=3D"display:none">=C2=A0</span>
<div id=3D"m_-455343694678785389ygrp-mlmsg">
<div id=3D"m_-455343694678785389ygrp-msg">
<div id=3D"m_-455343694678785389ygrp-text">
=20=20=20=20=20=20
=20=20=20=20=20=20
<p></p><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 seem.<br><br>I have added some std::string support to my local co=
py of WTL. I strongly adhere to the "UTF-8 Everywhere" philosophy=
(see <a href=3D"http://utf8everywhere.org/" target=3D"_blank">http://utf8e=
verywhere.org/</a>) where every std::string is considered to be UTF-8 encod=
ed, and std::wstring is not used except for performing wide/narrow conversi=
ons at API boundaries.<br><br>So, for example, std::string wrappers for Get=
/SetWindowText look something like this:<br><br><div><span style=3D"font-fa=
mily:monospace,monospace">void SetWindowText(std::string const & text)<=
/span><br></div><font face=3D"monospace, monospace">{<br>=C2=A0 =C2=A0 SetW=
indowText(widen(text).c_<wbr>str());<br>}<br><br>std::string GetWindowText(=
) const<br>{<br>=C2=A0 =C2=A0 ATL::CString str;<br>=C2=A0 =C2=A0 GetWindowT=
ext(str);<br>=C2=A0 =C2=A0 return narrow(str);<br>}<br></font><br>The "=
;get" wrapper delegates to the CString version, partly for convenience=
, and also because the non-const version of std::string::data() is only ava=
ilable since C++17.<br><br>I suppose that some people are still going to wa=
nt 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/ws=
tring) but this approach has some problems.<br><br>Otherwise, if both std::=
string and std::wstring support is required, then out-parameters must be us=
ed:<br><br><font face=3D"monospace, monospace">BOOL SetWindowText(std::stri=
ng const & text);<br>BOOL SetWindowText(std::wstring const & text);=
<br>int GetWindowText(std::string & text);<br>int GetWindowText(std::ws=
tring & 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 a=
ssuming a Unicode build. ANSI flavours of WinAPI functions (e.g. GetWindowT=
extA) don't understand UTF-8 so it makes little sense for Unicode strin=
gs to exist in an ANSI build.=C2=A0</div><div><br></div><div>Thoughts?</div=
><span class=3D""><div><br><br>On 22 September 2017 at 01:27, Nenad Stefano=
vi=C4=87 <a href=3D"mailto:[email protected]" target=3D"_blank">nenad2001=
@gmail.com</a> [wtl] <<a href=3D"mailto:[email protected]" target=3D"_=
blank">[email protected]</a>> wrote:<br>><br>><br>><br>> H=
i Jeff,<br>><br>> That can be done, depending on how many people are =
requesting it. Since WTL already uses CString, you can simply copy values f=
rom CString to std:string in your code.<br>><br>> I hope that others =
can reply to this thread if they think that direct use of std:string/wstrin=
g is needed.<br>><br>> Cheers,<br>> Nenad</div></span></div>
<p></p>
</div>
=20=20=20=20=20
=20=20=20=20
<div style=3D"color:#fff;height:0"></div>
</div>
=20=20
</blockquote></div><br></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: =3D?UTF-8?Q?Nenad_Stefanovi=3DC4=3D87?=3D <nenad2001=
@gmail.com> <hr style=3D"height:2px ; border-width:0; color:#E3E=
3E3; 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=3D16753/stime=3D1506464755" 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=3DX3oDMTJkZHBpb2VpBF9TAzk3MzU5NzE0BGdycElkAzQ4ODYyMQRncnBzcElkAzE3M=
DUwMDY3NjQEc2VjA3Z0bARzbGsDdmdocARzdGltZQMxNTA2NDY0NzUy" 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=3DX3oDMTJjZ3RlcXJrBF9TAzk3ND=
c2NTkwBGdycElkAzQ4ODYyMQRncnBzcElkAzE3MDUwMDY3NjQEc2VjA2Z0cgRzbGsDZ2ZwBHN0a=
W1lAzE1MDY0NjQ3NTU-" 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>
--f403045ef9065a43d0055a1f28dc--