| 694 | } |
| 695 | |
| 696 | bool string::scan_line(string& out, bool nonl /* = true */, |
| 697 | size_t* n /* = NIL */, bool move /* = false */) |
| 698 | { |
| 699 | if (n) { |
| 700 | *n = 0; |
| 701 | } |
| 702 | |
| 703 | char* pEnd = buf_end(); |
| 704 | if (pEnd == NIL) { |
| 705 | return false; |
| 706 | } |
| 707 | |
| 708 | size_t len = pEnd - scan_ptr_; |
| 709 | char *ln = (char*) memchr(scan_ptr_, '\n', len); |
| 710 | if (ln == NIL) { |
| 711 | return false; |
| 712 | } |
| 713 | |
| 714 | char *next = ln + 1; |
| 715 | len = ln - scan_ptr_ + 1; |
| 716 | |
| 717 | if (nonl) { |
| 718 | ln--; |
| 719 | len--; |
| 720 | if (ln >= scan_ptr_ && *ln == '\r') { |
| 721 | // ln--; |
| 722 | len--; |
| 723 | } |
| 724 | if (len > 0) { |
| 725 | out.append(scan_ptr_, len); |
| 726 | } |
| 727 | } else { |
| 728 | out.append(scan_ptr_, len); |
| 729 | } |
| 730 | |
| 731 | if (move) { |
| 732 | if (pEnd > next) { |
| 733 | acl_vstring_memmove(vbf_, next, pEnd - next); |
| 734 | TERM(vbf_); |
| 735 | scan_ptr_ = STR(vbf_); |
| 736 | } else { |
| 737 | clear(); |
| 738 | } |
| 739 | } else { |
| 740 | if (next >= pEnd) { |
| 741 | clear(); |
| 742 | } else { |
| 743 | scan_ptr_ = next; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | if (n) { |
| 748 | *n = len; |
| 749 | } |
| 750 | |
| 751 | return true; |
| 752 | } |
| 753 | |