Skip to content

Instantly share code, notes, and snippets.

@FWeinb
Created January 23, 2014 19:53
Show Gist options
  • Save FWeinb/8585608 to your computer and use it in GitHub Desktop.
Save FWeinb/8585608 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
@function _count-token-before($search, $token, $pointer){
$count: 0;
@for $i from 1 to $pointer{
$index: $pointer - $i;
@if ( str-slice($search, $index, $index) == $token){
$count: $count + 1;
}
@else{
@return $count;
}
}
@return $count;
}
@function _find-ending-quote($string){
$backslash: str-slice("\\", 1, 1); // Dirty hack to have a single backslash
$search: $string;
$end-quote-found: false;
$position: 0;
@while not $end-quote-found {
$index: str-index($search, '"');
@if not $index or $index == 0 { // No end of string found
@return $index;
}
@else {
$position: $position + $index;
}
$char-before-quote: str-slice($search, $index - 1, $index - 1);
@if $char-before-quote != $backslash or _count-token-before($search, $backslash, $index) % 2 == 0{
$end-quote-found: true;
}
$search: str-slice($search, $index + 1);
}
@return $position;
}
e{
test: _find-ending-quote('test\\\"test"');
test: _find-ending-quote('tes t\\\" "');
test: _find-ending-quote('test\\\"test"');
test: _find-ending-quote('test\\\\\"test"');
test: _find-ending-quote('te\st\\\\\"test"');
}
e {
test: 7;
test: 10;
test: 7;
test: 9;
test: 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment