highlight-accentfold-debug.js revision 6f5af1718dea14514e194dedfc335186cddd2a9a
/**
Adds accent-folding highlighters to `Y.Highlight`.
@module highlight
@submodule highlight-accentfold
**/
/**
@class Highlight
@static
**/
EMPTY_OBJECT = {},
// -- Public Static Methods ------------------------------------------------
/**
Accent-folding version of `all()`.
@method allFold
@param {String} haystack String to apply highlighting to.
@param {String|String[]} needles String or array of strings that should be
highlighted.
@param {Object} [options] Options object.
@param {Boolean} [options.startsWith=false] If `true`, matches must be
anchored to the beginning of the string.
@return {String} Escaped and highlighted copy of _haystack_.
@static
**/
results = [],
startPos = 0,
// This tells Highlight.all() not to escape HTML, in order to ensure
// usable match offsets. The output of all() is discarded, and we
// perform our own escaping before returning the highlighted string.
escapeHTML: false,
// While the highlight regex operates on the accent-folded strings,
// this replacer will highlight the matched positions in the
// original string.
//
// Note: this implementation doesn't handle multi-character folds,
// like "æ" -> "ae". Doing so correctly would be prohibitively
// expensive both in terms of code size and runtime performance, so
// I've chosen to take the pragmatic route and just not do it at
// all. This is one of many reasons why accent folding is best done
// on the server.
var len;
// Ignore matches inside HTML entities.
return match;
}
]);
}
}, options || EMPTY_OBJECT);
// Run the highlighter on the folded strings. We don't care about the
// output; our replacer function will build the canonical highlighted
// string, with original accented characters.
// Tack on the remainder of the haystack that wasn't highlighted, if
// any.
}
// Highlight and escape the string.
}
}
},
/**
Accent-folding version of `start()`.
@method startFold
@param {String} haystack String to apply highlighting to.
@param {String|String[]} needles String or array of strings that should be
highlighted.
@return {String} Escaped and highlighted copy of _haystack_.
@static
**/
},
/**
Accent-folding version of `words()`.
@method wordsFold
@param {String} haystack String to apply highlighting to.
@param {String|String[]} needles String or array of strings containing words
that should be highlighted. If a string is passed, it will be split
into words; if an array is passed, it is assumed to have already been
split.
@return {String} Escaped and highlighted copy of _haystack_.
@static
**/
}
}
});
}
});