@@ -268,63 +268,11 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
268268 switch value .Type {
269269 case KeyTypeBlock :
270270 if nil != value .Block && nil != other && nil != other .Block {
271- switch operator {
272- case FilterOperatorIsEqual :
273- return value .Block .Content == other .Block .Content
274- case FilterOperatorIsNotEqual :
275- return value .Block .Content != other .Block .Content
276- case FilterOperatorContains :
277- return strings .Contains (value .Block .Content , other .Block .Content )
278- case FilterOperatorDoesNotContain :
279- return ! strings .Contains (value .Block .Content , other .Block .Content )
280- case FilterOperatorStartsWith :
281- return strings .HasPrefix (value .Block .Content , other .Block .Content )
282- case FilterOperatorEndsWith :
283- return strings .HasSuffix (value .Block .Content , other .Block .Content )
284- case FilterOperatorIsEmpty :
285- return "" == strings .TrimSpace (value .Block .Content )
286- case FilterOperatorIsNotEmpty :
287- return "" != strings .TrimSpace (value .Block .Content )
288- }
271+ return filterTextContent (operator , value .Block .Content , other .Block .Content )
289272 }
290273 case KeyTypeText :
291274 if nil != value .Text && nil != other && nil != other .Text {
292- switch operator {
293- case FilterOperatorIsEqual :
294- if "" == strings .TrimSpace (other .Text .Content ) {
295- return true
296- }
297- return value .Text .Content == other .Text .Content
298- case FilterOperatorIsNotEqual :
299- if "" == strings .TrimSpace (other .Text .Content ) {
300- return true
301- }
302- return value .Text .Content != other .Text .Content
303- case FilterOperatorContains :
304- if "" == strings .TrimSpace (other .Text .Content ) {
305- return true
306- }
307- return strings .Contains (value .Text .Content , other .Text .Content )
308- case FilterOperatorDoesNotContain :
309- if "" == strings .TrimSpace (other .Text .Content ) {
310- return true
311- }
312- return ! strings .Contains (value .Text .Content , other .Text .Content )
313- case FilterOperatorStartsWith :
314- if "" == strings .TrimSpace (other .Text .Content ) {
315- return true
316- }
317- return strings .HasPrefix (value .Text .Content , other .Text .Content )
318- case FilterOperatorEndsWith :
319- if "" == strings .TrimSpace (other .Text .Content ) {
320- return true
321- }
322- return strings .HasSuffix (value .Text .Content , other .Text .Content )
323- case FilterOperatorIsEmpty :
324- return "" == strings .TrimSpace (value .Text .Content )
325- case FilterOperatorIsNotEmpty :
326- return "" != strings .TrimSpace (value .Text .Content )
327- }
275+ return filterTextContent (operator , value .Text .Content , other .Text .Content )
328276 }
329277 case KeyTypeNumber :
330278 if nil != value .Number && nil != other && nil != other .Number {
@@ -448,66 +396,15 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
448396 }
449397 case KeyTypeURL :
450398 if nil != value .URL && nil != other && nil != other .URL {
451- switch operator {
452- case FilterOperatorIsEqual :
453- return value .URL .Content == other .URL .Content
454- case FilterOperatorIsNotEqual :
455- return value .URL .Content != other .URL .Content
456- case FilterOperatorContains :
457- return strings .Contains (value .URL .Content , other .URL .Content )
458- case FilterOperatorDoesNotContain :
459- return ! strings .Contains (value .URL .Content , other .URL .Content )
460- case FilterOperatorStartsWith :
461- return strings .HasPrefix (value .URL .Content , other .URL .Content )
462- case FilterOperatorEndsWith :
463- return strings .HasSuffix (value .URL .Content , other .URL .Content )
464- case FilterOperatorIsEmpty :
465- return "" == strings .TrimSpace (value .URL .Content )
466- case FilterOperatorIsNotEmpty :
467- return "" != strings .TrimSpace (value .URL .Content )
468- }
399+ return filterTextContent (operator , value .URL .Content , other .URL .Content )
469400 }
470401 case KeyTypeEmail :
471402 if nil != value .Email && nil != other && nil != other .Email {
472- switch operator {
473- case FilterOperatorIsEqual :
474- return value .Email .Content == other .Email .Content
475- case FilterOperatorIsNotEqual :
476- return value .Email .Content != other .Email .Content
477- case FilterOperatorContains :
478- return strings .Contains (value .Email .Content , other .Email .Content )
479- case FilterOperatorDoesNotContain :
480- return ! strings .Contains (value .Email .Content , other .Email .Content )
481- case FilterOperatorStartsWith :
482- return strings .HasPrefix (value .Email .Content , other .Email .Content )
483- case FilterOperatorEndsWith :
484- return strings .HasSuffix (value .Email .Content , other .Email .Content )
485- case FilterOperatorIsEmpty :
486- return "" == strings .TrimSpace (value .Email .Content )
487- case FilterOperatorIsNotEmpty :
488- return "" != strings .TrimSpace (value .Email .Content )
489- }
403+ return filterTextContent (operator , value .Email .Content , other .URL .Content )
490404 }
491405 case KeyTypePhone :
492406 if nil != value .Phone && nil != other && nil != other .Phone {
493- switch operator {
494- case FilterOperatorIsEqual :
495- return value .Phone .Content == other .Phone .Content
496- case FilterOperatorIsNotEqual :
497- return value .Phone .Content != other .Phone .Content
498- case FilterOperatorContains :
499- return strings .Contains (value .Phone .Content , other .Phone .Content )
500- case FilterOperatorDoesNotContain :
501- return ! strings .Contains (value .Phone .Content , other .Phone .Content )
502- case FilterOperatorStartsWith :
503- return strings .HasPrefix (value .Phone .Content , other .Phone .Content )
504- case FilterOperatorEndsWith :
505- return strings .HasSuffix (value .Phone .Content , other .Phone .Content )
506- case FilterOperatorIsEmpty :
507- return "" == strings .TrimSpace (value .Phone .Content )
508- case FilterOperatorIsNotEmpty :
509- return "" != strings .TrimSpace (value .Phone .Content )
510- }
407+ return filterTextContent (operator , value .Phone .Content , other .Phone .Content )
511408 }
512409 case KeyTypeMAsset :
513410 if nil != value .MAsset && nil != other && nil != other .MAsset && 0 < len (value .MAsset ) && 0 < len (other .MAsset ) {
@@ -619,6 +516,46 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa
619516 return false
620517}
621518
519+ func filterTextContent (operator FilterOperator , valueContent , otherValueContent string ) bool {
520+ switch operator {
521+ case FilterOperatorIsEqual :
522+ if "" == strings .TrimSpace (otherValueContent ) {
523+ return true
524+ }
525+ return valueContent == otherValueContent
526+ case FilterOperatorIsNotEqual :
527+ if "" == strings .TrimSpace (otherValueContent ) {
528+ return true
529+ }
530+ return valueContent != otherValueContent
531+ case FilterOperatorContains :
532+ if "" == strings .TrimSpace (otherValueContent ) {
533+ return true
534+ }
535+ return strings .Contains (valueContent , otherValueContent )
536+ case FilterOperatorDoesNotContain :
537+ if "" == strings .TrimSpace (otherValueContent ) {
538+ return true
539+ }
540+ return ! strings .Contains (valueContent , otherValueContent )
541+ case FilterOperatorStartsWith :
542+ if "" == strings .TrimSpace (otherValueContent ) {
543+ return true
544+ }
545+ return strings .HasPrefix (valueContent , otherValueContent )
546+ case FilterOperatorEndsWith :
547+ if "" == strings .TrimSpace (otherValueContent ) {
548+ return true
549+ }
550+ return strings .HasSuffix (valueContent , otherValueContent )
551+ case FilterOperatorIsEmpty :
552+ return "" == strings .TrimSpace (valueContent )
553+ case FilterOperatorIsNotEmpty :
554+ return "" != strings .TrimSpace (valueContent )
555+ }
556+ return false
557+ }
558+
622559func filterRelativeTime (valueMills int64 , valueIsNotEmpty bool , operator FilterOperator , otherValueStart , otherValueEnd time.Time , direction RelativeDateDirection , otherValueStart2 , otherValueEnd2 time.Time , direction2 RelativeDateDirection ) bool {
623560 valueTime := time .UnixMilli (valueMills )
624561 switch operator {
0 commit comments