Last active
December 28, 2015 03:09
-
-
Save austa/7433551 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack | |
def initialize | |
@liste = [] | |
end | |
def isEmpty | |
return @liste == [] | |
end | |
def push(eleman) | |
@liste.push eleman | |
end | |
def pop | |
return @liste.pop | |
end | |
def peek | |
return @liste[-1] | |
end | |
def size | |
return @liste.length | |
end | |
end | |
def html_filtrele(dosya_adi) | |
tag_dizisi = [] | |
File.open("./" + dosya_adi).each do |line| | |
i = 0 | |
string = "" | |
while line.length > i and line[i] != '\0' | |
if line[i] == '<' | |
i += 1 | |
while line[i] != '>' | |
string += line[i].to_s() | |
i += 1 | |
end | |
tag_dizisi.push(string) | |
end | |
string = "" | |
i +=1 | |
end | |
end | |
return tag_dizisi | |
end | |
def tag_checker(tag_dizisi) | |
s = Stack.new() | |
deger = true | |
counter = 0 | |
while tag_dizisi.length > counter and deger | |
gelen = tag_dizisi[counter] | |
if not gelen.include? '/' | |
s.push(gelen) | |
else | |
if s.isEmpty | |
deger = false | |
else | |
son_eleman = s.pop | |
if not karsilastir(son_eleman, gelen) | |
deger = false | |
end | |
end | |
end | |
counter += 1 | |
end | |
if s.isEmpty and deger | |
return true | |
else | |
return false | |
end | |
end | |
def karsilastir(atag,ktag) | |
i = 1 | |
j = 0 | |
while ktag.length > i | |
if not atag[j] == ktag[i] | |
return false | |
end | |
j += 1 | |
i += 1 | |
end | |
return true | |
end | |
def html_tag_checker(dosya_adi) | |
taglar_dizisi = html_filtrele(dosya_adi) | |
return tag_checker(taglar_dizisi) | |
end | |
puts html_tag_checker("ornekhtml") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment