string bmlwriter::escape(cstring val) { string esc = "-"; bool needescape = (val.startswith("-")); for (byte c : val.bytes()) { if (isalnum(c) || c=='.') esc+=c; else if (c=='-') esc+="--"; else { esc+="-"+tostringhex<2>((uint8_t)c); needescape=true; } } if (needescape) return esc; else return val; }
static size_t linelen(const cstring& input) { //pointers are generally a bad idea, but this is such a hotspot it's worth it const uint8_t * inputraw = input.bytes().ptr(); size_t nlpos = 0; if (input.bytes_hasterm()) { while (!isendl(inputraw[nlpos])) nlpos++; } else { size_t inputlen = input.length(); while (nlpos < inputlen && !isendl(inputraw[nlpos])) nlpos++; } return nlpos; }