Skip to content

Commit f9c7552

Browse files
committed
Move BasicStringLexer out of fly::detail namespace
1 parent ce154e0 commit f9c7552

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

build/win/libfly/libfly.vcxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@
223223
<ClInclude Include="..\..\..\fly\types\string\detail\string_converter.hpp" />
224224
<ClInclude Include="..\..\..\fly\types\string\detail\string_formatter.hpp" />
225225
<ClInclude Include="..\..\..\fly\types\string\detail\string_formatter_types.hpp" />
226-
<ClInclude Include="..\..\..\fly\types\string\detail\string_lexer.hpp" />
227226
<ClInclude Include="..\..\..\fly\types\string\detail\string_stream_util.hpp" />
228227
<ClInclude Include="..\..\..\fly\types\string\detail\string_traits.hpp" />
229228
<ClInclude Include="..\..\..\fly\types\string\detail\string_unicode.hpp" />
230229
<ClInclude Include="..\..\..\fly\types\string\string.hpp" />
230+
<ClInclude Include="..\..\..\fly\types\string\string_lexer.hpp" />
231231
<ClInclude Include="..\..\..\fly\types\string\string_literal.hpp" />
232232
</ItemGroup>
233233
<ItemGroup>

build/win/libfly/libfly.vcxproj.filters

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@
265265
<ClInclude Include="..\..\..\fly\types\string\string.hpp">
266266
<Filter>types\string</Filter>
267267
</ClInclude>
268+
<ClInclude Include="..\..\..\fly\types\string\string_lexer.hpp">
269+
<Filter>types\string</Filter>
270+
</ClInclude>
268271
<ClInclude Include="..\..\..\fly\types\string\string_literal.hpp">
269272
<Filter>types\string</Filter>
270273
</ClInclude>
@@ -280,9 +283,6 @@
280283
<ClInclude Include="..\..\..\fly\types\string\detail\string_formatter_types.hpp">
281284
<Filter>types\string\detail</Filter>
282285
</ClInclude>
283-
<ClInclude Include="..\..\..\fly\types\string\detail\string_lexer.hpp">
284-
<Filter>types\string\detail</Filter>
285-
</ClInclude>
286286
<ClInclude Include="..\..\..\fly\types\string\detail\string_stream_util.hpp">
287287
<Filter>types\string\detail</Filter>
288288
</ClInclude>

fly/types/string/detail/string_formatter_types.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include "fly/fly.hpp"
44
#include "fly/types/string/detail/string_classifier.hpp"
5-
#include "fly/types/string/detail/string_lexer.hpp"
65
#include "fly/types/string/detail/string_traits.hpp"
6+
#include "fly/types/string/string_lexer.hpp"
77
#include "fly/types/string/string_literal.hpp"
88

99
#include <array>
@@ -385,7 +385,7 @@ class BasicFormatString
385385
{
386386
using traits = BasicStringTraits<StringType>;
387387
using classifier = BasicStringClassifier<StringType>;
388-
using lexer = BasicStringLexer<StringType>;
388+
using lexer = fly::BasicStringLexer<StringType>;
389389
using char_type = typename traits::char_type;
390390
using view_type = typename traits::view_type;
391391

fly/types/string/detail/string_lexer.hpp fly/types/string/string_lexer.hpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <cstdint>
88
#include <optional>
99

10-
namespace fly::detail {
10+
namespace fly {
1111

1212
/**
1313
* Helper class to perform lexical analysis of a C-string literal. All methods are constant
@@ -19,15 +19,14 @@ namespace fly::detail {
1919
template <typename StringType>
2020
class BasicStringLexer
2121
{
22-
using traits = BasicStringTraits<StringType>;
23-
using classifier = BasicStringClassifier<StringType>;
22+
using traits = detail::BasicStringTraits<StringType>;
23+
using classifier = detail::BasicStringClassifier<StringType>;
2424
using char_type = typename traits::char_type;
2525
using view_type = typename traits::view_type;
2626

2727
public:
2828
/**
29-
* Constructor. Stores a view into a C-string literal. This class is not interested in the null
30-
* terminator, thus if provided, it is excluded from the view.
29+
* Constructor. Stores a view into a C-string literal.
3130
*
3231
* @tparam N The size of the C-string literal.
3332
*
@@ -36,6 +35,13 @@ class BasicStringLexer
3635
template <std::size_t N>
3736
constexpr explicit BasicStringLexer(const char_type (&literals)[N]) noexcept;
3837

38+
/**
39+
* Constructor. Stores an existing view into a string.
40+
*
41+
* @param view The existing view into the string.
42+
*/
43+
constexpr explicit BasicStringLexer(view_type view) noexcept;
44+
3945
/**
4046
* @return A string view into the C-string literal.
4147
*/
@@ -116,6 +122,14 @@ constexpr BasicStringLexer<StringType>::BasicStringLexer(const char_type (&liter
116122
{
117123
}
118124

125+
//==================================================================================================
126+
template <typename StringType>
127+
constexpr BasicStringLexer<StringType>::BasicStringLexer(view_type view) noexcept :
128+
m_size(view.size()),
129+
m_view(std::move(view))
130+
{
131+
}
132+
119133
//==================================================================================================
120134
template <typename StringType>
121135
constexpr auto BasicStringLexer<StringType>::view() const -> view_type
@@ -199,4 +213,4 @@ constexpr std::optional<std::size_t> BasicStringLexer<StringType>::consume_numbe
199213
return parsed_number ? std::optional<std::size_t>(number) : std::nullopt;
200214
}
201215

202-
} // namespace fly::detail
216+
} // namespace fly

test/types/string/string_lexer.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "fly/types/string/detail/string_lexer.hpp"
1+
#include "fly/types/string/string_lexer.hpp"
22

33
#include "fly/types/string/string_literal.hpp"
44

@@ -18,7 +18,7 @@ CATCH_TEMPLATE_TEST_CASE(
1818
{
1919
using StringType = TestType;
2020
using char_type = typename StringType::value_type;
21-
using Lexer = fly::detail::BasicStringLexer<StringType>;
21+
using Lexer = fly::BasicStringLexer<StringType>;
2222

2323
CATCH_SECTION("Cannot consume from empty lexer")
2424
{
@@ -56,6 +56,19 @@ CATCH_TEMPLATE_TEST_CASE(
5656
CATCH_CHECK_FALSE(lexer.consume());
5757
}
5858

59+
CATCH_SECTION("Lexer accepts an already-existing string view")
60+
{
61+
const char_type *str = FLY_STR(char_type, "ab");
62+
auto view = std::basic_string_view<char_type>(str);
63+
64+
Lexer lexer(view);
65+
CATCH_CHECK(lexer.view() == FLY_ARR(char_type, "ab"));
66+
67+
CATCH_CHECK(lexer.consume_if(FLY_CHR(char_type, 'a')));
68+
CATCH_CHECK(lexer.consume_if(FLY_CHR(char_type, 'b')));
69+
CATCH_CHECK_FALSE(lexer.consume());
70+
}
71+
5972
CATCH_SECTION("Peeking does not advance internal pointer")
6073
{
6174
Lexer lexer(FLY_ARR(char_type, "ab"));

0 commit comments

Comments
 (0)