File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,15 @@ class LIBC_GSL_POINTER string_view {
4444 return static_cast <size_t >(End - Str);
4545 }
4646
47+ template <size_t N>
48+ LIBC_INLINE static constexpr size_t
49+ bounded_length (LIBC_LIFETIME_BOUND const char (&Str)[N]) {
50+ for (size_t i = 0 ; i < N; ++i)
51+ if (Str[i] == ' \0 ' )
52+ return i;
53+ return N;
54+ }
55+
4756 LIBC_INLINE bool equals (string_view Other) const {
4857 return (Len == Other.Len &&
4958 compareMemory (Data, Other.Data , Other.Len ) == 0 );
@@ -77,8 +86,9 @@ class LIBC_GSL_POINTER string_view {
7786 LIBC_INLINE constexpr string_view (const char *Str, size_t N)
7887 : Data(Str), Len(N) {}
7988
80- LIBC_INLINE constexpr string_view (LIBC_LIFETIME_BOUND const char (&Str)[])
81- : Data(Str), Len(length(Str)) {}
89+ template <size_t N>
90+ LIBC_INLINE constexpr string_view (LIBC_LIFETIME_BOUND const char (&Str)[N])
91+ : Data(Str), Len(bounded_length(Str)) {}
8292
8393 LIBC_INLINE constexpr const char *data () const { return Data; }
8494
You can’t perform that action at this time.
0 commit comments