Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit042fcca

Browse files
committed
#203-remove signatures with c-strings and chars
Completed. Validated.
1 parent1559542 commit042fcca

File tree

1 file changed

+2
-218
lines changed

1 file changed

+2
-218
lines changed

‎cpp-strings/cppstrings.h‎

Lines changed: 2 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -487,33 +487,6 @@ namespace pcs // i.e. "pythonic c++ strings"
487487
#endif
488488
}
489489

490-
/** \brief Returns true if this string contains the passed C-string, or false otherwise.*/
491-
inlineconstexprboolcontains(const CharT* substr)constnoexcept
492-
{
493-
if (substr ==nullptr)
494-
// just to avoid system error on invalid access
495-
returntrue;
496-
497-
#if (defined(_HAS_CXX23) && _HAS_CXX23) || (!defined(_HAS_CXX23) && __cplusplus >= 202302L)
498-
// c++23 and above already defines this method
499-
returnMyBaseClass::contains(substr);
500-
#else
501-
returncontains(CppStringT(substr));
502-
#endif
503-
}
504-
505-
/** \brief Returns true if this string contains the passed char, or false otherwise.*/
506-
inlineconstexprboolcontains(const CharT& ch)constnoexcept
507-
{
508-
#if (defined(_HAS_CXX23) && _HAS_CXX23) || (!defined(_HAS_CXX23) && __cplusplus >= 202302L)
509-
// c++23 and above already defines this method
510-
returnMyBaseClass::contains(ch);
511-
#else
512-
// up to c++20, we have to implement this method
513-
returnstd::ranges::any_of(*this, [ch](const value_type c) ->bool {return c == ch; });
514-
#endif
515-
}
516-
517490

518491
//--- contains_n() ------------------------------------
519492
/** Returns true if the passed string is found within the slice str[start:start+count-1], or false otherwise.
@@ -530,32 +503,6 @@ namespace pcs // i.e. "pythonic c++ strings"
530503
}
531504
}
532505

533-
/** Returns true if the passed C-string is found within the slice str[start:start+count-1], or false otherwise.*/
534-
inlineconstexprboolcontains_n(const CharT* sub,const size_type start,const size_type count = -1)constnoexcept
535-
{
536-
if (sub ==nullptr)
537-
// just to avoid system error on invalid access
538-
returntrue;
539-
540-
try {
541-
returnthis->substr(start, count).contains(sub);
542-
}
543-
catch (...) {
544-
returnfalse;
545-
}
546-
}
547-
548-
/** Returns true if the passed char is found within the slice str[start:start+count-1], or false otherwise.*/
549-
inlineconstexprboolcontains_n(const CharT ch,const size_type start,const size_type count = -1)constnoexcept
550-
{
551-
try {
552-
returnthis->substr(start, count).contains(ch);
553-
}
554-
catch (...) {
555-
returnfalse;
556-
}
557-
}
558-
559506

560507
//--- count() -----------------------------------------
561508
/** \brief Returns the number of non-overlapping occurrences of substring sub in the range [start, end].*/
@@ -698,42 +645,6 @@ namespace pcs // i.e. "pythonic c++ strings"
698645
returnfind_n(sub, start, end_ - start +1);
699646
}
700647

701-
/** Returns the lowest index in the string where character ch is found within the slice str[start:end], or -1 (i.e. 'npos') if ch is not found.
702-
*
703-
* Note: this method should be used only if you need to know the position of
704-
* sub. To check if sub is a substring or not, use the method contains().
705-
*
706-
* CAUTION: empty substrings are considered to be in the string if start and
707-
* end positions are both less than the string size and if start <= end.
708-
*
709-
* \see find_n(), rfind() and rfind_n().
710-
* \see index(), index_n(), rindex() and rindex_n().
711-
*/
712-
inlineconstexpr size_typefind(const CharT ch,const size_type start =0,const size_type end = -1)constnoexcept
713-
{
714-
returnfind(CppStringT(ch), start, end);
715-
}
716-
717-
/** Returns the lowest index in the string where null-terminated string sub is found within the slice str[start:end], or -1 (i.e. 'npos') if sub is not found.
718-
*
719-
* Note: this method should be used only if you need to know the position of
720-
* sub. To check if sub is a substring or not, use the method contains().
721-
*
722-
* CAUTION: empty substrings are considered to be in the string if start and
723-
* end positions are both less than the string size and if start <= end. The
724-
* returned position is 0.
725-
*
726-
* \see find_n(), rfind() and rfind_n().
727-
* \see index(), index_n(), rindex() and rindex_n().
728-
*/
729-
inlineconstexpr size_typefind(const CharT* sub,const size_type start =0,const size_type end = -1)constnoexcept
730-
{
731-
if (sub ==nullptr)
732-
return CppStringT::npos;
733-
else
734-
returnfind(CppStringT(sub), start, end);
735-
}
736-
737648

