5 function stripWithoutWhitespace() {
9 function stripWithWhitespace(str, start, end) {
10 return str.slice(start, end).replace(/\S/g, ' ');
13 module.exports = function (str, opts) {
18 var insideString = false;
19 var insideComment = false;
22 var strip = opts.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;
24 for (var i = 0; i < str.length; i++) {
26 nextChar = str[i + 1];
28 if (!insideComment && currentChar === '"') {
29 var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\';
31 insideString = !insideString;
39 if (!insideComment && currentChar + nextChar === '//') {
40 ret += str.slice(offset, i);
42 insideComment = singleComment;
44 } else if (insideComment === singleComment && currentChar + nextChar === '\r\n') {
46 insideComment = false;
47 ret += strip(str, offset, i);
50 } else if (insideComment === singleComment && currentChar === '\n') {
51 insideComment = false;
52 ret += strip(str, offset, i);
54 } else if (!insideComment && currentChar + nextChar === '/*') {
55 ret += str.slice(offset, i);
57 insideComment = multiComment;
60 } else if (insideComment === multiComment && currentChar + nextChar === '*/') {
62 insideComment = false;
63 ret += strip(str, offset, i + 1);
69 return ret + (insideComment ? strip(str.substr(offset)) : str.substr(offset));