@@ -34,6 +34,9 @@ SOFTWARE.
34
34
#include " etl/vector.h"
35
35
36
36
#include < string>
37
+ #include < string_view>
38
+ #include < vector>
39
+ #include < list>
37
40
38
41
#undef STR
39
42
#define STR (x ) x
@@ -54,6 +57,9 @@ namespace
54
57
using Vector = etl::vector<String, 15 >;
55
58
using SizeType = etl::istring::size_type;
56
59
60
+ using VectorOfViews7 = etl::vector<StringView, 7 >;
61
+ using VectorOfViews5 = etl::vector<StringView, 5 >;
62
+
57
63
#if ETL_USING_CPP17
58
64
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
59
65
#else
@@ -1085,6 +1091,121 @@ namespace
1085
1091
CHECK_EQUAL (0U , tokens.size ());
1086
1092
}
1087
1093
1094
+ // *************************************************************************
1095
+ TEST (test_split_to_vector_of_string_view_all_tokens_captured_ignore_empty_tokens)
1096
+ {
1097
+ String text (STR (" ,,,The,cat,sat,,on,the,mat" ));
1098
+ VectorOfViews7 views;
1099
+
1100
+ bool all_views_found = etl::get_token_list (text, views, STR (" ," ), true );
1101
+
1102
+ CHECK_TRUE (all_views_found);
1103
+ CHECK_EQUAL (6 , views.size ());
1104
+ CHECK_EQUAL (std::string (" The" ), std::string (views[0 ].begin (), views[0 ].end ()));
1105
+ CHECK_EQUAL (std::string (" cat" ), std::string (views[1 ].begin (), views[1 ].end ()));
1106
+ CHECK_EQUAL (std::string (" sat" ), std::string (views[2 ].begin (), views[2 ].end ()));
1107
+ CHECK_EQUAL (std::string (" on" ), std::string (views[3 ].begin (), views[3 ].end ()));
1108
+ CHECK_EQUAL (std::string (" the" ), std::string (views[4 ].begin (), views[4 ].end ()));
1109
+ CHECK_EQUAL (std::string (" mat" ), std::string (views[5 ].begin (), views[5 ].end ()));
1110
+ }
1111
+
1112
+ // *************************************************************************
1113
+ TEST (test_get_token_list_to_vector_of_string_view_all_but_1_tokens_captured_ignore_empty_tokens)
1114
+ {
1115
+ String text (STR (" ,,,The,cat,sat,,on,the,mat" ));
1116
+ VectorOfViews5 views;
1117
+
1118
+ bool all_views_found = etl::get_token_list (text, views, STR (" ," ), true );
1119
+
1120
+ CHECK_FALSE (all_views_found);
1121
+ CHECK_EQUAL (5 , views.size ());
1122
+ CHECK_EQUAL (std::string (" The" ), std::string (views[0 ].begin (), views[0 ].end ()));
1123
+ CHECK_EQUAL (std::string (" cat" ), std::string (views[1 ].begin (), views[1 ].end ()));
1124
+ CHECK_EQUAL (std::string (" sat" ), std::string (views[2 ].begin (), views[2 ].end ()));
1125
+ CHECK_EQUAL (std::string (" on" ), std::string (views[3 ].begin (), views[3 ].end ()));
1126
+ CHECK_EQUAL (std::string (" the" ), std::string (views[4 ].begin (), views[4 ].end ()));
1127
+ }
1128
+
1129
+ #if ETL_USING_CPP17
1130
+ // *************************************************************************
1131
+ TEST (test_get_token_list_to_std_vector_of_std_string_view_all_tokens_captured_ignore_empty_tokens)
1132
+ {
1133
+ std::string text (STR (" ,,,The,cat,sat,,on,the,mat" ));
1134
+ std::vector<std::string_view> views;
1135
+
1136
+ bool all_views_found = etl::get_token_list (text, views, STR (" ," ), true );
1137
+
1138
+ CHECK_TRUE (all_views_found);
1139
+ CHECK_EQUAL (6 , views.size ());
1140
+ CHECK_EQUAL (std::string (" The" ), std::string (views[0 ].begin (), views[0 ].end ()));
1141
+ CHECK_EQUAL (std::string (" cat" ), std::string (views[1 ].begin (), views[1 ].end ()));
1142
+ CHECK_EQUAL (std::string (" sat" ), std::string (views[2 ].begin (), views[2 ].end ()));
1143
+ CHECK_EQUAL (std::string (" on" ), std::string (views[3 ].begin (), views[3 ].end ()));
1144
+ CHECK_EQUAL (std::string (" the" ), std::string (views[4 ].begin (), views[4 ].end ()));
1145
+ CHECK_EQUAL (std::string (" mat" ), std::string (views[5 ].begin (), views[5 ].end ()));
1146
+ }
1147
+ #endif
1148
+
1149
+ // *************************************************************************
1150
+ TEST (test_get_token_list_to_vector_of_string_view_all_tokens_captured_ignore_empty_tokens_maximum_of_3_tokens)
1151
+ {
1152
+ String text (STR (" ,,,The,cat,sat,,on,the,mat" ));
1153
+ VectorOfViews7 views;
1154
+
1155
+ bool all_views_found = etl::get_token_list (text, views, STR (" ," ), true , 3 );
1156
+
1157
+ CHECK_FALSE (all_views_found);
1158
+ CHECK_EQUAL (3 , views.size ());
1159
+ CHECK_EQUAL (std::string (" The" ), std::string (views[0 ].begin (), views[0 ].end ()));
1160
+ CHECK_EQUAL (std::string (" cat" ), std::string (views[1 ].begin (), views[1 ].end ()));
1161
+ CHECK_EQUAL (std::string (" sat" ), std::string (views[2 ].begin (), views[2 ].end ()));
1162
+ }
1163
+
1164
+ #if ETL_USING_CPP17
1165
+ // *************************************************************************
1166
+ TEST (test_get_token_list_to_std_vector_of_std_string_view_all_tokens_captured_ignore_empty_tokens_maximum_of_3_tokens)
1167
+ {
1168
+ std::string text (STR (" ,,,The,cat,sat,,on,the,mat" ));
1169
+ std::vector<std::string_view> views;
1170
+
1171
+ bool all_views_found = etl::get_token_list (text, views, STR (" ," ), true , 3 );
1172
+
1173
+ CHECK_FALSE (all_views_found);
1174
+ CHECK_EQUAL (3 , views.size ());
1175
+ CHECK_EQUAL (std::string (" The" ), std::string (views[0 ].begin (), views[0 ].end ()));
1176
+ CHECK_EQUAL (std::string (" cat" ), std::string (views[1 ].begin (), views[1 ].end ()));
1177
+ CHECK_EQUAL (std::string (" sat" ), std::string (views[2 ].begin (), views[2 ].end ()));
1178
+ }
1179
+ #endif
1180
+
1181
+ #if ETL_USING_CPP17
1182
+ // *************************************************************************
1183
+ TEST (test_get_token_list_to_std_list_of_std_string_view_all_tokens_captured_ignore_empty_tokens)
1184
+ {
1185
+ std::string text (STR (" ,,,The,cat,sat,,on,the,mat" ));
1186
+ std::list<std::string_view> views;
1187
+
1188
+ bool all_views_found = etl::get_token_list (text, views, STR (" ," ), true );
1189
+
1190
+ CHECK_TRUE (all_views_found);
1191
+ CHECK_EQUAL (6 , views.size ());
1192
+
1193
+ auto itr = views.begin ();
1194
+
1195
+ CHECK_EQUAL (std::string (" The" ), std::string (itr->begin (), itr->end ()));
1196
+ ++itr;
1197
+ CHECK_EQUAL (std::string (" cat" ), std::string (itr->begin (), itr->end ()));
1198
+ ++itr;
1199
+ CHECK_EQUAL (std::string (" sat" ), std::string (itr->begin (), itr->end ()));
1200
+ ++itr;
1201
+ CHECK_EQUAL (std::string (" on" ), std::string (itr->begin (), itr->end ()));
1202
+ ++itr;
1203
+ CHECK_EQUAL (std::string (" the" ), std::string (itr->begin (), itr->end ()));
1204
+ ++itr;
1205
+ CHECK_EQUAL (std::string (" mat" ), std::string (itr->begin (), itr->end ()));
1206
+ }
1207
+ #endif
1208
+
1088
1209
// *************************************************************************
1089
1210
TEST (test_pad_left)
1090
1211
{
0 commit comments