738649
//--- find_n() ----------------------------------------
739650
/** Returns the lowest index in the string where substring sub is found within the slice str[start:start+count-1], or -1 (i.e. 'npos') if sub is not found.
@@ -780,64 +691,6 @@ namespace pcs // i.e. "pythonic c++ strings"
780691
returnfind_n(sub,0, count);
781692
}
782693

783-
/** Returns the lowest index in the string where character ch is found within the slice str[start:start+count-1], or -1 (i.e. 'npos') if ch is not found.
784-
*
785-
* Note: this method should be used only if you need to know the position of
786-
* sub. To check if sub is a substring or not, use the method contains_n().
787-
*
788-
* CAUTION: empty substrings are considered to be in the string if start and
789-
* end positions are both less than the string size and if start <= end.
790-
*
791-
* \see find(), rfind() and rfind_n().
792-
* \see index(), index_n(), rindex() and rindex_n().
793-
*/
794-
inlineconstexpr size_typefind_n(const CharT ch,const size_type start,const size_type count)constnoexcept
795-
{
796-
returnfind_n(CppStringT(ch), start, count);
797-
}
798-
799-
/** Returns the lowest index in the string where character ch is found within the slice str[0:count-1], or -1 (i.e. 'npos') if ch is not found.
800-
*
801-
* Note: this method should be used only if you need to know the position of
802-
* sub. To check if sub is a substring or not, use the method contains_n().
803-
*
804-
* \see find(), rfind() and rfind_n().
805-
* \see index(), index_n(), rindex() and rindex_n().
806-
*/
807-
inlineconstexpr size_typefind_n(const CharT ch,const size_type count)constnoexcept
808-
{
809-
returnfind_n(CppStringT(ch),0, count);
810-
}
811-
812-
/** Returns the lowest index in the string where null-terminated substring sub is found within the slice str[start:start+count-1], or -1 (i.e. 'npos') if sub is not found.
813-
*
814-
* Note: this method should be used only if you need to know the position of
815-
* sub. To check if sub is a substring or not, use the method contains_n().
816-
*
817-
* \see find(), rfind() and rfind_n().
818-
* \see index(), index_n(), rindex() and rindex_n().
819-
*/
820-
inlineconstexpr size_typefind_n(const CharT* sub,const size_type start,const size_type count)constnoexcept
821-
{
822-
if (sub ==nullptr)
823-
return CppStringT::npos;
824-
else
825-
returnfind_n(CppStringT(sub), start, count);
826-
}
827-
828-
/** Returns the lowest index in the string where null-terminated substring sub is found within the slice str[0:count-1], or -1 (i.e. 'npos') if sub is not found.
829-
*
830-
* Note: this method should be used only if you need to know the position of
831-
* sub. To check if sub is a substring or not, use the method contains_n().
832-
*
833-
* \see find(), rfind() and rfind_n().
834-
* \see index(), index_n(), rindex() and rindex_n().
835-
*/
836-
inlineconstexpr size_typefind_n(const CharT* sub,const size_type count)constnoexcept
837-
{
838-
returnfind_n(sub,0, count);
839-
}
840-
841694

