lua-users home
lua-l archive

string buffer needs

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Referring to the recent discussion on a need for string buffer (general data buffer, ranges et.al.) has anyone made a API-like list of how that should really work? I mean, we could do it 'by hand' with Lua, awful performance but the codeability aspects could be experimented with. Here's a couple of funcs that I'd personally find a use for in the remake of Lumikki:
** Find with a range **
int, int [capture_str [,...]]= buffer.findfrom( text_str, start_int, pattern_str ) This is a variant of 'string.find()' with a starting place (probably, range?) within a string. Allows me to look for HTML tags etc. within a huge all-in-one string, without creating an awful lot of intermediate substrings.
Current implementation:	using 'string.find' and 'string.sub'
	-----
-- [start_int, stop_int [,capture ...]]= string.findfrom( str, start_int, pattern_str )
	--
	local function string_findfrom( str, start, pat )
	 --
 	local tbl= { string.find( string.sub(str,start), pat ) }
	 if not tbl[1] then
 	 return nil
	 else
 	 tbl[1]= tbl[1]+(start-1)
 	tbl[2]= tbl[2]+(start-1)
	 return unpack(tbl)
 	end
	end
** In-place appending **
void= buffer.append( text_str, ... )
Ability to modify a string 'in place', without creating new entries all over. This is basically the same as "str ..=" (C-like in-place operator syntax) would be. Usage: gathering strings together, big data. Perhaps there's a table function for this, I'll see.. (yes, 'table.concat' but I still needed to craft a temporary table to collect the strings first)
Current implementation: str= str..whatever
 or: table.concat()
Question: does anyone know of the performance difference between 'table.concat' and regular appending?

AltStyle によって変換されたページ (->オリジナル) /