mirror of https://github.com/natnat-mc/moonbuild
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							25 lines
						
					
					
						
							618 B
						
					
					
				
			
		
		
	
	
							25 lines
						
					
					
						
							618 B
						
					
					
				import match, gmatch, sub from string
 | 
						|
import upper, lower from string
 | 
						|
 | 
						|
GLOB_PATT='^([^%%]*)%%([^%%]*)$'
 | 
						|
 | 
						|
patsubst = (str, pattern, replacement) ->
 | 
						|
	return [patsubst s, pattern, replacement for s in *str] if (type str)=='table'
 | 
						|
	prefix, suffix = match pattern, GLOB_PATT
 | 
						|
	return str unless prefix
 | 
						|
	reprefix, resuffix = match replacement, GLOB_PATT
 | 
						|
	return replacement unless reprefix
 | 
						|
 | 
						|
	if (sub str, 1, #prefix)==prefix and (sub str, -#suffix)==suffix
 | 
						|
		return reprefix..(sub str, #prefix+1, -#suffix-1)..resuffix
 | 
						|
	str
 | 
						|
 | 
						|
splitsp = (str) ->
 | 
						|
	[elem for elem in gmatch str, '%S+']
 | 
						|
 | 
						|
{
 | 
						|
	:patsubst
 | 
						|
	:splitsp
 | 
						|
 | 
						|
	:upper, :lower
 | 
						|
}
 | 
						|
 |