@@ -62,87 +62,120 @@ namespace nodepp { namespace generator { namespace file {
6262
6363 /* ─······································································─*/
6464
65- GENERATOR ( until ){
66- protected: ulong pos ; file::read _read;
67- public: ulong state; string_t data ;
65+ GENERATOR ( split ){
66+ protected: string_t borrow; ulong pos ; file::read _read;
67+ public: string_t data ; ulong state ;
6868
6969 template < class T > coEmit ( T* fd, string_t ch ){
7070 coBegin; state=0 ; pos=0 ; data.clear ();
7171
72- coWait ( _read (fd) ==1 );
73- if ( _read.state <=0 )
74- { state = data.size (); coEnd; }
75- fd->set_borrow ( _read.data );
72+ do { auto &bff = fd->get_borrow (); if ( !bff.empty () ){
7673
77- do { for ( auto x: _read. data ){ ++state;
74+ do { for ( auto &x:bff ){ ++state;
7875 if ( ch[pos] ==x ){ ++pos; } else { pos=0 ; }
7976 if ( ch.size ()==pos ){ break ; } }
8077 } while (0 );
8178
82- if ( memcmp ( _read.data .get (), ch.get (), ch.size () )==0 ){
83- auto &x = fd->get_borrow ();
84- data= x.slice ( 0 , ch.size () );
85- /* -*/ x.ptr ().slice ( ch.size (), (ulong) -1 );
79+ if ( memcmp ( bff.get (), ch.get (), ch.size () )==0 ){
80+ data= bff.slice ( 0 , ch.size () );
8681 } elif ( state > pos ) {
87- auto &x = fd->get_borrow ();
88- data= x.slice ( 0 , state - pos );
89- /* -*/ x.ptr ().slice ( state - pos, (ulong) -1 );
82+ data= bff.slice ( 0 , state - pos );
9083 } else {
91- auto &x = fd->get_borrow ();
92- data= x.slice ( 0 , state );
93- /* -*/ x.ptr ().slice ( state, (ulong) -1 );
94- }
84+ data= bff.slice ( 0 , state );
85+ }
9586
96- state = data.size ();
87+ fd->get_borrow ().ptr ().slice ( data.size (), (ulong) -1 );
88+ state = data.size ();
89+
90+ return -1 ; }} while (0 ); coNext;
9791
98- coFinish }
92+ coWait ( _read ( fd )==1 );
93+ if ( _read.state <=0 ){ state=0 ; coEnd; }
94+ fd->set_borrow ( borrow+_read.data ); coGoto (0 );
9995
100- template < class T > coEmit ( T* fd, char ch ){
101- coBegin; data.clear (); coYield (1 ); state=0 ;
96+ coFinish }};
10297
103- coWait ( _read (fd) ==1 );
104- if ( _read.state <=0 )
105- { state = data.size (); coEnd; }
106- fd->set_borrow ( _read.data );
98+ /* ─······································································─*/
10799
108- do { for ( auto x: _read.data ){ ++state;
109- if ( ch ==x ){ break ; } continue ; }
110- } while (0 );
100+ GENERATOR ( until ){
101+ protected:
102+
103+ file::read _read; string_t borrow;
104+
105+ public:
106+
107+ ulong state;
108+ string_t data;
111109
112- do { auto &x = fd->get_borrow ();
113- data += x.slice ( 0 , state );
114- /* ---*/ x.ptr ().slice ( state, (ulong) -1 );
115- state = data.size ();
116- } while (0 );
110+ template < class T > coEmit ( T* fd, string_t ch ){
111+ coBegin data.clear (); state = 0UL ;
112+
113+ do { /* ----------------*/ auto &bff = fd->get_borrow ();
114+ if ( !bff.empty () ){ do { auto pos = bff.find ( ch );
115+
116+ if ( pos.null () ){
117+ if ( bff.size () > NODEPP_UNBFF_SIZE ){
118+ data = type::move ( bff );
119+ state= data.size ();
120+ return 1 ; } break ; }
121+
122+ data = bff.slice ( 0 , pos[0 ] );
123+ state= data.size ();
124+
125+ fd->get_borrow ().ptr ().slice ( pos[1 ], (ulong) -1 );
126+
127+ return -1 ; } while (0 ); }
128+
129+ borrow = type::move ( fd->get_borrow () );
117130
118- if ( data[ data. size ()- 1 ] == ch ){ coEnd; }
131+ } while ( 0 ); coNext;
119132
120- coGoto (1 ) ; coFinish }};
133+ coWait ( _read ( fd )==1 );
134+ if ( _read.state <=0 ){ state=0 ; coEnd; }
135+ fd->set_borrow ( borrow+_read.data ); coGoto (0 );
136+
137+ coFinish }};
121138
122139 /* ─······································································─*/
123140
124141 GENERATOR ( line ){
125- protected: file::read _read;
126- public: ulong state; string_t data;
142+ protected:
143+
144+ file::read _read; string_t borrow;
145+
146+ public:
147+
148+ ulong state;
149+ string_t data;
127150
128151 template < class T > coEmit ( T* fd ){
129- coBegin data.clear (); coYield ( 1 ); state= 0 ;
152+ coBegin data.clear (); state = 0UL ;
130153
131- coWait ( _read ( fd )==1 );
132- if ( _read.state <=0 ){ state = data.size (); coEnd; }
154+ do { /* ----------------*/ auto &bff = fd->get_borrow ();
155+ if ( !bff.empty () ){ do { auto pos = bff.find (' \n ' );
156+
157+ if ( pos.null () ){
158+ if ( bff.size () > NODEPP_UNBFF_SIZE ){
159+ data = type::move ( bff );
160+ state= data.size ();
161+ return 1 ; } break ; }
133162
134- fd->set_borrow (_read.data );
163+ data = bff.slice ( 0 , pos[0 ] );
164+ state= data.size ();
135165
136- do { for ( auto x: _read.data ){ ++state;
137- if (' \n ' ==x ){ break ; } continue ; }
138- } while (0 );
166+ fd->get_borrow ().ptr ().slice ( pos[1 ], (ulong) -1 );
139167
140- data +=fd->get_borrow ().splice ( 0 , state );
141- state =data.size ();
142-
143- if ( data[data.size ()-1 ] == ' \n ' ){ coEnd; }
168+ return -1 ; } while (0 ); }
169+
170+ borrow = type::move ( fd->get_borrow () );
171+
172+ } while (0 ); coNext;
144173
145- coGoto (1 ) ; coFinish }};
174+ coWait ( _read ( fd )==1 );
175+ if ( _read.state <=0 ){ state=0 ; coEnd; }
176+ fd->set_borrow ( borrow+_read.data ); coGoto (0 );
177+
178+ coFinish }};
146179
147180}}}
148181#undef NODEPP_GENERATOR
@@ -234,6 +267,50 @@ namespace nodepp { namespace generator { namespace stream {
234267
235268 /* ─······································································─*/
236269
270+ GENERATOR ( split ){
271+ protected:
272+
273+ file::write _write;
274+ file::split _read ;
275+
276+ public:
277+
278+ template < class T , class U >
279+ coEmit ( const T& inp, const U& val ){
280+ coBegin
281+
282+ inp.onPipe .emit (); inp.resume ();
283+
284+ while ( inp.is_available () ){
285+ coWait ( _read (&inp,val)==1 ); if ( _read.state <=0 ){ break ; }
286+ inp.onData .emit (_read.data );
287+ }
288+
289+ inp.close ();
290+
291+ coFinish }
292+
293+ template < class T , class V , class U >
294+ coEmit ( const T& inp, const V& out, const U& val ){
295+ coBegin
296+
297+ inp.onPipe .emit (); inp.resume ();
298+ out.onPipe .emit (); out.resume ();
299+
300+ while ( inp.is_available () && out.is_available () ){
301+ coWait ( _read (&inp,val)==1 ); /* --*/ if ( _read .state <=0 ){ break ; }
302+ coWait ( _write (&out,_read.data )==1 ); if ( _write.state <=0 ){ break ; }
303+ inp.onData .emit (_read.data );
304+ }
305+
306+ inp.close (); out.close ();
307+
308+ coFinish }
309+
310+ };
311+
312+ /* ─······································································─*/
313+
237314 GENERATOR ( until ){
238315 protected:
239316
0 commit comments