MCPcopy Create free account
hub / github.com/acl-dev/acl / scan_line

Method scan_line

lib_acl_cpp/src/stdlib/string.cpp:696–752  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

694}
695
696bool 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

Callers 6

test_mainFunction · 0.80
body_getsMethod · 0.80
infoMethod · 0.80
cluster_infoMethod · 0.80
cluster_nodesMethod · 0.80
infoMethod · 0.80

Calls 3

acl_vstring_memmoveFunction · 0.85
clearFunction · 0.50
appendMethod · 0.45

Tested by 1

test_mainFunction · 0.64