mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Bug fix in the FTS1 snippet generator. Improvements in the way the snippet
generator handles whitespace. (CVS 3448) FossilOrigin-Name: d3f4ae827582bd0aac54ae3211d272a1429b6523
This commit is contained in:
@ -2298,11 +2298,32 @@ static int wordBoundary(
|
||||
return iBreak;
|
||||
}
|
||||
|
||||
/*
|
||||
** If the StringBuffer does not end in white space, add a single
|
||||
** space character to the end.
|
||||
*/
|
||||
static void appendWhiteSpace(StringBuffer *p){
|
||||
if( p->len==0 ) return;
|
||||
if( isspace(p->s[p->len-1]) ) return;
|
||||
append(p, " ");
|
||||
}
|
||||
|
||||
/*
|
||||
** Remove white space from teh end of the StringBuffer
|
||||
*/
|
||||
static void trimWhiteSpace(StringBuffer *p){
|
||||
while( p->len>0 && isspace(p->s[p->len-1]) ){
|
||||
p->len--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Allowed values for Snippet.aMatch[].snStatus
|
||||
*/
|
||||
#define SNIPPET_IGNORE 0 /* It is ok to omit this match from the snippet */
|
||||
#define SNIPPET_DESIRED 1 /* We want to include this match in the snippet */
|
||||
#define SNIPPET_DESIRED 1 /* We want to include this match in the snippet */
|
||||
|
||||
/*
|
||||
** Generate the text of a snippet.
|
||||
@ -2369,8 +2390,12 @@ static void snippetText(
|
||||
wantEllipsis = 0;
|
||||
tailEllipsis = 0;
|
||||
}
|
||||
if( iCol!=tailCol || iStart!=tailOffset ){
|
||||
appendWhiteSpace(&sb);
|
||||
}
|
||||
if( wantEllipsis || tailEllipsis ){
|
||||
append(&sb, zEllipsis);
|
||||
appendWhiteSpace(&sb);
|
||||
}
|
||||
iEnd = aMatch[i].iStart + aMatch[i].nByte + 40;
|
||||
iEnd = wordBoundary(iEnd, zDoc, nDoc, aMatch, nMatch, iCol);
|
||||
@ -2382,8 +2407,12 @@ static void snippetText(
|
||||
}
|
||||
while( iMatch<nMatch && aMatch[iMatch].iCol<iCol ){ iMatch++; }
|
||||
while( iStart<iEnd ){
|
||||
while( iMatch<nMatch && aMatch[iMatch].iStart<iStart ){ iMatch++; }
|
||||
if( iMatch<nMatch && aMatch[iMatch].iStart<iEnd ){
|
||||
while( iMatch<nMatch && aMatch[iMatch].iStart<iStart
|
||||
&& aMatch[iMatch].iCol<=iCol ){
|
||||
iMatch++;
|
||||
}
|
||||
if( iMatch<nMatch && aMatch[iMatch].iStart<iEnd
|
||||
&& aMatch[iMatch].iCol==iCol ){
|
||||
nappend(&sb, &zDoc[iStart], aMatch[iMatch].iStart - iStart);
|
||||
iStart = aMatch[iMatch].iStart;
|
||||
append(&sb, zStartMark);
|
||||
@ -2405,7 +2434,9 @@ static void snippetText(
|
||||
tailCol = iCol;
|
||||
tailOffset = iEnd;
|
||||
}
|
||||
trimWhiteSpace(&sb);
|
||||
if( tailEllipsis ){
|
||||
appendWhiteSpace(&sb);
|
||||
append(&sb, zEllipsis);
|
||||
}
|
||||
pCursor->snippet.zSnippet = sb.s;
|
||||
|
Reference in New Issue
Block a user