diff --git a/lib/base.js b/lib/base.js index a66318a..7ca9deb 100644 --- a/lib/base.js +++ b/lib/base.js @@ -336,29 +336,13 @@ CalendarProperty.prototype.format = function() { if(params.length) params = ';'+params.join(';'); - var data = new Buffer(this.name+params+':'+format_value(this.type, this.value, this.parameters)); - var pos = 0, len; - var output = []; - while(true) { - len = MAX_LINE; - if(pos+len >= data.length) - len = data.length-pos; - - // We're in the middle of a unicode character if the high bit is set and - // the next byte is 10xxxxxx (or 0x80). Don't split it in half. - // Wind backward until we find the start character... - while((data[pos+len] & 0xc0) == 0x80) - len--; - - output.push(data.toString('utf8', pos, pos+len)); - - if(pos+len >= data.length) - break; - - // Insert the space for the start of the next line... - pos += len-1; - data[pos] = 0x20; + let line = this.name + params + ':' + format_value(this.type, this.value, this.parameters); + const output = []; + while (line.length > MAX_LINE) { + output.push(line.substring(0, MAX_LINE)); + line = ' ' + line.substring(MAX_LINE); } + output.push(line); return output; } diff --git a/lib/parser.js b/lib/parser.js index b084528..90d4aa6 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -82,13 +82,13 @@ function parse_component(component, next_state) { } } -PROP_NAME = 0; -PARAM_NAME = 1; -PARAM_VALUE = 2; -MAYBE_QUOTED_PARAM = 3; -QUOTED_PARAM_VALUE = 4; -PARAM_OR_VALUE = 5; -PROP_VALUE = 6; +const PROP_NAME = 0; +const PARAM_NAME = 1; +const PARAM_VALUE = 2; +const MAYBE_QUOTED_PARAM = 3; +const QUOTED_PARAM_VALUE = 4; +const PARAM_OR_VALUE = 5; +const PROP_VALUE = 6; function parse_record(rec) { var propname;