842695
//--- index() -----------------------------------------
843696
/** Like find(const CppStringT&), but raises NotFoundException when the substring sub is not found.
@@ -855,36 +708,6 @@ namespace pcs // i.e. "pythonic c++ strings"
855708
return ret_value;
856709
}
857710

858-
/** Like find(const CharT), but raises NotFoundException when character ch is not found.
859-
*
860-
* \see index_n(), rindex() and rindex_n().
861-
* \see find(), find_n(), rfind() and rfind_n().
862-
*/
863-
inlineconstexpr size_typeindex(const CharT ch,const size_type start =0,const size_type end = -1)const
864-
{
865-
const size_type ret_value =find(ch, start, end);
866-
if (ret_value == CppStringT::npos)
867-
throwNotFoundException("char not found in string.");
868-
//throw NotFoundException(CppStringT(std::format("character \"{}\" not found in string \"{}\"", CppStringT(ch).c_str(), this->c_str()).c_str()));
869-
else
870-
return ret_value;
871-
}
872-
873-
/** Like find(const CharT*), but raises NotFoundException when the substring sub is not found.
874-
*
875-
* \see index_n(), rindex() and rindex_n().
876-
* \see find(), find_n(), rfind() and rfind_n().
877-
*/
878-
inlineconstexpr size_typeindex(const CharT* sub,const size_type start =0,const size_type end = -1)const
879-
{
880-
const size_type ret_value =find(sub, start, end);
881-
if (ret_value == CppStringT::npos)
882-
throwNotFoundException("substring not found in string");
883-
//throw NotFoundException(CppStringT(std::format("substring \"{}\" not found in string \"{}\"", CppStringT(sub).c_str(), this->c_str()).c_str()));
884-
else
885-
return ret_value;
886-
}
887-
888711

889712
//--- index_n() ---------------------------------------
890713
/** Like find_n(sub, start, count), but raises NotFoundException when the substring is not found.
@@ -907,46 +730,6 @@ namespace pcs // i.e. "pythonic c++ strings"
907730
returnindex(sub,0, count);
908731
}
909732

910-
/** Like find_n(sub, start, count), but raises NotFoundException when the character is not found.
911-
*
912-
* \see index_n(), rindex() and rindex_n().
913-
* \see find(), find_n(), rfind() and rfind_n().
914-
*/
915-
inlineconstexpr size_typeindex_n(const CharT ch,const size_type start,const size_type count)const
916-
{
917-
returnindex(ch, start, start + count -1);
918-
}
919-
920-
/** Like find_n(sub, count), but raises NotFoundException when the character is not found.
921-
*
922-
* \see index_n(), rindex() and rindex_n().
923-
* \see find(), find_n(), rfind() and rfind_n().
924-
*/
925-
inlineconstexpr size_typeindex_n(const CharT ch,const size_type count)const
926-
{
927-
returnindex(ch,0, count);
928-
}
929-
930-
/** Like find_n(sub, start, count), but raises NotFoundException when the null-terminated substring is not found.
931-
*
932-
* \see index_n(), rindex() and rindex_n().
933-
* \see find(), find_n(), rfind() and rfind_n().
934-
*/
935-
inlineconstexpr size_typeindex_n(const CharT* sub,const size_type start,const size_type count)const
936-
{
937-
returnindex(sub, start, start + count -1);
938-
}
939-
940-
/** Like find_n(sub, count), but raises NotFoundException when the null-terminated substring is not found.
941-
*
942-
* \see index_n(), rindex() and rindex_n().
943-
* \see find(), find_n(), rfind() and rfind_n().
944-
*/
945-
inlineconstexpr size_typeindex_n(const CharT* sub,const size_type count)const
946-
{
947-
returnindex(sub,0, count);
948-
}
949-
950733

951734
//--- isalnum() ---------------------------------------
952735
/** \brief Returns true if all characters in the string are alphanumeric and there is at least one character, or false otherwise.*/
@@ -1378,7 +1161,8 @@ namespace pcs // i.e. "pythonic c++ strings"
13781161
returnrfind(sub, start,this->size() -1);
13791162
}
13801163

1381-
/** Returns the highest index in the string where substring sub is found in the whole string, or -1 (i.e. 'npos') if sub is not found.
1164+
1165+
/** Returns the highest index in the string where C-substring sub is found in the whole string, or -1 (i.e. 'npos') if sub is not found.
13821166
*
13831167
* Note that this is an offset from the start of the string, not the end.
13841168
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp