- Joined
- Oct 20, 2007
- Messages
- 353
I know that there already exists one ASCII library made by Bribe.
I have looked at it and realised that it uses 4 arrays.
I made some research and found a way to use only 2 arrays.
Also I have excluded useless chars with ASCII code over 126.
So here it is:
Testing trigger:
I have looked at it and realised that it uses 4 arrays.
I made some research and found a way to use only 2 arrays.
Also I have excluded useless chars with ASCII code over 126.
So here it is:
JASS:
library SimpleAscii initializer Init // by D.O.G.
globals
private integer array h
private string array c
endglobals
function C2A takes string char returns integer
local integer i = StringHash(char)
if StringCase(char, true) == char then
set i = i + 1
endif
if i < 0 then
set i = -i
endif
return h[i - (i / 982) * 982]
endfunction
function A2C takes integer ascii returns string
return c[ascii]
endfunction
function A2S takes integer ascii returns string
local string s = ""
local integer i
loop
set i = ascii / 256
set s = c[ascii - i * 256] + s
set ascii = i
exitwhen ascii == 0
endloop
return s
endfunction
function S2A takes string s returns integer
local integer a = 0
local integer l = StringLength(s)
local integer i = 0
loop
exitwhen i == l
set a = a * 256 + C2A(SubString(s, i, i + 1))
set i = i + 1
endloop
return a
endfunction
private function Init takes nothing returns nothing
set c[8] = "\b"
set c[9] = "\t"
set c[10] = "\n"
set c[12] = "\f"
set c[13] = "\r"
set c[32] = " "
set c[33] = "!"
set c[34] = "\""
set c[35] = "#"
set c[36] = "$"
set c[37] = "%"
set c[38] = "&"
set c[39] = "'"
set c[40] = "("
set c[41] = ")"
set c[42] = "*"
set c[43] = "+"
set c[44] = ","
set c[45] = "-"
set c[46] = "."
set c[47] = "/"
set c[48] = "0"
set c[49] = "1"
set c[50] = "2"
set c[51] = "3"
set c[52] = "4"
set c[53] = "5"
set c[54] = "6"
set c[55] = "7"
set c[56] = "8"
set c[57] = "9"
set c[58] = ":"
set c[59] = ";"
set c[60] = "<"
set c[61] = "="
set c[62] = ">"
set c[63] = "?"
set c[64] = "@"
set c[65] = "A"
set c[66] = "B"
set c[67] = "C"
set c[68] = "D"
set c[69] = "E"
set c[70] = "F"
set c[71] = "G"
set c[72] = "H"
set c[73] = "I"
set c[74] = "J"
set c[75] = "K"
set c[76] = "L"
set c[77] = "M"
set c[78] = "N"
set c[79] = "O"
set c[80] = "P"
set c[81] = "Q"
set c[82] = "R"
set c[83] = "S"
set c[84] = "T"
set c[85] = "U"
set c[86] = "V"
set c[87] = "W"
set c[88] = "X"
set c[89] = "Y"
set c[90] = "Z"
set c[91] = "["
set c[93] = "]"
set c[94] = "^"
set c[95] = "_"
set c[96] = "`"
set c[97] = "a"
set c[98] = "b"
set c[99] = "c"
set c[100] = "d"
set c[101] = "e"
set c[102] = "f"
set c[103] = "g"
set c[104] = "h"
set c[105] = "i"
set c[106] = "j"
set c[107] = "k"
set c[108] = "l"
set c[109] = "m"
set c[110] = "n"
set c[111] = "o"
set c[112] = "p"
set c[113] = "q"
set c[114] = "r"
set c[115] = "s"
set c[116] = "t"
set c[117] = "u"
set c[118] = "v"
set c[119] = "w"
set c[120] = "x"
set c[121] = "y"
set c[122] = "z"
set c[123] = "{"
set c[124] = "|"
set c[125] = "}"
set c[126] = "~"
set h[122] = 8
set h[632] = 9
set h[505] = 10
set h[238] = 12
set h[348] = 13
set h[98] = 32
set h[513] = 33
set h[620] = 34
set h[306] = 35
set h[818] = 36
set h[164] = 37
set h[282] = 38
set h[698] = 39
set h[851] = 40
set h[886] = 41
set h[724] = 42
set h[433] = 43
set h[67] = 44
set h[250] = 45
set h[26] = 46
set h[487] = 47
set h[495] = 48
set h[571] = 49
set h[48] = 50
set h[292] = 51
set h[950] = 52
set h[528] = 53
set h[918] = 54
set h[27] = 55
set h[370] = 56
set h[136] = 57
set h[172] = 58
set h[373] = 59
set h[527] = 60
set h[737] = 61
set h[951] = 62
set h[697] = 63
set h[934] = 64
set h[276] = 65
set h[805] = 66
set h[101] = 67
set h[191] = 68
set h[399] = 69
set h[657] = 70
set h[249] = 71
set h[379] = 72
set h[153] = 73
set h[711] = 74
set h[960] = 75
set h[480] = 76
set h[426] = 77
set h[624] = 78
set h[729] = 79
set h[303] = 80
set h[177] = 81
set h[654] = 82
set h[647] = 83
set h[828] = 84
set h[24] = 85
set h[909] = 86
set h[716] = 87
set h[511] = 88
set h[83] = 89
set h[145] = 90
set h[132] = 91
set h[415] = 93
set h[121] = 94
set h[409] = 95
set h[778] = 96
set h[277] = 97
set h[806] = 98
set h[102] = 99
set h[192] = 100
set h[398] = 101
set h[656] = 102
set h[248] = 103
set h[380] = 104
set h[152] = 105
set h[712] = 106
set h[959] = 107
set h[481] = 108
set h[425] = 109
set h[623] = 110
set h[728] = 111
set h[302] = 112
set h[176] = 113
set h[653] = 114
set h[646] = 115
set h[827] = 116
set h[25] = 117
set h[908] = 118
set h[717] = 119
set h[512] = 120
set h[84] = 121
set h[146] = 122
set h[561] = 123
set h[604] = 124
set h[807] = 125
set h[96] = 126
endfunction
endlibrary
Testing trigger:
JASS:
library SimpleAsciiTest initializer Init requires SimpleAscii
private function Init takes nothing returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 300.0, I2S('TEST'))
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 300.0, I2S(S2A("TEST")))
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 300.0, A2S(1413829460))
endfunction
endlibrary
Last edited: