Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void cut(CutBuilder& builder) const
- {
- if (builder.length() == 0) {
- /* source completed */
- return;
- }
- /*
- * Where source starts (relative to dimension begin)?
- *
- * source
- * <==>
- * INTERVAL [__|__]
- * ^
- * |
- * source
- */
- position_t source = builder.logical() % _interval;
- /*
- * How many position absent in MAIN (not overlap) area?
- *
- * skipMain
- * <==>
- * PREFIX[___] MAIN & SUFFIX[__|__]
- * ^
- * |
- * source
- */
- position_t skipMain;
- if (source < _prefix) {
- /*
- * Source starts inside PREFIX.
- *
- * How many position absent in MAIN (not overlap) area?
- * skipPrefix
- * <==>
- * PREFIX[__|__] MAIN[___] SUFFIX [___]
- * ^
- * |
- * source
- */
- position_t skipPrefix = _prefix - source;
- if (skipPrefix > builder.length()) {
- /* source shorter than PREFIX */
- builder.skipSource(builder.length());
- /* source completed */
- return;
- } else {
- /* skip PREFIX */
- builder.skipSource(skipPrefix);
- }
- /*
- * Now we exactly on begin of MAIN, and skipMain equal zero.
- *
- * PREFIX[___] MAIN[|__] SUFFIX[___]
- * ^
- * |
- * source
- */
- skipMain = 0;
- } else {
- /*
- * Source starts in MAIN or SUFFIX.
- *
- * PREFIX[___] MAIN & SUFFIX [__|__]
- * ^
- * |
- * source
- */
- skipMain = source - _prefix;
- }
- if (skipMain < _main) {
- /*
- * Source starts in MAIN area.
- *
- * How many position should we copy?
- * copyMain
- * <==>
- * PREFIX[___] MAIN[____|____] SUFFIX[___]
- * ^
- * |
- * source
- */
- position_t copyMain = _main - skipMain;
- /* Move result segment to source position */
- builder.skipResultToSource();
- if (_nested) {
- /* We have nested dimensions (not fully included) */
- while(builder.length() > 0 && copyMain > 0) {
- /* Process one line from nested dimension */
- _nested->cut(builder);
- /* Go to next line */
- copyMain -= _nested->_interval;
- }
- } else {
- /*
- We do not have nested dimensions
- (or their fully included).
- */
- builder.copy(min(copyMain, builder.length()));
- }
- /* MAIN area completed! */
- }
- /*
- * Source now in SUFFIX.
- *
- * How many positions left in suffix?
- * <==>
- * PREFIX[___] MAIN[___] SUFFIX[__|__]
- * ^
- * |
- * source
- */
- builder.skipSource(min(_interval - source,
- builder.length()));
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement