- Joined
- Dec 12, 2008
- Messages
- 7,385
FileIONameSafety was a pretty silly library with very limited application.
I decided to get rid of it and replace with something more modular and general-purpose.
This library is used to remove the leading and trailing spaces in a string, and it can be used to do what FileIONameSafety did just by doing the following:
Code
Feel free to comment.
I decided to get rid of it and replace with something more modular and general-purpose.
This library is used to remove the leading and trailing spaces in a string, and it can be used to do what FileIONameSafety did just by doing the following:
JASS:
function FixPlayerName takes player p returns nothing
call SetPlayerName(p, RemoveLeadingSpaces(GetPlayerName(p)))
endfunction
Code
JASS:
/********************************
*
* RemoveStringCharacters
* v1.1.0.0
* By Magtheridon96
*
* - This library allows you to remove
* leading and trailing spaces from a string
* and it ensures minimal string leaks in
* doing so.
*
* API:
* ----
*
* - function RemoveLeadingCharacters takes string whichString, string character returns string
* - Removes all leading instances of character in whichString.
* - function RemoveLeadingSpaces takes string whichString returns string
* - Removes all leading spaces in whichString.
* - function RemoveTrailingCharacters takes string whichString, string character returns string
* - Removes all trailing instances of character in whichString.
* - function RemoveTrailingSpaces takes string whichString returns string
* - Removes all trailing spaces in whichString.
* - function StringTrimCharacters takes string whichString, string character returns string
* - Removes all trailing and leading instances of character in whichString.
* - function StringTrim takes string whichString returns string
* - Removes all trailing and leading spaces in whichString.
*
********************************/
library RemoveStringCharacters
function RemoveLeadingCharacters takes string str, string character returns string
local integer position = 0
local integer length = StringLength(str)
loop
exitwhen position == length or SubString(str, position, position + 1) != character
set position = position + 1
endloop
return SubString(str, position, length)
endfunction
function RemoveLeadingSpaces takes string str returns string
return RemoveLeadingCharacters(str, " ")
endfunction
function RemoveTrailingCharacters takes string str, string character returns string
local integer length = StringLength(str)
local integer position = length - 1
loop
exitwhen position == -1 or SubString(str, position, position + 1) != character
set position = position - 1
endloop
return SubString(str, 0, position + 1)
endfunction
function RemoveTrailingSpaces takes string str returns string
return RemoveTrailingCharacters(str, " ")
endfunction
function StringTrimCharacters takes string whichString, string character returns string
return RemoveTrailingCharacters(RemoveLeadingCharacters(whichString, character), character)
endfunction
function StringTrim takes string whichString returns string
return StringTrimCharacters(whichString, " ")
endfunction
endlibrary
// Backwards compatibility
library RemoveStringSpaces requires RemoveStringCharacters
endlibrary
Feel free to comment.
Last edited: