2222
2323// =============================================================
2424#include < algorithm>
25+ #include < array>
2526#include < cassert>
2627#include < cctype>
2728#include < cwctype>
@@ -392,10 +393,10 @@ namespace pcs // i.e. "pythonic c++ strings"
392393 inline CppStringT (InputIt first, InputIt last) : MyBaseClass(first, last) {} // #16
393394
394395 template <class StringViewLike >
395- explicit CppStringT (const StringViewLike& svl) : MyBaseClass(svl) {} // #17
396+ explicit CppStringT (StringViewLike& svl) : MyBaseClass(svl) {} // #17
396397
397398 template <class StringViewLike >
398- CppStringT (const StringViewLike& svl, size_type pos, size_type n) : MyBaseClass(svl, pos, n) {} // #18
399+ CppStringT (StringViewLike& svl, size_type pos, size_type n) : MyBaseClass(svl, pos, n) {} // #18
399400
400401 inline ~CppStringT () noexcept = default ;
401402
@@ -981,10 +982,14 @@ namespace pcs // i.e. "pythonic c++ strings"
981982 *
982983 * For instance uppercase characters may only follow uncased
983984 * characters and lowercase characters only cased ones.
985+ *
986+ * CAUTION: current implementation only tests for uppercase
987+ * characters following whitespaces and lowercase characters
988+ * anywhere else.
984989 */
985990 inline const bool istitle () const noexcept
986991 {
987- return !this ->empty && this ->title () == *this ;
992+ return !this ->empty () && this ->title () == *this ;
988993 }
989994
990995
@@ -1005,6 +1010,39 @@ namespace pcs // i.e. "pythonic c++ strings"
10051010
10061011
10071012 // --- join() ------------------------------------------
1013+ /* * \brief Returns a string which is the concatenation of the strings in the array parameter.
1014+ *
1015+ * The separator between elements is the string to which this method is applied.
1016+ */
1017+ template <const std::size_t N>
1018+ inline CppStringT join (const std::array<CppStringT, N>& strs) const noexcept
1019+ {
1020+ auto str_it = strs.cbegin ();
1021+ if (str_it == strs.cend ())
1022+ return CppStringT ();
1023+
1024+ CppStringT res{ *str_it++ };
1025+ while (str_it != strs.cend ())
1026+ res += *this + *str_it++;
1027+ return res;
1028+ }
1029+
1030+ /* * \brief Returns a string which is the concatenation of the strings in the vector parameter.
1031+ *
1032+ * The separator between elements is the string to which this method is applied.
1033+ */
1034+ CppStringT join (const std::vector<CppStringT>& strs) const noexcept
1035+ {
1036+ auto str_it = strs.cbegin ();
1037+ if (str_it == strs.cend ())
1038+ return CppStringT ();
1039+
1040+ CppStringT res{ *str_it++ };
1041+ while (str_it != strs.cend ())
1042+ res += *this + *str_it++;
1043+ return res;
1044+ }
1045+
10081046 /* * \brief Returns a string which is the concatenation of the strings in the parameters list.
10091047 *
10101048 * The separator between elements is the string to which this method is applied.
@@ -1537,7 +1575,7 @@ namespace pcs // i.e. "pythonic c++ strings"
15371575 */
15381576 inline std::vector<CppStringT> split (const CppStringT& sep) const noexcept
15391577 {
1540- std::vector<std::string > res;
1578+ std::vector<CppStringT > res;
15411579 for (const auto & word : *this | std::views::split (sep))
15421580 res.push_back (CppStringT (word.begin (), word.end ()));
15431581 return res;
@@ -1800,13 +1838,13 @@ namespace pcs // i.e. "pythonic c++ strings"
18001838 /* * \brief Returns a titlecased copy of the string where words start with an uppercase character and the remaining characters are lowercase. */
18011839 CppStringT title () const noexcept
18021840 {
1803- constexpr CppStringT whitespace (value_type (' ' ));
1841+ const CppStringT whitespace (value_type (' ' ));
18041842
18051843 CppStringT res (*this );
18061844 std::vector<CppStringT> words = res.split (whitespace);
18071845
18081846 for (CppStringT& word : words)
1809- word.capitalize ();
1847+ word = word .capitalize ();
18101848
18111849 return whitespace.join (words);
18121850 }
0 commit comments