File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -174,8 +174,10 @@ namespace pcs // i.e. "pythonic c++ strings"
174174 /* * \brief In-place modifies the string with its first character capitalized and the rest lowercased. Returns a reference to the string*/
175175 inline CppStringT& capitalize () noexcept
176176 {
177- this ->lower ();
178- (*this )[0 ] = upper ((*this )[0 ]);
177+ if (!this ->empty ()) {
178+ this ->lower ();
179+ (*this )[0 ] = pcs::to_upper ((*this )[0 ]);
180+ }
179181 return *this ;
180182 }
181183
@@ -1339,17 +1341,30 @@ namespace pcs // i.e. "pythonic c++ strings"
13391341 */
13401342 inline CppStringT swapcase () const noexcept
13411343 {
1342- CppStringT res ( *this );
1344+ /*
1345+ CppStringT res(*this);
13431346 std::transform(this->cbegin(), this->cend(), res.begin(), pcs::swap_case);
13441347 return res;
1348+ */
1349+ CppStringT res;
1350+ std::ranges::copy (std::views::transform (*this , pcs::swap_case), std::back_inserter (res));
1351+ return res;
13451352 }
13461353
13471354
13481355 // --- title() -----------------------------------------
13491356 /* * \brief Returns a titlecased copy of the string where words start with an uppercase character and the remaining characters are lowercase. */
1350- inline CppStringT title () const noexcept
1357+ CppStringT title () const noexcept
13511358 {
1352- return *this ;
1359+ constexpr CppStringT whitespace (value_type (' ' ));
1360+
1361+ CppStringT res (*this );
1362+ std::vector<CppStringT> words = res.split (whitespace);
1363+
1364+ for (CppStringT& word : words)
1365+ word.capitalize ();
1366+
1367+ return whitespace.join (words);
13531368 }
13541369
13551370
You can’t perform that action at this time.
0 commit comments