Created
May 17, 2011 17:46
-
-
Save semihozkoroglu/976957 to your computer and use it in GitHub Desktop.
html veriyi düz metin yapmak için (belirli karakterler için tanımlı)
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
using System; | |
using System.IO; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace MetinBicimleme | |
{ | |
public class OkumaYazma | |
{ | |
public static string Oku(string DosyaAdresi) | |
{ | |
string okunan = ""; | |
StreamReader sr = new StreamReader(DosyaAdresi); | |
okunan = sr.ReadToEnd(); | |
sr.Close(); | |
return okunan; | |
} | |
} | |
public class Stack | |
{ | |
public string[] depo; | |
public int dp = 0; | |
public string[] buf; | |
private string tmp;//pop icin ara degisken. | |
private int sp = 0; //stack degiskenimiz. | |
private int spboy; | |
public Stack(int boy) | |
{ | |
depo = new string[boy]; | |
buf = new string[boy]; | |
spboy = boy;//push methodu icin | |
} | |
public Boolean isEmpty() | |
{ | |
if ( sp == 0 ) | |
return true; | |
else | |
return false; | |
} | |
public string peek() | |
{ | |
if (isEmpty()) | |
return null; | |
return buf[sp-1]; | |
} | |
public string pop() | |
{ | |
if (isEmpty()) | |
return null; | |
tmp = buf[sp - 1]; | |
buf[sp - 1] = null; | |
sp--; | |
return tmp; | |
} | |
public int push(string p) | |
{ | |
if (sp == spboy) | |
return -1; | |
buf[sp++] = p; | |
depo[dp++] = p; | |
return 0; | |
} | |
} | |
class Program | |
{ | |
static int control(string str, Stack nesne) | |
{ | |
int i = 0; | |
while (true) | |
{ | |
if (str[i] == '<' && str[i + 1] != '/') | |
{ | |
if (str[i + 2] != '>') | |
return 0; | |
nesne.push(char.ToString(str[i + 1])); | |
i++; | |
} | |
else if (str[i] == '<' && str[i + 1] == '/') | |
{ | |
if (nesne.isEmpty()) | |
return 0; | |
if (str[i + 3] != '>') | |
return 0; | |
if (!(nesne.peek() == char.ToString(str[i + 2]))) | |
return 0; | |
nesne.pop(); | |
i++; | |
} | |
else | |
{ | |
if ((i == str.Length - 1) && nesne.isEmpty()) | |
return 1; | |
else if (i == str.Length-1) | |
return 0; | |
i++; | |
} | |
} | |
} | |
static void ekranabas(string str, Stack stck) | |
{ | |
int t = 2, yazma = 1; | |
int i = 0; | |
while (true) | |
{ | |
if (str[i] == '<' && str[i + 1] != '/') | |
{ | |
stck.push(char.ToString(str[i + 1])); | |
if (char.ToString(str[i + 1]) == "p") | |
{ | |
if (!(Array.IndexOf(stck.buf, "h") != -1)) | |
{ | |
if (Array.IndexOf(stck.buf, "b") != -1) | |
{ | |
while (t-- > 0) | |
Console.Write("["); | |
t = 2; | |
} | |
else | |
{ | |
Console.Write("["); | |
} | |
} | |
} | |
i += 3 ; | |
} | |
else if (str[i] == '<' && str[i + 1] == '/') | |
{ | |
if (stck.peek() == "h") | |
yazma = 1; | |
if (stck.pop() == "p" && (yazma == 1)) | |
{ | |
if (Array.IndexOf(stck.buf, "b") != -1) | |
{ | |
while (t-- > 0) | |
Console.Write("]"); | |
t = 2; | |
} | |
else | |
{ | |
Console.Write("]"); | |
} | |
} | |
i += 4; | |
if (i >= str.Length - 1) | |
break; | |
} | |
else | |
{ | |
if (Array.IndexOf(stck.buf, "h") != -1) | |
{ | |
i++; | |
if (Array.IndexOf(stck.buf, "p") != -1)//p 'i kapatirkende yazma | |
yazma = 0; | |
} | |
else | |
{ | |
if (Array.IndexOf(stck.buf, "b") != -1) | |
{ | |
if (Array.IndexOf(stck.buf, "u") != -1) | |
{ | |
while (t-- > 0) | |
Console.Write(char.ToString(str[i]).ToUpper()); | |
t = 2; | |
} | |
else | |
{ | |
while (t-- > 0) | |
Console.Write(str[i]); | |
t = 2; | |
} | |
i++; | |
} | |
else if (Array.IndexOf(stck.buf, "u") != -1) | |
{ | |
Console.Write(char.ToString(str[i]).ToUpper()); | |
i++; | |
} | |
else | |
{ | |
Console.Write(str[i++]); | |
} | |
if (i >= str.Length - 1) | |
break; | |
} | |
} | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Stack a = new Stack(100); | |
string str = OkumaYazma.Oku("C:/Kaynak.txt"); | |
if (control(str, a) == 0) | |
Console.WriteLine("Kaynak dosyanin bicimleme etiketleri hatalidir, kontrol ediniz."); | |
else | |
ekranabas(str, a); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment