Skip to content

Commit

Permalink
* Modified TextManager.Match to only make partial matches if asterisk…
Browse files Browse the repository at this point in the history
…s are explicitly added to the beginning and/or end of the pattern.
  • Loading branch information
YotaXP committed May 21, 2012
1 parent 055a375 commit f27edd8
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions code/controllers/managers/textman.dm
Expand Up @@ -260,27 +260,37 @@ TextManager
// Simple string matching procedure. // Simple string matching procedure.
// Crashed, C*a*h*d will match. // Crashed, C*a*h*d will match.
// Crashed, Crah*d will not (missing s). // Crashed, Crah*d will not (missing s).
// Crashed, Crash* will match.
// Crashed, Crash will not (missing ed).
Match(string, pattern) Match(string, pattern)
if(!string || !pattern) return 0

var parts[] = list() var parts[] = list()
var find = findtext(pattern, "*") var find = findtext(pattern, "*")
var startWild = find == 1
var endWild = text2ascii(pattern, length(pattern)) == 42 // '*'


while(find) while(find)
var part = copytext(pattern, 1, find) if(find > 1) parts += copytext(pattern, 1, find)
parts += part
pattern = copytext(pattern, find + 1) pattern = copytext(pattern, find + 1)
find = findtext(pattern, "*") find = findtext(pattern, "*")


parts += pattern if(pattern) parts += pattern

if(!parts.len) return 1 // "*" pattern

find = findtext(string, parts[1])
if(!find || (!startWild && find != 1)) return 0


if(!length(parts)) return 0 find += length(parts[1])
parts.Cut(1, 2)


find = 1
for(var/part in parts) for(var/part in parts)
find = findtext(string, part, find) + length(part) find = findtext(string, part, find)
if(find == length(part)) if(find) find += length(part)
return 0 else return 0


return 1 return endWild || find == length(string)+1


fadetext(var/text, var/list/colors) fadetext(var/text, var/list/colors)
if(!colors) return text if(!colors) return text
Expand Down

0 comments on commit f27edd8

Please sign in to comment.