Adds a case-sensitivity permutation routine

git-svn-id: file:///home/svn/framework3/trunk@5780 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2008-10-22 22:43:13 +00:00
parent 65419ad206
commit 1df0612f61
1 changed files with 26 additions and 1 deletions

View File

@ -915,6 +915,31 @@ module Text
return arr
end
# Permute the case of a word
def self.permute_case(word, idx=0)
res = []
if( (UpperAlpha+LowerAlpha).index(word[idx,1]))
word_ucase = word.dup
word_ucase[idx, 1] = word[idx, 1].upcase
word_lcase = word.dup
word_lcase[idx, 1] = word[idx, 1].downcase
if (idx == word.length)
return [word]
else
res << permute_case(word_ucase, idx+1)
res << permute_case(word_lcase, idx+1)
end
else
res << permute_case(word, idx+1)
end
res.flatten
end
# Generate a random hostname
def self.rand_hostname
host = []
@ -1022,4 +1047,4 @@ protected
end
end
end
end