1- // Copyright(c) 1999-2022 aslze
1+ // Copyright(c) 1999-2023 aslze
22// Licensed under the MIT License (http://opensource.org/licenses/MIT)
33
44#ifndef ASL_STRING_H
@@ -95,7 +95,7 @@ characters transparently.
9595
9696~~~
9797String dirName = "Mis imágenes" // this is UTF-8
98- CreateDirectoryW( dirName ); // this gets converted to UTF-16 LPWSTRING
98+ CreateDirectoryW( dirName ); // this gets converted to UTF-16 LPCWSTR
9999~~~
100100
101101There are automatic conversions to/from many basic types, but please use with care!
@@ -336,7 +336,8 @@ class ASL_API String
336336 /* *
337337 Returns true if this string is not empty (warning: this might change in the future to mean isTrue(), use `ok()`)
338338 */
339- operator bool () const {return _len > 0 ;}
339+ ASL_EXPLICIT operator bool () const { return _len > 0 ; }
340+
340341 /* *
341342 Returns true if this string is empty (warning: this might change in the future to mean !isTrue(), use `!ok()`)
342343 */
@@ -354,14 +355,21 @@ class ASL_API String
354355 Returns a pointer to the beginning of the character data (suitable for functions
355356 requiring C-style strings)
356357 */
357- operator char *() {return str ();}
358+ char * data () { return str (); }
359+ const char * data () const { return str (); }
360+
358361 /* *
359- Returns a const pointer to a Unicode UCS2 representation of this string by expanding from the internal
360- byte representation (suitable for functions requiring C-style wide strings (LPWSTR ))
362+ Returns a const pointer to a Unicode UTF16 representation of this string by expanding from the internal
363+ byte representation (suitable for functions requiring C-style wide strings (LPCWSTR ))
361364 */
362365 operator const wchar_t *() const ;
363366
364- operator wchar_t *() const {return (wchar_t *)(const wchar_t *)*this ;}
367+ /* *
368+ Returns a pointer to a Unicode UTF16 representation of this string by expanding from the internal
369+ byte representation (suitable for functions requiring C-style wide strings (LPWSTR))
370+ */
371+ wchar_t * dataw () { return (wchar_t *)(const wchar_t *)*this ; }
372+ const wchar_t * dataw () const { return (const wchar_t *)*this ; }
365373
366374 /* *
367375 Returns a const pointer to the beginning of the character data (suitable for functions
@@ -711,8 +719,8 @@ class SafeString
711719 SafeString (String& s, int n) : _s(s), _wide(false ) { _s.resize (3 * n); }
712720 ~SafeString () { if (_wide) _s.fixW (); else _s.fix (); }
713721 operator const char *() const {return _s;}
714- operator char *() const {return _s;}
715- operator const wchar_t *() { _wide = true ; return ( wchar_t *)_s ; }
722+ operator char *() const {return _s. data () ;}
723+ operator const wchar_t *() { _wide = true ; return _s. dataw () ; }
716724 operator const wchar_t *() const { _wide = true ; return (const wchar_t *)(String*)&_s; }
717725 operator wchar_t *() { _wide = true ; return (wchar_t *)(const wchar_t *)_s; }
718726};
0 commit comments