Darthfett
Aerospace/Cybersecurity Software Engineer
- Reaction score
- 615
stringType
Created by Darthfett
Created by Darthfett
Description:
A small collection of functions that can be used to determine a string's type, such as if it is numerical, a metacharacter, etc.
Requirements:
N/A
The rest of the documentation can be found in the system code, below:
JASS:
library stringType
/*
__________________________________________________________________________________
stringType library, created by Darthfett - version 1.2
http://www.thehelper.net/forums/showthread.php?t=143592
Requirements
-vJass compiler (such as JASSHelper)
-If you remove the library and multi-line comment(s), you can make this JASS compatable.
Documentation
-All functions are standalone. Feel free to copy an individual function.
-Credit for this library is not necessary. Feel free to use it in your map.
If you feel obligated to credit me, I won't object. I only ask that you do
not simply copy and paste the library as your own.
API
function IsInt takes string s returns boolean
returns whether a string is a numeric integer.
(Not necessarily within integer bounds)
function IsReal takes string s returns boolean
returns whether a string a numeric real.
(Not necessarily within real bounds)
function IsLetter takes string s returns boolean
returns whether the specified character is a letter (a-z,A-Z).
function IsLetters takes string s returns boolean
returns whether the specified string contains only letters (a-z,A-Z).
function IsMeta takes string s returns boolean
returns whether the specified character is a metacharacter (!@#$%^...)
function IsMetas takes string s returns boolean
returns whether the specified string contains only metacharacters (!@#$%...)
__________________________________________________________________________________
*/
function IsInt takes string s returns boolean
local integer i = 0
local integer j
local string c
local integer len
local integer sublen
if s == "" or s == null or s == "-" or s == "+" then
return false
endif
if I2S(S2I(s)) == s then
return true
endif
set len = StringLength(s)
loop
set sublen = IMinBJ(i+8,len)
exitwhen i == len
set c = SubString(s,i,sublen)
if I2S(S2I(c)) != c then
set j = sublen
loop
exitwhen j == i
set c = SubString(s,j-1,j)
if I2S(S2I(c)) != c then
if (c == "+" or c == "-") and j == 1 then
//pass
else
return false
endif
endif
set j = j - 1
endloop
endif
set i = sublen
endloop
return true
endfunction
function IsReal takes string s returns boolean
local integer i = 0
local integer j
local integer k = 0
local string c
local integer len
local integer sublen
if s == "" or s == null or s == "-" or s == "+" then
return false
endif
if R2S(S2R(s)) == s then
return true
endif
set len = StringLength(s)
loop
set sublen = IMinBJ(i+8,len)
exitwhen i == len
set c = SubString(s,i,sublen)
if I2S(S2I(c)) != c then
if R2S(S2R(c)) == c then
set k = k + 1
if k > 1 then
return false
endif
else
set j = sublen
loop
exitwhen j == i
set c = SubString(s,j-1,j)
if I2S(S2I(c)) != c then
if c == "." then
set k = k + 1
if k > 1 then
return false
endif
elseif (c == "+" or c == "-") and j == 1 then
//pass
else
return false
endif
endif
set j = j - 1
endloop
endif
endif
set i = sublen
endloop
return true
endfunction
function IsLetter takes string s returns boolean
return StringCase(s,true) != StringCase(s,false) and StringLength(s) == 1
endfunction
function IsLetters takes string s returns boolean
local integer i = 0
local string str
loop
set str = SubString(s, i, i + 1)
exitwhen str == ""
if StringCase(s,true) == StringCase(s,false) then
return false
endif
set i = i + 1
endloop
return true
endfunction
function IsMeta takes string s returns boolean
return I2S(S2I(s)) != s and StringCase(s,true) == StringCase(s,false) and StringLength(s) == 1
endfunction
function IsMetas takes string s returns boolean
local integer i = 0
local string str
if StringCase(s,true) != StringCase(s,false) then
return false
endif
loop
set str = SubString(s, i, i + 1)
exitwhen str == ""
if I2S(S2I(str)) == str then
return false
endif
set i = i + 1
endloop
return true
endfunction
endlibrary