--[[ * Copyright (c) 2011 by Adam Hellberg. * * This file is part of Command. * * Command is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Command is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Command. If not, see <http://www.gnu.org/licenses/>. --]] if type(Command.Extensions) ~= "table" then Command.Extensions = {} end local C = Command --- Table containing all String methods. -- This is referenced "CES" in String.lua. -- @name Command.Extentions.String -- @class table -- @field type No current use. -- C.Extensions.String = { type = "ext" -- For future use } local CES = C.Extensions.String --- Check if a string starts with a specific string. -- @param s String to be checked. -- @param target String to search for at beginning of s. -- function CES:StartsWith(s, target) return s:sub(1, target:len()) == target end --- Check if a string ends with a specific string. -- @param s String to be checked. -- @param target Stromg to search for at end of s. -- function CES:EndsWith(s, target) return target == '' or s:sub(-target:len()) == target end --- Trim a string, removing whitespace at the beginning of it. -- @param s String to be trimmed. -- @return The trimmed string. -- function CES:Trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end --- Split a string with space as delimiter. -- @param s String to be split. -- @return Table containing the individual words. -- function CES:Split(s) local t = {} for token in string.gmatch(s, "[^%s]+") do table.insert(t, token) end return t end