-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (70 loc) · 2.56 KB
/
script.js
File metadata and controls
83 lines (70 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const _PROPRIEDADE_ = " { get; set; }";
const _VISIBILIDADE_ = " public ";
function LimparSaida(){
document.getElementById('outputText').value = "";
}
function Converter(){
LimparSaida();
let input = (document.getElementById("inputText").value).split(/\r?\n/);
input.forEach(function(linha){
let classe;
let modificado = TrocarCaracterEspecial(linha);
if(modificado.match(/[a-z]/i)){
classe = ChecarAtributo(linha);
if(classe == linha) classe = ChecarCriacaoTabela(modificado);
if(classe == linha) classe = -1;
}
else classe = modificado + "\n";
if(modificado != "" && classe != -1 && classe != modificado) document.getElementById('outputText').value += classe;
});
}
function TrocarCaracterEspecial(linha){
if(linha.indexOf("(") > -1) linha = linha.replace("(", "{");
if(linha.indexOf(");") > -1) linha = linha.replace(");", "}");
if(linha.indexOf(")") > -1) linha = linha.replace(")", "}");
return linha;
}
function ChecarAtributo(linha){
let nome, tipo;
let nomeTipo = RetornarNomeTipo(linha.split(' '));
if(nomeTipo[1] == undefined) return linha;
nome = nomeTipo[0];
tipo = nomeTipo[1].toUpperCase();
if(ProcurarTipos(tipo)) return _VISIBILIDADE_ + ProcurarTipos(tipo) + nome;
return linha;
}
function RetornarNomeTipo(linha){
let nomeTipo = [], qtd = 0;
linha.forEach(function (parte){
if(parte != '' && qtd == 1){
nomeTipo.push(parte);
qtd++;
}
if(parte != '' && qtd == 0){
nomeTipo.push(parte + _PROPRIEDADE_ + "\n");
qtd++;
}
});
return nomeTipo;
}
function ProcurarTipos(linha){
if(linha.indexOf("TINYINT") > -1) return "sbyte ";
if(linha.indexOf("SMALLINT") > -1) return "short ";
if(linha.indexOf("BIGINT") > -1) return "long ";
if(linha.indexOf("INT") > -1) return "int ";
if(linha.indexOf("FLOAT") > -1) return "float ";
if(linha.indexOf("DOUBLE") > -1) return "double ";
if(linha.indexOf("DECIMAL") > -1) return "decimal ";
if(linha.indexOf("CHAR") > -1) return "string ";
if(linha.indexOf("TEXT") > -1) return "string ";
if(linha.indexOf("BOOLEAN") > -1) return "bool ";
if(linha.indexOf("DATE") > -1) return "DateTime ";
return false;
}
function ChecarCriacaoTabela(linha){
if(linha.toUpperCase().indexOf("CREATE TABLE") > -1){
linha = linha.replace(/CREATE TABLE/gi, "public class");
return linha + "\n";
}
return linha;
}