Skip to content

Commit 1ba40cb

Browse files
committed
Provide nonstd::string::npos, update Synopsis
1 parent 71be699 commit 1ba40cb

File tree

4 files changed

+50
-55
lines changed

4 files changed

+50
-55
lines changed

README.md

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -92,56 +92,53 @@ Creating *string bare* I've had a look at the [C++ standard](https://eel.is/c++d
9292
<a id="syn-doc"></a>
9393
### Documentation of *string bare*
9494

95-
The following table presents simplified, short prototypes of the functions in _string-bare_.
96-
97-
| Kind | Type or function | Notes |
98-
| ------------- | ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
99-
| **Type** | **literal_delimiter** | a single string |
100-
| &nbsp; | **any_of_delimiter** | any of given characters |
101-
| &nbsp; | **fixed_delimiter** | fixed length |
102-
| &nbsp; | **limit_delimiter** | apply given delimiter a limited number of times (not implemented) |
103-
| &nbsp; | **regex_delimiter** | regular expression |
104-
| &nbsp; | **char_delimiter** | character position |
105-
| &nbsp; | &nbsp; | &nbsp; |
106-
| **Utilities** | char_t **nullchr**() | null char of template character type |
107-
| &nbsp; | char_t \* **nullstr**() | empty character string of template character type |
108-
| &nbsp; | &nbsp; | &nbsp; |
109-
| **Observers** | size_t **length**(string_view sv) | length of string |
110-
| &nbsp; | size_t **size**(string_view sv) | length of string |
111-
| &nbsp; | bool **is_empty**(string_view sv) | true if string is empty |
112-
| &nbsp; | bool **contains**(string_view sv, string_view what) | true if string contains given string |
113-
| &nbsp; | bool **starts_with**(string_view sv, string_view what) | true if string starts with given string |
114-
| &nbsp; | bool **ends_with**(string_view sv, string_view what) | true if string ends with given string |
115-
| &nbsp; | &nbsp; | &nbsp; |
116-
| **Searching** | size_t **find_first**(string_view sv, string_view what) | position of first occurrence of given string, or npos [Note 1](#note-1) |
117-
| &nbsp; | size_t **find_first_of**(string_view sv, string_view set) | position of first occurrence of character in set, or npos |
118-
| &nbsp; | size_t **find_first_not_of**(string_view sv, string_view set) | position of first occurrence of character not in set, or npos |
119-
| &nbsp; | size_t **find_last**(string_view sv, string_view what) | position of last occurrence of given string, or npos |
120-
| &nbsp; | size_t **find_last_of**(string_view sv, string_view set) | position of last occurrence of character in set, or npos |
121-
| &nbsp; | size_t **find_last_not_of**(string_view sv, string_view set) | position of last occurrence of character not in set, or npos |
122-
| &nbsp; | &nbsp; | &nbsp; |
123-
| **Modifiers** | char_t **to_lowercase**(char_t chr) | character transformed to lowercase |
124-
| &nbsp; | char_t **to_uppercase**(char_t chr) | character transformed to uppercase |
125-
| &nbsp; | string **to_lowercase**(string_view sv) | string transformed to lowercase |
126-
| &nbsp; | string **to_uppercase**(string_view sv) | string transformed to uppercase |
127-
| &nbsp; | string **substring**(string_view sv, size_t pos \[, size_t count\]); | substring starting at given position of given length, default up to end |
128-
| &nbsp; | string **strip**(string_view sv, string_view set) | string with characters given in set stripped from left and right |
129-
| &nbsp; | string **strip_left**(string_view sv, string_view set) | string with characters given in set stripped from left |
130-
| &nbsp; | string **strip_right**(string_view sv, string_view set) | string with characters given in set stripped from right |
131-
| &nbsp; | string **replace_all**(string_view sv, string_view what, string_view with) | string with all occurrences of 'what' replaced with 'with' |
132-
| &nbsp; | string **replace_first**(string_view sv, string_view what, string_view with) | string with first occurrence of 'what' replaced with 'with' |
133-
| &nbsp; | string **replace_last**(string_view sv, string_view what, string_view with) | string with last occurrence of 'what' replaced with 'with' |
134-
| &nbsp; | &nbsp; | &nbsp; |
95+
The following table presents types, values and simplified, short prototypes of the functions in _string-bare_'s `nonstd` namespace.
96+
97+
| Kind | Type or function | Notes |
98+
| ------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
99+
| **Type** | **literal_delimiter** | a single string, `literal_delimiter("exact_text")` |
100+
| &nbsp; | **any_of_delimiter** | any of given characters, `any_of_delimiter("+-")` |
101+
| &nbsp; | **fixed_delimiter** | fixed length, `fixed_delimiter(length)` |
102+
| &nbsp; | **limit_delimiter** | apply given delimiter a limited number of times (not implemented) |
103+
| &nbsp; | **regex_delimiter** | regular expression, `regex_delimiter("regexp")` |
104+
| &nbsp; | **char_delimiter** | character position, `char_delimiter('&')` |
105+
| &nbsp; | &nbsp; | &nbsp; |
106+
| **Value** | size_t **string::npos** | not-found position value, in nonstd::string namespace |
107+
| &nbsp; | &nbsp; | &nbsp; |
108+
| **Observers** | size_t **length**(string_view sv) | length of string |
109+
| &nbsp; | size_t **size**(string_view sv) | length of string |
110+
| &nbsp; | bool **is_empty**(string_view sv) | true if string is empty |
111+
| &nbsp; | bool **contains**(string_view sv, string_view what) | true if string contains given string |
112+
| &nbsp; | bool **starts_with**(string_view sv, string_view what) | true if string starts with given string |
113+
| &nbsp; | bool **ends_with**(string_view sv, string_view what) | true if string ends with given string |
114+
| &nbsp; | &nbsp; | &nbsp; |
115+
| **Searching** | size_t **find_first**(string_view sv, string_view what) | position of first occurrence of given string, or npos |
116+
| &nbsp; | size_t **find_first_of**(string_view sv, string_view set) | position of first occurrence of character in set, or npos |
117+
| &nbsp; | size_t **find_first_not_of**(string_view sv, string_view set) | position of first occurrence of character not in set, or npos |
118+
| &nbsp; | size_t **find_last**(string_view sv, string_view what) | position of last occurrence of given string, or npos |
119+
| &nbsp; | size_t **find_last_of**(string_view sv, string_view set) | position of last occurrence of character in set, or npos |
120+
| &nbsp; | size_t **find_last_not_of**(string_view sv, string_view set) | position of last occurrence of character not in set, or npos |
121+
| &nbsp; | &nbsp; | &nbsp; |
122+
| **Modifiers** | char_t **to_lowercase**(char_t chr) | character transformed to lowercase |
123+
| &nbsp; | char_t **to_uppercase**(char_t chr) | character transformed to uppercase |
124+
| &nbsp; | string **to_lowercase**(string_view sv) | string transformed to lowercase |
125+
| &nbsp; | string **to_uppercase**(string_view sv) | string transformed to uppercase |
126+
| &nbsp; | string **substring**(string_view sv, size_t pos \[, size_t count\]); | substring starting at given position of given length, default up to end |
127+
| &nbsp; | string **strip**(string_view sv, string_view set) | string with characters given in set stripped from left and right |
128+
| &nbsp; | string **strip_left**(string_view sv, string_view set) | string with characters given in set stripped from left |
129+
| &nbsp; | string **strip_right**(string_view sv, string_view set) | string with characters given in set stripped from right |
130+
| &nbsp; | string **replace_all**(string_view sv, string_view what, string_view with) | string with all occurrences of 'what' replaced with 'with' |
131+
| &nbsp; | string **replace_first**(string_view sv, string_view what, string_view with) | string with first occurrence of 'what' replaced with 'with' |
132+
| &nbsp; | string **replace_last**(string_view sv, string_view what, string_view with) | string with last occurrence of 'what' replaced with 'with' |
133+
| &nbsp; | &nbsp; | &nbsp; |
135134
| **Combining** | string **append**(string_view head, string_view tail) | string with tail appended to head |
136-
| &nbsp; | string **join**(collection\<string_view\> vec, string_view sep) | string with elements of collection joined with given separator string |
137-
| &nbsp; | vector\<string_view\> **split**(string_view sv, string_view set) | vector of string_view with elements of string separated by characters from given set |
135+
| &nbsp; | string **join**(collection\<string_view\> vec, string_view sep) | string with elements of collection joined with given separator string |
136+
| &nbsp; | vector\<string_view\> **split**(string_view sv, string_view set) | vector of string_view with elements of string separated by characters from given set |
138137
| &nbsp; | tuple\<string_view, string_view\> **split_left**(string_view sv, Delimiter delim) | tuple with head and tail string_view on given string as split at left by given delimiter |
139138
| &nbsp; | tuple\<string_view, string_view\> **split_right**(string_view sv, Delimiter delim) | tuple with head and tail string_view on given string as split at right by given delimiter |
140139
| &nbsp; | tuple\<string_view, string_view\> **split_left**(string_view sv, string_view set) | tuple with head and tail string_view on given string as split at left by characters in given set |
141140
| &nbsp; | tuple\<string_view, string_view\> **split_right**(string_view sv, string_view set) | tuple with head and tail string_view on given string as split at right by characters in given set |
142141

143-
<a id="note-1"></a>Note 1: npos: `nonstd::string::std17::string_view::npos`; TODO: provide `nonstd::string::npos`.
144-
145142
### Configuration
146143

147144
#### Tweak header

include/nonstd/string.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ namespace nonstd {
279279

280280
namespace string {
281281

282-
namespace detail {
283-
284282
// npos
285283

286284
#if string_CPP17_OR_GREATER
@@ -291,6 +289,8 @@ namespace detail {
291289
enum { npos = std::size_t(-1) };
292290
#endif
293291

292+
namespace detail {
293+
294294
template< typename T >
295295
string_constexpr std::size_t to_size_t(T value) string_noexcept
296296
{
@@ -360,11 +360,11 @@ class basic_string_view
360360
// Constants:
361361

362362
#if string_CPP17_OR_GREATER
363-
static string_constexpr std::size_t npos = detail::npos;
363+
static string_constexpr std::size_t npos = string::npos;
364364
#elif string_CPP11_OR_GREATER
365-
enum : std::size_t { npos = detail::npos };
365+
enum : std::size_t { npos = string::npos };
366366
#else
367-
enum { npos = detail::npos };
367+
enum { npos = string::npos };
368368
#endif
369369

370370
// 24.4.2.1 Construction and assignment:
@@ -665,8 +665,6 @@ string_nodiscard string_constexpr char32_t const * nullstr( char32_t ) noexcept
665665
}
666666
#endif
667667

668-
// TODO: nullstr() for other character types
669-
670668
#if string_HAVE_STRING_VIEW
671669
#define MK_DETAIL_TO_STRING_SV(T) \
672670
string_nodiscard inline std::basic_string<T> \
@@ -707,6 +705,7 @@ string_nodiscard string_constexpr char32_t const * nullstr( char32_t ) noexcept
707705
// enable use of string-specific namespaces detail and stdxx:
708706

709707
using namespace string;
708+
710709
//
711710
// Observers
712711
//
@@ -864,7 +863,7 @@ string_nodiscard std::size_t find_first( std17::basic_string_view<CharT> text, S
864863
template< typename SeekT > \
865864
string_nodiscard bool contains( std17::basic_string_view<CharT> text, SeekT const & seek ) \
866865
{ \
867-
return detail::npos != find_first(text, seek); \
866+
return string::npos != find_first(text, seek); \
868867
}
869868
#endif
870869

@@ -1151,7 +1150,7 @@ replace_all( std17::basic_string_view<CharT> text, std17::basic_string_view<Char
11511150

11521151
#define string_MK_SUBSTRING(CharT) \
11531152
string_nodiscard inline std::basic_string<CharT> \
1154-
substring( std17::basic_string_view<CharT> text, std::size_t pos = 0, std::size_t count = detail::npos ) \
1153+
substring( std17::basic_string_view<CharT> text, std::size_t pos = 0, std::size_t count = string::npos ) \
11551154
{ \
11561155
return std::basic_string<CharT>( text ).substr( pos, count ); \
11571156
}

test/string-main.t.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ inline nonstd::std17::string_view text_view()
4747
return ::nonstd::string::std17::string_view( text().c_str(), text().length() );
4848
}
4949

50-
const auto sv_npos = ::nonstd::string::detail::npos;
50+
const auto sv_npos = ::nonstd::string::npos;
5151

5252
namespace std {
5353

0 commit comments

Comments
 (0)