File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,14 @@ static bool pushline(LacoState* laco, bool isFirstLine) {
100100 return result ;
101101}
102102
103+ static inline void ignore_extra_spaces (char * * string_ptr ) {
104+ if (* string_ptr == NULL ) return ;
105+
106+ while (* * string_ptr == ' ' ) {
107+ * string_ptr += 1 ;
108+ }
109+ }
110+
103111/* External API */
104112
105113int laco_load_line (LacoState * laco ) {
@@ -170,3 +178,22 @@ int laco_is_match(const char** matches, const char* test_string) {
170178
171179 return false;
172180}
181+
182+ char * * laco_line_to_words (char * line ) {
183+ if (line == NULL ) return NULL ;
184+
185+ char * * result = calloc (16 , sizeof (char * ));
186+ size_t i = 0 ;
187+
188+ while (1 ) {
189+ result [i ] = strsep (& line , " " );
190+
191+ if (result [i ] == NULL ) break ;
192+
193+ ignore_extra_spaces (& line );
194+
195+ i += 1 ;
196+ }
197+
198+ return result ;
199+ }
Original file line number Diff line number Diff line change @@ -38,4 +38,6 @@ void laco_report_error(struct LacoState* laco, int status);
3838 */
3939int laco_is_match (const char * * matches , const char * test_string );
4040
41+ char * * laco_line_to_words (char * line );
42+
4143#endif /* LACO_UTIL_H */
You can’t perform that action at this time.
0 commit comments