local a={}function a.Trim(a,L)L=L or"\037\115"return a:gsub("\094"..(L..("\042\040\046-\041"..(L.."\042\036"))),"\037\049")end function a.ToCamelCase(a)a=a:lower()a=a:gsub("\091 \095\093\040\037\097\041",string.upper)a=a:gsub("\094\037\097",string.upper)a=a:gsub("\037\112","")return a end function a.ToLowerCamelCase(a)a=a:lower()a=a:gsub("\091 \095\093\040\037\097\041",string.upper)a=a:gsub("\094\037\097",string.lower)a=a:gsub("\037\112","")return a end function a.ToPrivateCase(a)return"\095"..((a:sub(1,1)):lower()..a:sub(2,#a))end function a.TrimFront(a,L)L=L or"\037\115"return a:gsub("\094"..(L..("\042\040\046-\041"..(L.."\042"))),"\037\049")end function a.CheckNumOfCharacterInString(a,L)local I=0 for a in string.gmatch(a,L)do I=I+1 end return I end function a.IsEmptyOrWhitespaceOrNil(L)return type(L)~="\115\116\114\105\110\103"or L==""or a.IsWhitespace(L)end function a.IsWhitespace(a)return string.match(a,"\091\037\115\093\043")==a end function a.ElipseLimit(a,L)if#a>L then a=a:sub(1,L-3).."\046\046\046"end return a end function a.AddCommas(a)if type(a)=="\110\117\109\098\101\114"then a=tostring(a)end local L=-1 while L~=0 do a,L=string.gsub(a,"\094\040-\063\037\100\043\041\040\037\100\037\100\037\100\041","\037\049\044\037\050")end return a end return a
--- This module provides utility functions for strings
-- @module String

local lib = {}

function lib.Trim(str, pattern)
	pattern = pattern or "%s";
	-- %S is whitespaces
	-- When we find the first non space character defined by ^%s
	-- we yank out anything in between that and the end of the string
	-- Everything else is replaced with %1 which is essentially nothing
	return (str:gsub("^"..pattern.."*(.-)"..pattern.."*$", "%1"))
end

--- Sets it to UpperCamelCase
function lib.ToCamelCase(str)
	str = str:lower()
	str = str:gsub("[ _](%a)", string.upper)
	str = str:gsub("^%a", string.upper)
	str = str:gsub("%p", "")

	return str
end

function lib.ToLowerCamelCase(str)
	str = str:lower()
	str = str:gsub("[ _](%a)", string.upper)
	str = str:gsub("^%a", string.lower)
	str = str:gsub("%p", "")

	return str
end

function lib.ToPrivateCase(str)
	return "_" .. str:sub(1, 1):lower() .. str:sub(2, #str)
end

-- Only trims the front of the string...
function lib.TrimFront(str, pattern)
	pattern = pattern or "%s";
	return (str:gsub("^"..pattern.."*(.-)"..pattern.."*", "%1"))
end

function lib.CheckNumOfCharacterInString(str, char)
	local count = 0
	for _ in string.gmatch(str, char) do
		count = count + 1
	end
	return count
end

--- Checks if a string is empty or nil
function lib.IsEmptyOrWhitespaceOrNil(str)
	return type(str) ~= "string" or str == "" or lib.IsWhitespace(str)
end

--- Returns whether or not text is whitespace
function lib.IsWhitespace(str)
	return string.match(str, "[%s]+") == str
end

--- Converts text to have a ... after it if it's too long.
function lib.ElipseLimit(str, characterLimit)
	if #str > characterLimit then
		str = str:sub(1, characterLimit-3).."..."
	end
	return str
end

function lib.AddCommas(number)
	if type(number) == "number" then
		number = tostring(number)
	end

	local index = -1

	while index ~= 0 do
		number, index = string.gsub(number, "^(-?%d+)(%d%d%d)", '%1,%2')
	end

	return number
end

return lib