hivedav

A curlable free/busy scheduler with CalDAV integration
git clone https://git.in0rdr.ch/hivedav.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 983fb6dc9098218344a9c0fbae74d856514e0350
parent 59ba44dc6787dcb5d21b1448955da4fa7a0824e0
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Thu,  9 Nov 2023 22:22:21 +0100

feat(fold): simplify iterators

Diffstat:
Mserver.go | 25+++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/server.go b/server.go @@ -875,10 +875,10 @@ func fold(s string) string { runeStr := []rune(s) // create buffer for escaped result TEXT - buf := make([]rune, 1) + buf := make([]rune, 0) // bufl is the current buffer size incl. \0 - var bufl = 1 + var bufl = 0 // i is the iterator in s var i = 0 @@ -895,7 +895,7 @@ func fold(s string) string { // break lines after 75 chars // split between any two characters by inserting a CRLF // immediately followed by a white space character - buf[bufl-2] = rune(0xa) // newline '\n' + buf[bufl-1] = rune(0xa) // newline '\n' escch = rune(0x20) // whitespace ' ' esc = true @@ -904,48 +904,45 @@ func fold(s string) string { if esc { // only escape char, do not advance iterator i - buf[bufl-2] = escch + buf[bufl-1] = escch esc = false } else { // escape characters // https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.11 switch runeStr[i] { case rune(0x5c): // backslash '\' - buf[bufl-2] = rune(0x5c) + buf[bufl-1] = rune(0x5c) escch = rune(0x5c) esc = true break case rune(0x3b): // semicolon ';' - buf[bufl-2] = rune(0x5c) + buf[bufl-1] = rune(0x5c) escch = rune(0x3b) esc = true break case rune(0x2c): // comma ',' - buf[bufl-2] = rune(0x5c) + buf[bufl-1] = rune(0x5c) escch = rune(0x2c) esc = true break case rune(0xa): // newline '\n' - buf[bufl-2] = rune(0x5c) // backslash '\' + buf[bufl-1] = rune(0x5c) // backslash '\' escch = rune(0x6e) // literal 'n' - //escch = rune(0xa) // newline '\n' esc = true break case rune(0xd): // carriage return '\r' - buf[bufl-2] = rune(0x20) // whitespace ' ' + buf[bufl-1] = rune(0x20) // whitespace ' ' break default: // write regular character from runeStr - buf[bufl-2] = runeStr[i] + buf[bufl-1] = runeStr[i] break } i++ } - // terminate the char string in any case (esc or not) - //buf[bufl-1] = rune(0x0) } - return string(buf[:len(buf)-1]) + return string(buf) } // https://datatracker.ietf.org/doc/html/rfc7986#section-5.3