Skip to content

Commit 122dfd1

Browse files
committed
#57 - Implement operator ""cs
Completed.
1 parent 42928ad commit 122dfd1

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

cpp-strings/cppstrings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ using namespace pcs;
2929
*/
3030
int main()
3131
{
32-
CppString s("-5.1");
33-
CppWString ws(L"-5.1");
32+
CppString s = "-5.1";
33+
CppWString ws{ L"-5.2"cs };
3434

3535
std::cout << ws.isupper() << std::endl;
3636
std::cout << s.zfill(10).c_str() << std::endl;

cpp-strings/cppstrings.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ namespace pcs // i.e. "pythonic c++ strings"
5050
using CppString = CppStringT<char>; //!< Specialization of basic class with template argument 'char'
5151
using CppWString = CppStringT<wchar_t>; //!< Specialization of basic class with template argument 'wchar_t'
5252

53+
// litteral operators
54+
#pragma warning(disable: 4455)
55+
inline const CppString operator""cs(const char* str, std::size_t len); //!< Forms a CppString literal.
56+
inline const CppString operator""csv(const char* str, std::size_t len); //!< Forms a CppString view literal.
57+
/*inline const CppWString operator""cs(const wchar_t* str, std::size_t len); //!< Forms a CppWString literal.
58+
inline const CppWString operator""csv(const wchar_t* str, std::size_t len); //!< Forms a CppWString view literal. */
59+
5360
// chars classifications -- not to be directly called, see respective specializations at the very end of this module.
5461
template<class CharT>
5562
inline const bool is_alpha(const CharT ch) noexcept; //!< Returns true if character ch is alphabetic, or false otherwise.
@@ -1431,6 +1438,31 @@ namespace pcs // i.e. "pythonic c++ strings"
14311438
};
14321439

14331440

1441+
//===== litteral operators ============================
1442+
/** \brief Forms a CppString literal. */
1443+
inline const CppString operator""cs(const char* str, std::size_t len)
1444+
{
1445+
return CppString(CppString::MyBaseClass(str, len));
1446+
}
1447+
1448+
/** \brief Forms a CppString view literal. */
1449+
inline const CppString operator""csv(const char* str, std::size_t len)
1450+
{
1451+
return CppString(CppString::MyStringView(str, len));
1452+
}
1453+
1454+
/*
1455+
inline const CppWString operator""cs(const wchar_t* str, std::size_t len)
1456+
{
1457+
return CppWString(CppWString::MyBaseClass(str, len));
1458+
}
1459+
1460+
inline const CppWString operator""csv(const wchar_t* str, std::size_t len)
1461+
{
1462+
return CppWString(CppWString::MyStringView(str, len));
1463+
}
1464+
*/
1465+
14341466

14351467
//===== templated chars classes ===========================
14361468
//--- is_alpha() ------------------------------------------

0 commit comments

Comments
 (0)