You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
What if c++ strings where as easy to use as Python strings?</h2>
95
96
<p>Let's just use c++ strings as are Python ones, with same API or as similar API as possible.<br/>
96
97
Library<b>cpp-strings</b> is fully templated. Just download header file<spanclass="tt">cppstrings.h</span> and put it anywhere in your project. Notice: all of its stuff is declared and defined in namespace<spanclass="tt">pcs</span> - which stands for<b>P**ythonic **C</b>++ **S**trings.</p>
97
98
<ul>
@@ -100,11 +101,12 @@
100
101
<li>Class<spanclass="tt">pcs::CppString</span> specializes the templated class with<spanclass="tt">char</span> characters.</li>
101
102
<li>Class<spanclass="tt">pcs::CppWString</span> specializes the templated class with<spanclass="tt">wchar_t</span> characters.</li>
102
103
</ul>
103
-
<p><b>cpp-strings</b> is implemented with the currently most recent c++ standard available with gcc, clang and msvc c++ compilers, i.e. standard<b>c++20</b>.</p>
104
+
<p>The<b>cpp-strings</b> HTML documentation is available here:<ahref="html/index.html">html/index.html</a>.</p>
105
+
<p>Library<b>cpp-strings</b> is implemented with the currently most recent c++ standard available with gcc, clang and msvc c++ compilers, i.e. standard<b>c++20</b>.</p>
104
106
<ul>
105
107
<li>directory<spanclass="tt">cpp-strings</span> contains the header file<spanclass="tt">cppstring.h</span>.<br/>
106
108
This is the header file to include in your projects.</li>
107
-
<li>directory<spanclass="tt">cpp-strings-tests</span> contains the unit test file<spanclass="tt">cpp-strings-tests.cpp</span><br/>
109
+
<li>directory<spanclass="tt">cpp-strings-tests</span> contains the unit-tests file<spanclass="tt">cpp-strings-tests.cpp</span><br/>
108
110
This file tests all the library stuff. It is a valuable code container with so many examples of use of the library, the classes, the methods and the functions it defines.</li>
109
111
</ul>
110
112
<p>The code has been developed using VS2022 IDE. As such, unitary tests have been coded using Microsoft Visual Studio Cpp Unit Test Framework. The related VS project is provided with this library.</p>
@@ -115,8 +117,10 @@
115
117
</ul>
116
118
<p>If you want to run the unitary tests, well, use the last version of Visual Studio (i.e. VS 2022, by July 2025). The Community free version will truly be fine.<br/>
117
119
The vcproject associated with the unit tests in<b>cpp-strings</b> is already configured to use the option flag<spanclass="tt">/std:c++latest</span> since the implemented code uses a very few but very useful c++23 goodies.</p>
<p>The creation of this library has been started with the aim at easing the use of strings in c++. Other projects exist, even aiming also to implement a Python-like strings API, but the only ones we have found were either started but not completed, or were not implementing the whole Python API.</p>
143
147
<p>So, we started to work on<b>Pythonic c++ strings</b>. Library<b>cpp-strings</b> is now ready. It fully implements the Python API (even with a c++ implementation of<em>slices</em>) and it is fully tested with<em>unitary tests</em>.</p>
144
148
<p>The implementation of library<b>cpp-strings</b> is fully templated and is contained into a single header file:<spanclass="tt">cpp-strings/cppstrings.h</span>. To take a whole benefit of it, just add this header file to your project and include it in your own files. It very fastly compiles. That's all!</p>
<li>templated class<spanclass="tt">template<typename CharT> class pcs::CppStringT</span> which implements all the stuff about pythonic c++ strings. It inherits from c++ STL class<spanclass="tt">std::basic_string<CharT></span>, so it gets access to all c++ STL methods, functions and goodies about strings;</li>
147
-
<li>this class is specialized by<spanclass="tt">using pcs::CppString> = pcs::CppStringT<char></span> for pythonic c++ strings based on<spanclass="tt">char</span> characters;</li>
148
-
<li>it is also specialized by<spanclass="tt">using pcs::CppWString> = pcs::CppStringT<wchar_t></span> for pythonic c++ strings based on<spanclass="tt">wchar_t</span> characters.</li>
151
+
<li>this class is specialized by:<spanclass="tt">using pcs::CppString> = pcs::CppStringT<char></span> for pythonic c++ strings based on<spanclass="tt">char</span> characters;</li>
152
+
<li>it is also specialized by:<spanclass="tt">using pcs::CppWString> = pcs::CppStringT<wchar_t></span> for pythonic c++ strings based on<spanclass="tt">wchar_t</span> characters.</li>
149
153
</ul>
150
-
<p>The unitary tests are provided in directory<spanclass="tt">cpp-strings-tests/</span>. File<spanclass="tt">cpp-strings-tests.cpp</span> contains the related code. They has been coded using VS2022 IDE and as such, are using the Microsoft Visual Studio Cpp Unit Test Framework. The related VS project can be found in the same directory. It is already configured to create code for Release as well as for Debug configurations, and for 32-bits or 64-bits platforms at your choice.<br/>
151
-
This<spanclass="tt">.cpp file</span> is a great place to see<b>cpp-strings</b> code in action. Each structure, class, method, litteral operator and function being unitary tested, you should find there many examples of their use for all<b>cpp-strings</b> stuff.</p>
154
+
<p>The unitary tests are provided in directory<spanclass="tt">cpp-strings-tests/</span>. File<spanclass="tt">cpp-strings-tests/cpp-strings-tests.cpp</span> contains the related code. Tests have been coded using VS2022 IDE and as such, are using the Microsoft Visual Studio Cpp Unit Test Framework. The related VS project can be found in the same directory. It is already configured to create code for Release as well as for Debug configurations, and for 32-bits or 64-bits platforms at your choice.<br/>
155
+
This<spanclass="tt">.cpp</span> file is a great place to see<b>cpp-strings</b> code in action. Each structure, class, method, litteral operator and function being unitary tested in here, you should find there many examples of its use for all<b>cpp-strings</b> stuff.</p>
<p>The coding of this project started by March 2023 and had been put in standby mode for some months - no time to work on it. The very first release is now availble (since July 2025), as<b>Release 1.0</b>.</p>
160
+
<p>This release has been fully tested. Code coverage is 100%.</p>
161
+
<p>Release 1.0 implements all Python strings API but one feature (see below).</p>
162
+
<p>Python<em>slices</em> are implemented via c++<spanclass="tt">operator()</span> as declared and defined in the templated class<spanclass="tt">pcs::CppStringT<></span>. Python slices have next specific notation:<spanclass="tt">[start : stop : step]</span> and allow the running step by step through range [start, stop) (notice: stop is excluded from the range). Operator<spanclass="tt">(start, stop, step)</span> acts the same way while running through the content of pythonic c++ strings. A dedicated base class<spanclass="tt">Slice</span> is also provided and can be passed as argument to<spanclass="tt">operator()</span>. It is derived in many simpler slices classes, since Python slices may not define either<spanclass="tt">start</span>,<spanclass="tt">stop</span> or<spanclass="tt">step</span> which then get default values (resp. 0,<em>end-of-sequence</em>, and 1).</p>
<p>Python strings are based on Unicode chars. This is currently not the case for pythonic c++ strings in<b>cpp-strings</b>.<br/>
166
+
Unicode encoding allows for a specific comparison mode on strings, the<b>casefold</b> mode. There, Unicode chars are transformed into their lower equivalent char in a standardized manner which is more "agressive" than the simpler lowering method<spanclass="tt">lower()</span>. Comparing strings without taking into account the case of their chars is then performed in a far more accurate manner.<br/>
167
+
This feature is currently NOT implemented in library<b>cpp-strings</b>.</p>
168
+
<p>So up to now, if you want to compare pythonic c++ strings from<b>cpp-strings</b> on whatever the case is for each of their chars, compare them applying method<spanclass="tt">.lower()</span> to both strings. This will do the job for chars and for wchar_t also for a majority of languages (but might fail for very few signs of specific languages in this last case).</p>
169
+
<p>Notice: dealing with Unicode chars and implementing method<spanclass="tt">casefold()</span> as it is the case in Python is planned for a next release of library<b>cpp-strings</b>.<br/>
170
+
N.B. "*planned for a next release*" does not imply that a fixed date is planned either.</p>
<p>The coding of this project started by March 2023 and had been put in standby mode for some months. The very first release is now availble (since July 2025), as<b>Release 1.0</b>.</p>
156
-
<p>This release has been fully tested. It implements all Python strings API but one feature (see below). Python<em>slices</em> are implemented via c++<spanclass="tt">operator()</span> as declared and defined in the templated class<spanclass="tt">pcs::CppStringT<></span>. Python slices have next specific notation:<spanclass="tt">[start : stop : step]</span> and allow the running through range [start, stop) (notice: stop is excluded from the range) step by step. Operator<spanclass="tt">(start, stop, step)</span> acts the same way while running through the content of c++ strings.</p>
<p>The<b>cpp-strings</b> HTML documentation is available here:<ahref="html/index.html">html/index.html</a>.</p>
175
+
<p>It has then been produced with the great utility<b>doxygen</b> developed by Vicente Hernando (the doxygen Github repository can be accessed<ahref="https://github.com/doxygen/doxygen">here</a>, and the utility can be downloaded from there:<ahref="https://www.doxygen.nl/download.html">https://www.doxygen.nl/download.html</a>).</p>
176
+
<p>This is a short documentation of the library. For some of its part it is a copy of the Python original documentation on strings. For its other part it documents the c++ implementation of<b>cpp-strings</b>.</p>
177
+
<p>And remember: to better understand how to use this pythonic c++ strings library, have a look also at<ahref="cpp-strings-tests/cpp-strings-tests.cpp"><spanclass="tt">cpp-strings-tests/cpp-strings-tests.cpp</span></a> to see<b>cpp-strings</b> library code in action!</p>