Skip to content
This repository has been archived by the owner on Feb 10, 2018. It is now read-only.

Commit

Permalink
Implement validate.is_exact for exact search of needle in haystack
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaustav Das Modak committed Jan 20, 2013
1 parent b0bc1f6 commit f8c600d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pyavrophonetic/utils/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def is_case_sensitive(text):
else:
return False

def is_exact(needle, haystack, start, end, matchnot):
"""Check exact occurrence of needle in haystack"""
return (start >= 0 and end < len(haystack) and
(haystack[start:end] == needle) ^ matchnot)

def fix_string_case(text):
"""Converts case-insensitive characters to lower case
Expand Down
7 changes: 7 additions & 0 deletions tests/test_utils_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ def test_fix_string_case(self):
# 'raMgoRurer Chana' should become 'ramgoRurer chana'
self.assertEquals(validate.fix_string_case('raMgoRurer Chana'),
'ramgoRurer chana')

def test_is_exact(self):
"""Test exact search response of needle in haystack"""
self.assertTrue(validate.is_exact('abcd', 'abcdefgh', 0, 4, False))
self.assertFalse(validate.is_exact('abcd', 'abcdefgh', 0, 4, True))
self.assertFalse(validate.is_exact('bcd', 'abcdefgh', 0, 4, False))
self.assertTrue(validate.is_exact('bcd', 'abcdefgh', 0, 4, True))

0 comments on commit f8c600d

Please sign in to comment.