Skip to content

Instantly share code, notes, and snippets.

@dangalipo
Created September 28, 2011 15:20
Show Gist options
  • Select an option

  • Save dangalipo/1248213 to your computer and use it in GitHub Desktop.

Select an option

Save dangalipo/1248213 to your computer and use it in GitHub Desktop.
class Foo
def self.pat_test(subject, pattern)
notfound = -1
iSub = 0
rtnIndex = notfound
isPat = false;
subjectLen = subject.length;
patternLen = pattern.length;
while (isPat == false && iSub + patternLen - 1 < subjectLen)
if (subject[iSub] == pattern[0])
rtnIndex = iSub
isPat = true
(1..(patternLen-1)).each do |iPat|
if (subject[iSub + iPat] != pattern[iPat])
rtnIndex = notfound;
isPat = false;
break
end
end
end
iSub = iSub + 1
end
[rtnIndex, iSub]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment