B2G/gaia/apps/email/js/ext/mailapi/worker-bootstrap.js
/**
 * Assists in generating a `FilterMatchItem` for a substring that is part of a
 * much longer string where we expect we need to reduce things down to a
 * snippet.
 *
 * Context generating is whitespace-aware and tries to avoid leaving partial
 * words.  In the event our truncation would leave us without any context
 * whatsoever, we will leave partial words.  This is also important for us not
 * being rude to CJK languages (although the number used for contextBefore may
 * be too high for CJK, we may want to have them 'cost' more.)
 *
 * We don't pursue any whitespace normalization here because we want our offsets
 * to line up properly with the real data, but also because we can depend on
 * HTML to help us out and normalize everything anyways.
 */
Assists in generating a `FilterMatchItem` for a substring that is part of a
much longer string where we expect we need to reduce things down to a
snippet.

Context generating is whitespace-aware and tries to avoid leaving partial
words.  In the event our truncation would leave us without any context
whatsoever, we will leave partial words.  This is also important for us not
being rude to CJK languages (although the number used for contextBefore may
be too high for CJK, we may want to have them 'cost' more.)

We don't pursue any whitespace normalization here because we want our offsets
to line up properly with the real data, but also because we can depend on
HTML to help us out and normalize everything anyways.
Assists in generating a ` FilterMatchItem ` for a substring that is part of a much longer string where we expect we need to reduce things down to a snippet . Context generating is whitespace - aware and tries to avoid leaving partial words . In the event our truncation would leave us without any context whatsoever we will leave partial words . This is also important for us not being rude to CJK languages ( although the number used for contextBefore may be too high for CJK we may want to have them ' cost ' more . ) We don ' t pursue any whitespace normalization here because we want our offsets to line up properly with the real data but also because we can depend on HTML to help us out and normalize everything anyways .
function snippetMatchHelper(str, start, length, contextBefore, contextAfter,
                            path) {
  if (contextBefore > start)
    contextBefore = start;
  var offset = str.indexOf(' ', start - contextBefore);
  if (offset === -1)
    offset = 0;
  if (offset >= start)
    offset = start - contextBefore;
  var endIdx = str.lastIndexOf(' ', start + length + contextAfter);
  if (endIdx <= start + length)
    endIdx = start + length + contextAfter;
  var snippet = str.substring(offset, endIdx);
  return {
    text: snippet,
    offset: offset,
    matchRuns: [{ start: start - offset, length: length }],
    path: path
  };
}
function snippetMatchHelper ( str , start , length , contextBefore , contextAfter , path ) { if ( contextBefore > start ) contextBefore = start ; var offset = str . indexOf ( ' ' , start - contextBefore ) ; if ( offset === - 1 ) offset = 0 ; if ( offset >= start ) offset = start - contextBefore ; var endIdx = str . lastIndexOf ( ' ' , start + length + contextAfter ) ; if ( endIdx <= start + length ) endIdx = start + length + contextAfter ; var snippet = str . substring ( offset , endIdx ) ; return { text : snippet , offset : offset , matchRuns : [ { start : start - offset , length : length } ] , path : path } ; }
Assists in generating a `FilterMatchItem` for a substring that is part of a
 much longer string where we expect we need to reduce things down to a
 snippet.
Assists in generating a ` FilterMatchItem ` for a substring that is part of a much longer string where we expect we need to reduce things down to a snippet .