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

Version Path
stylus-source-0.23.0 vendor/node_modules/cssom/comments.js
stylus-source-0.22.6 vendor/node_modules/cssom/comments.js
stylus-source-0.22.5 vendor/node_modules/cssom/comments.js
stylus-source-0.22.4 vendor/node_modules/cssom/comments.js
stylus-source-0.22.3 vendor/node_modules/cssom/comments.js
stylus-source-0.22.2 vendor/node_modules/cssom/comments.js
stylus-source-0.22.1 vendor/node_modules/cssom/comments.js
stylus-source-0.22.0 vendor/node_modules/cssom/comments.js
stylus-source-0.21.2 vendor/node_modules/cssom/comments.js
stylus-source-0.21.1 vendor/node_modules/cssom/comments.js
stylus-source-0.21.0 vendor/node_modules/cssom/comments.js
stylus-source-0.20.1 vendor/node_modules/cssom/comments.js
stylus-source-0.20.0 vendor/node_modules/cssom/comments.js
stylus-source-0.19.8 vendor/node_modules/cssom/comments.js
stylus-source-0.19.7 vendor/node_modules/cssom/comments.js
stylus-source-0.19.6 vendor/node_modules/cssom/comments.js
stylus-source-0.19.5 vendor/node_modules/cssom/comments.js
stylus-source-0.19.4 vendor/node_modules/cssom/comments.js
stylus-source-0.19.3 vendor/node_modules/cssom/comments.js
stylus-source-0.19.2 vendor/node_modules/cssom/comments.js