Module:Codedoc/util

-- --| Basic utility functions. --by Pedro Miller Rabinovitch --$Id: util.lua,v 1.3 2003/10/03 15:53:26 miller Exp $ --http://lua-users.org/wiki/ExpLua --http://lua-users.org/files/wiki_insecure/users/miller/explua.tar.gz

--% Current system verbosity level (the more the most) VERB_LEVEL = 2 --% Current system prefix VERB_NAME = ''

--% Emit a log message -- Sends out (or not) a line of logging information, depending on the current -- verbosity level. --@ level (number) Specifies this message's verbosity level --@ ... (tostringable) Message arguments (must be |tostring|able) function verb( level, ... ) if level <= VERB_LEVEL then return print( os.date..VERB_NAME, unpack( arg )) end end --% Assert parameter types are correct --@ type_name (string) expected type name --@ ... (any) values to be checked function check_types( type_name, ... ) for i, v in ipairs( arg ) do     assert( type(v) == type_name ) end end

--% Adds an optional punctuation mark to a string, if there's none. --@ text (string) text to be adjusted --@ char (string) character (or sequence thereof) to be added. '.' (period) -- is used by default. --@ mask (string) mask representing punctuation characters. '[.;!?]' by default. --: (string) adjusted text function add_punctuation( text, char, mask ) check_types( 'string', text ) char = char or '.' mask = mask or '[.;!?]' check_types( 'string', text, char ) if string.len( text ) > 1 then if not string.find( text, mask..'%s*$') then text = string.gsub( text,			 '%s*$', char ) end end

return text end