Trims field values to address any validation problems with whitespace.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150865 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kelvin Tan 2002-12-05 00:21:45 +00:00
parent 0bf9042be4
commit 96c581df2c
1 changed files with 18 additions and 1 deletions

View File

@ -101,6 +101,8 @@ function doMakeQuery( query )
function addFieldWithModifier(query, modifier, field, fieldValue)
{
fieldValue = trim(fieldValue);
if(query.value.length == 0)
{
query.value = modifier + '(' + field + ':(' + fieldValue + '))';
@ -110,3 +112,18 @@ function addFieldWithModifier(query, modifier, field, fieldValue)
query.value = query.value + ' ' + modifier + '(' + field + ':(' + fieldValue + '))';
}
}
function trim(inputString) {
if (typeof inputString != "string") { return inputString; }
var temp = inputString;
// Replace whitespace with a single space
var pattern = /\s/ig;
temp = temp.replace(pattern, " ");
// Trim
pattern = /^(\s*)([\w\W]*)(\b\s*$)/;
if (pattern.test(temp)) { temp = temp.replace(pattern, "$2"); }
return temp; // Return the trimmed string back to the user
}