Sha256: 24d0d284fd60ac458dc244e28b6f292b843fa0e842ce2a1b65ac7a473ad181b9
Contents?: true
Size: 1.23 KB
Versions: 22
Compression:
Stored size: 1.23 KB
Contents
var str = '"BB"/** sdfsdfs **/"CC"'; var str2 = '"BBB"/* sdfsdfs */ "CCC" /* "asdfasdf" **/ \n' + '"D""E"'; function extractStrings(str) { var result = []; var quote_opened; var afterSlash; var comment_opened; var buffer = ''; for (var i = 0, character; character = str[i]; i++) { switch (character) { case '"': if (comment_opened) { break; } if (quote_opened) { result.push(buffer); buffer = ''; quote_opened = false; } else { quote_opened = true; } break; case '/': if (quote_opened) { buffer += character; } else if (str[i + 1] == '*') { i++; comment_opened = true; } break; case '*': if (quote_opened) { buffer += character; } else if (comment_opened && str[i + 1] == '/') { i++; comment_opened = false; } else if (quote_opened && !comment_opened) { buffer += character; } break; default: if (quote_opened) { buffer += character; } break; } } return result; } console.log(extractStrings('"AAA"')); console.log(extractStrings('"/*AAA*/"')); console.log(extractStrings('/*"BBB"*/')); console.log(extractStrings('/**"BBB"**/')); console.log(extractStrings('"/*A" BBB "A*/"'));
Version data entries
22 entries across 22 versions & 1 rubygems