Skip to content

Commit

Permalink
Was overcomplicating the string handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
pifantastic committed May 7, 2011
1 parent c382cdb commit 92d439c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
39 changes: 17 additions & 22 deletions respond.parser.js
Expand Up @@ -7,37 +7,31 @@
stack = [],
media = [],
queries = [],
inMediaQuery = false,
inDoubleString = false,
inSingleString = false;
inMediaQuery = false;

while (index < len) {
switch (str[index]) {
case '{':
if (!inDoubleString && !inSingleString) {
stack.push('{');
if (stack.length === 2) {
inMediaQuery = true;
}
stack.push('{');
if (stack.length === 2) {
inMediaQuery = true;
}
break;

case '}':
if (!inDoubleString && !inSingleString) {
stack.pop();
if (stack.length === 0 && inMediaQuery) {
// We might be in a media query!
if (media.length) {
var start = media.pop();
queries.push(str.substring(start, index));
}
inMediaQuery = false;
stack.pop();
if (stack.length === 0 && inMediaQuery) {
// We might be in a media query!
if (media.length) {
var start = media.pop();
queries.push(str.substring(start, index));
}
inMediaQuery = false;
}
break;

case '@':
if (!inDoubleString && !inSingleString && str.substring(index + 1, index + 6) === 'media') {
if (str.substring(index + 1, index + 6) === 'media') {
var start = index;
// Zip forward to the start of the media query.
while (str[index] !== '{' && index++ < len);
Expand All @@ -53,16 +47,17 @@
}
break;

// Doubley quoted strings.
case '"':
console.log('inDoubleString');
inDoubleString = (!inSingleString && !inDoubleString);
while (str[++index] !== '"');
break;

// Singley quoted strings.
case "'":
console.log('inSingleString');
inSingleString = (!inDoubleString && !inSingleString);
while (str[++index] !== "'");
break;

// Comments.
case "/":
if (str[index + 1] == '*') {
index += 2;
Expand Down
2 changes: 1 addition & 1 deletion respond.src.js
Expand Up @@ -253,7 +253,7 @@
})(
this,
(function( win ){
return false;
//for speed, flag browsers with window.matchMedia support and IE 9 as supported
if( win.matchMedia ){ return true; }

Expand Down

0 comments on commit 92d439c

Please sign in to comment.